Changeset 4776


Ignore:
Timestamp:
2003-06-24T13:07:24+12:00 (21 years ago)
Author:
mdewsnip
Message:

Now uses the PrintUsage module to automatically generate usage text from the $options and $arguments structures.

Location:
trunk/gsdl/bin/script
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/bin/script/buildcol.pl

    r4766 r4776  
    2626###########################################################################
    2727
     28# 11/04/03 Added usage datastructure - John Thompson
     29
    2830package buildcol;
    2931
     
    4042use util;
    4143use FileHandle;
     44use printusage;
     45
     46my $mode_list =
     47    [ { 'name' => "all",
     48        'desc' => "Do everything." },
     49      { 'name' => "compress_text",
     50        'desc' => "Just compress the text." },
     51      { 'name' => "build_index",
     52        'desc' => "Just index the text." },
     53      { 'name' => "infodb",
     54        'desc' => "Just build the metadata database." } ];
     55
     56my $arguments =
     57    [ { 'name' => "archivedir",
     58    'desc' => "Where the archives live.",
     59    'type' => "string",
     60    'reqd' => "no" },
     61      { 'name' => "verbosity",
     62    'desc' => "0=none, 3=lots",
     63    'type' => "int",
     64    'deft' => "2",
     65    'reqd' => "no" },
     66      { 'name' => "builddir",
     67    'desc' => "Where to put the built indexes.",
     68    'type' => "string",
     69    'reqd' => "no" },
     70      { 'name' => "cachedir",
     71    'desc' => "?",
     72    'type' => "string",
     73    'reqd' => "no" },
     74      { 'name' => "maxdocs",
     75    'desc' => "Maximum number of documents to build.",
     76    'type' => "int",
     77    'reqd' => "no" },
     78      { 'name' => "debug",
     79    'desc' => "Print output to STDOUT.",
     80    'type' => "flag",
     81    'reqd' => "no" },
     82      { 'name' => "mode",
     83    'desc' => "The parts of the building process to carry out.",
     84    'type' => "enum",
     85    'list' => $mode_list,
     86    'deft' => "all",
     87    'reqd' => "no" },
     88      { 'name' => "index",
     89    'desc' => "Index to build (will build all in config file if not set).",
     90    'type' => "string",
     91    'reqd' => "no" },
     92      { 'name' => "keepold",
     93    'desc' => "Will not destroy the current contents of the building directory.",
     94    'type' => "flag",
     95    'reqd' => "no" },
     96      { 'name' => "no_text",             
     97    'desc' => "Don't store compressed text. This option is useful for minimizing the size of the built indexes if you intend always to display the original documents at run time (i.e. you won't be able to retrieve the compressed text version).",
     98    'type' => "flag",
     99    'reqd' => "no" },
     100      { 'name' => "allclassifications",
     101    'desc' => "Don't remove empty classifications.",
     102    'type' => "flag",
     103    'reqd' => "no" },
     104      { 'name' => "create_images",
     105    'desc' => "Attempt to create default images for new collection. This relies on the Gimp being installed along with relevant perl modules to allow scripting from perl.",
     106    'type' => "flag",
     107    'reqd' => "no" },
     108      { 'name' => "collectdir",
     109    'desc' => "Collection directory.",
     110    'type' => "string",
     111    'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
     112    'reqd' => "no" },
     113      { 'name' => "out",
     114    'desc' => "Filename or handle to print output status to.",
     115    'type' => "string",
     116    'deft' => "STDERR",
     117    'reqd' => "no" },
     118      { 'name' => "no_strip_html",
     119    'desc' => "Do not strip the html tags from the indexed text (only used for mgpp collections).",
     120    'type' => "flag",
     121    'reqd' => "no" },
     122      { 'name' => "faillog",
     123    'desc' => "Fail log filename. This log receives the filenames of any files which fail to be processed.",
     124    'type' => "string",
     125    'deft' => &util::filename_cat("<collectdir>", "colname", "etc", "fail.log"),
     126    'reqd' => "no" } ];
     127
     128my $options = { 'name' => "buildcol.pl",
     129        'desc' => "PERL script used to build a greenstone collection from GML documents.",
     130        'args' => $arguments };
     131
     132
     133sub print_xml_usage
     134{
     135    &PrintUsage::print_xml_header();
     136
     137    print STDERR "<Info>\n";
     138    print STDERR "  <Name>$options->{'name'}</Name>\n";
     139    print STDERR "  <Desc>$options->{'desc'}</Desc>\n";
     140    print STDERR "  <Arguments>\n";
     141    if (defined($options->{'args'})) {
     142    &PrintUsage::print_options_xml($options->{'args'});
     143    }
     144    print STDERR "  </Arguments>\n";
     145    print STDERR "</Info>\n";
     146}
     147
     148
     149sub print_txt_usage
     150{
     151    local $programname = $options->{'name'};
     152    local $programargs = $options->{'args'};
     153
     154    # Find the length of the longest option string
     155    local $descoffset = 0;
     156    if (defined($programargs)) {
     157    $descoffset = &PrintUsage::find_longest_option_string($programargs);
     158    }
     159
     160    # Produce the usage information using the data structure above
     161    print STDERR " usage: $programname [options] collection-name\n\n";
     162
     163    # Display the program options, if there are some
     164    if (defined($programargs)) {
     165    # Calculate the column offset of the option descriptions
     166    local $optiondescoffset = $descoffset + 2;  # 2 spaces between options & descriptions
     167
     168    print STDERR " options:\n";
     169
     170    # Display the program options
     171    &PrintUsage::print_options_txt($programargs, $optiondescoffset);
     172    }
     173}
     174
     175
     176#  sub print_usage {
     177#      print STDOUT "\n";
     178#      print STDOUT "buildcol.pl: Builds the indexes of a Greenstone collection.\n\n";
     179#      print STDOUT "  usage: $0 [options] collection-name\n\n";
     180#      print STDOUT "  options:\n";
     181#      print STDOUT "   -verbosity number     0=none, 3=lots\n";
     182#      print STDOUT "   -archivedir directory Where the archives live\n";
     183#      print STDOUT "   -builddir directory   Where to put the built indexes\n";
     184#      print STDOUT "   -maxdocs number       Maximum number of documents to build\n";
     185#      print STDOUT "   -debug                Print output to STDOUT\n";
     186#      print STDOUT "   -mode all|compress_text|build_index|infodb\n";
     187#      print STDOUT "   -index indexname      Index to build (will build all in\n";
     188#      print STDOUT "                         config file if not set)\n";
     189#      print STDOUT "   -keepold              will not destroy the current contents of the\n";
     190#      print STDOUT "                         building directory\n";
     191#      print STDOUT "   -no_text              Don't store compressed text. This option is\n";
     192#      print STDOUT "                         useful for minimizing the size of the built\n";
     193#      print STDOUT "                         indexes if you intend always to display the\n";
     194#      print STDOUT "                         original documents at run time (i.e. you won't\n";
     195#      print STDOUT "                         be able to retrieve the compressed text version)\n";
     196#      print STDOUT "   -allclassifications   Don't remove empty classifications\n";
     197#      print STDOUT "   -create_images        Attempt to create default images for new\n";
     198#      print STDOUT "                         collection. This relies on the Gimp being\n";
     199#      print STDOUT "                         installed along with relevant perl modules\n";
     200#      print STDOUT "                         to allow scripting from perl\n";
     201#      print STDOUT "   -collectdir directory Collection directory (defaults to " .
     202#   &util::filename_cat ($ENV{'GSDLHOME'}, "collect") . ")\n";
     203#      print STDOUT "   -out                  Filename or handle to print output status to.\n";
     204#      print STDOUT "                         The default is STDERR\n";
     205#      print STDOUT "   -no_strip_html        Do not strip the html tags from the indexed text\n";
     206#      print STDOUT "                         (only used for mgpp collections).\n\n";
     207#      print STDOUT "   -faillog name         Fail log filename. This log receives the filenames\n";
     208#      print STDOUT "                         of any files which fail to be processed (defaults.\n";
     209#      print STDOUT "                         to " .
     210#   &util::filename_cat("<collectdir>", "colname", "etc", "fail.log") . ")\n";
     211#      print STDOUT "  [Type \"perl -S buildcol.pl | more\" if this help text scrolled off your screen]";
     212#      print STDOUT "\n" unless $ENV{'GSDLOS'} =~ /^windows$/i;
     213#  }
     214
    42215
    43216&main();
    44 
    45 sub print_usage {
    46     print STDOUT "\n";
    47     print STDOUT "buildcol.pl: Builds the indexes of a Greenstone collection.\n\n";
    48     print STDOUT "  usage: $0 [options] collection-name\n\n";
    49     print STDOUT "  options:\n";
    50     print STDOUT "   -verbosity number     0=none, 3=lots\n";
    51     print STDOUT "   -archivedir directory Where the archives live\n";
    52     print STDOUT "   -builddir directory   Where to put the built indexes\n";
    53     print STDOUT "   -maxdocs number       Maximum number of documents to build\n";
    54     print STDOUT "   -debug                Print output to STDOUT\n";
    55     print STDOUT "   -mode all|compress_text|build_index|infodb\n";
    56     print STDOUT "   -index indexname      Index to build (will build all in\n";
    57     print STDOUT "                         config file if not set)\n";
    58     print STDOUT "   -keepold              will not destroy the current contents of the\n";
    59     print STDOUT "                         building directory\n";
    60     print STDOUT "   -no_text              Don't store compressed text. This option is\n";
    61     print STDOUT "                         useful for minimizing the size of the built\n";
    62     print STDOUT "                         indexes if you intend always to display the\n";
    63     print STDOUT "                         original documents at run time (i.e. you won't\n";
    64     print STDOUT "                         be able to retrieve the compressed text version)\n";
    65     print STDOUT "   -allclassifications   Don't remove empty classifications\n";
    66     print STDOUT "   -create_images        Attempt to create default images for new\n";
    67     print STDOUT "                         collection. This relies on the Gimp being\n";
    68     print STDOUT "                         installed along with relevant perl modules\n";
    69     print STDOUT "                         to allow scripting from perl\n";
    70     print STDOUT "   -collectdir directory Collection directory (defaults to " .
    71     &util::filename_cat ($ENV{'GSDLHOME'}, "collect") . ")\n";
    72     print STDOUT "   -out                  Filename or handle to print output status to.\n";
    73     print STDOUT "                         The default is STDERR\n";
    74     print STDOUT "   -no_strip_html        Do not strip the html tags from the indexed text\n";
    75     print STDOUT "                         (only used for mgpp collections).\n\n";
    76     print STDOUT "   -faillog name         Fail log filename. This log receives the filenames\n";
    77     print STDOUT "                         of any files which fail to be processed (defaults.\n";
    78     print STDOUT "                         to " .
    79     &util::filename_cat("<collectdir>", "colname", "etc", "fail.log") . ")\n";
    80     print STDOUT "  [Type \"perl -S buildcol.pl | more\" if this help text scrolled off your screen]";
    81     print STDOUT "\n" unless $ENV{'GSDLOS'} =~ /^windows$/i;
    82 }
    83217
    84218
     
    89223    $create_images, $collectdir, $out, $buildtype, $textindex,
    90224    $no_strip_html, $no_text, $faillog);
     225
     226    # ***** 11-04-03 - John Thompson *****
     227    my $xml = 0;
     228    # ************************************
    91229
    92230    # note that no defaults are passed for most options as they're set
     
    108246             'out/.*/STDERR', \$out,
    109247             'no_strip_html', \$no_strip_html,
    110              'faillog/.*/', \$faillog)) {
    111     &print_usage();
     248             'faillog/.*/', \$faillog,
     249             q^xml^, \$xml)) {
     250    &print_txt_usage();
     251    die "\n";
     252    }
     253
     254    if ($xml) {
     255        &print_xml_usage();
    112256    die "\n";
    113257    }
     
    124268    # get and check the collection
    125269    if (($collection = &util::use_collection(@ARGV, $collectdir)) eq "") {
    126     &print_usage();
     270    &print_txt_usage();
    127271    die "\n";
    128272    }
  • trunk/gsdl/bin/script/import.pl

    r3402 r4776  
    4646use parsargv;
    4747use FileHandle;
    48 
    49 sub print_usage {
    50     print STDOUT "\n";
    51     print STDOUT "import.pl: Converts documents in collections -importdir directory into\n";
    52     print STDOUT "           xml documents which are written to the -archivedir directory.\n\n";
    53     print STDOUT "  usage: $0 [options] collection-name\n\n";
    54     print STDOUT "  options:\n";
    55     print STDOUT "   -verbosity number      0=none, 3=lots\n";
    56     print STDOUT "   -importdir directory   Where the original material lives\n";
    57     print STDOUT "   -archivedir directory  Where the converted material ends up\n";
    58     print STDOUT "   -keepold               Will not destroy the current contents of the\n";
    59     print STDOUT "                          archives directory (the default)\n";
    60     print STDOUT "   -removeold             Will remove the old contents of the archives\n";
    61     print STDOUT "                          directory -- use with care\n";
    62     print STDOUT "   -gzip                  Use gzip to compress resulting xml documents\n";
    63     print STDOUT "                          (don't forget to include ZIPPlug in your plugin\n";
    64     print STDOUT "                          list when building from compressed documents)\n";
    65     print STDOUT "   -maxdocs number        Maximum number of documents to import\n";
    66     print STDOUT "   -groupsize number      Number of import documents to group into one XML file\n";
    67     print STDOUT "   -OIDtype hash|incremental The method to use when generating unique\n";
    68     print STDOUT "                          identifiers for each document. \"hash\" (the\n";
    69     print STDOUT "                          default) hashes the contents of the file and so\n";
    70     print STDOUT "                          will be the same every time the collection is\n";
    71     print STDOUT "                          imported. \"incremental\" is a simple document\n";
    72     print STDOUT "                          count and so will be significantly faster than\n";
    73     print STDOUT "                          \"hash\". It is not guaranteed to always assign\n";
    74     print STDOUT "                          the same identifier to a given document though\n";
    75     print STDOUT "                          and does not allow further documents to be added\n";
    76     print STDOUT "                          to existing xml archives\n";
    77     print STDOUT "   -sortmeta metadata     Sort documents alphabetically by metadata for\n";
    78     print STDOUT "                          building. This will be disabled if groupsize > 1\n";
    79     print STDOUT "   -debug                 Print imported text to STDOUT\n";
    80     print STDOUT "   -collectdir directory  Collection directory (defaults to " .
    81     &util::filename_cat ($ENV{'GSDLHOME'}, "collect") . ")\n";
    82     print STDOUT "   -out name              Filename or handle to print output status to.\n";
    83     print STDOUT "                          The default is STDERR\n";
    84     print STDOUT "   -statsfile name        Filename or handle to print import statistics to.\n";
    85     print STDOUT "                          The default is STDERR\n";
    86     print STDOUT "   -faillog name          Fail log filename. This log receives the filenames\n";
    87     print STDOUT "                          of any files which fail to be processed (defaults\n";
    88     print STDOUT "                          to " .
    89     &util::filename_cat("<collectdir>", "colname", "etc", "fail.log") . ")\n";
    90     print STDOUT "  [Type \"perl -S import.pl | more\" if this help text scrolled off your screen]";
    91     print STDOUT "\n" unless $ENV{'GSDLOS'} =~ /^windows$/i;
     48use printusage;
     49
     50my $oidtype_list =
     51    [ { 'name' => "hash",
     52        'desc' => "Hashes the contents of the file. Document identifier will be the same every time the collection is imported." },
     53      { 'name' => "incremental",
     54        'desc' => "A simple document count that is significantly faster than \"hash\". It is not guaranteed to always assign the same identifier to a given document though and does not allow further documents to be added to existing xml archives." } ];
     55
     56my $arguments =
     57    [ { 'name' => "archivedir",
     58    'desc' => "Where the converted material ends up.",
     59    'type' => "string",
     60    'reqd' => "no" },
     61      { 'name' => "collectdir",
     62    'desc' => "Collection directory.",
     63    'type' => "string",
     64    'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
     65    'reqd' => "no" },
     66      { 'name' => "debug",
     67    'desc' => "Print imported text to STDOUT.",
     68    'type' => "flag",
     69    'reqd' => "no" },
     70      { 'name' => "faillog",
     71    'desc' => "Fail log filename. This log receives the filenames of any files which fail to be processed.",
     72    'type' => "string",
     73    'deft' => &util::filename_cat("<collectdir>", "colname", "etc", "fail.log"),
     74    'reqd' => "no" },
     75      { 'name' => "groupsize",
     76    'desc' => "Number of import documents to group into one XML file.",
     77    'type' => "int",
     78    'deft' => "1",
     79    'reqd' => "no" },
     80      { 'name' => "gzip",
     81    'desc' => "Use gzip to compress resulting xml documents (don't forget to include ZIPPlug in your plugin list when building from compressed documents).",
     82    'type' => "flag",
     83    'reqd' => "no" },
     84      { 'name' => "importdir",
     85    'desc' => "Where the original material lives.",
     86    'type' => "string",
     87    'reqd' => "no" },
     88      { 'name' => "keepold",
     89    'desc' => "Will not destroy the current contents of the archives directory (the default).",
     90    'type' => "flag",
     91    'reqd' => "no" },
     92      { 'name' => "maxdocs",
     93    'desc' => "Maximum number of documents to import.",
     94    'type' => "int",
     95    'reqd' => "no" },
     96      { 'name' => "OIDtype",
     97    'desc' => "The method to use when generating unique identifiers for each document.",
     98    'type' => "enum",
     99    'list' => $oidtype_list,
     100    'deft' => "hash",
     101    'reqd' => "no" },
     102      { 'name' => "out",
     103    'desc' => "Filename or handle to print output status to.",
     104    'type' => "string",
     105    'deft' => "STDERR",
     106    'reqd' => "no" },
     107      { 'name' => "removeold",
     108    'desc' => "Will remove the old contents of the archives directory -- use with care.",
     109    'type' => "flag",
     110    'reqd' => "no" },
     111      { 'name' => "sortmeta",
     112    'desc' => "Sort documents alphabetically by metadata for building. This will be disabled if groupsize > 1.",
     113    'type' => "string",
     114    'reqd' => "no" },
     115      { 'name' => "statsfile",
     116    'desc' => "Filename or handle to print import statistics to.",
     117    'type' => "string",
     118    'deft' => "STDERR",
     119    'reqd' => "no" },
     120      { 'name' => "verbosity",
     121    'desc' => "0=none, 3=lots",
     122    'type' => "int",
     123    'deft' => "2",
     124    'reqd' => "no" } ];
     125
     126my $options = { 'name' => "import.pl",
     127        'desc' => "PERL script used to import files into a GML format ready for building.",
     128        'args' => $arguments };
     129
     130
     131sub print_xml_usage
     132{
     133    &PrintUsage::print_xml_header();
     134
     135    print STDERR "<Info>\n";
     136    print STDERR "  <Name>$options->{'name'}</Name>\n";
     137    print STDERR "  <Desc>$options->{'desc'}</Desc>\n";
     138    print STDERR "  <Arguments>\n";
     139    if (defined($options->{'args'})) {
     140    &PrintUsage::print_options_xml($options->{'args'});
     141    }
     142    print STDERR "  </Arguments>\n";
     143    print STDERR "</Info>\n";
    92144}
     145
     146
     147sub print_txt_usage
     148{
     149    local $programname = $options->{'name'};
     150    local $programargs = $options->{'args'};
     151
     152    # Find the length of the longest option string
     153    local $descoffset = 0;
     154    if (defined($programargs)) {
     155    $descoffset = &PrintUsage::find_longest_option_string($programargs);
     156    }
     157
     158    # Produce the usage information using the data structure above
     159    print STDERR " usage: $programname [options] collection-name\n\n";
     160
     161    # Display the program options, if there are some
     162    if (defined($programargs)) {
     163    # Calculate the column offset of the option descriptions
     164    local $optiondescoffset = $descoffset + 2;  # 2 spaces between options & descriptions
     165
     166    print STDERR " options:\n";
     167
     168    # Display the program options
     169    &PrintUsage::print_options_txt($programargs, $optiondescoffset);
     170    }
     171}
     172
     173
     174#  sub print_usage {
     175#      print STDOUT "\n";
     176#      print STDOUT "import.pl: Converts documents in collections -importdir directory into\n";
     177#      print STDOUT "           xml documents which are written to the -archivedir directory.\n\n";
     178#      print STDOUT "  usage: $0 [options] collection-name\n\n";
     179#      print STDOUT "  options:\n";
     180#      print STDOUT "   -verbosity number      0=none, 3=lots\n";
     181#      print STDOUT "   -importdir directory   Where the original material lives\n";
     182#      print STDOUT "   -archivedir directory  Where the converted material ends up\n";
     183#      print STDOUT "   -keepold               Will not destroy the current contents of the\n";
     184#      print STDOUT "                          archives directory (the default)\n";
     185#      print STDOUT "   -removeold             Will remove the old contents of the archives\n";
     186#      print STDOUT "                          directory -- use with care\n";
     187#      print STDOUT "   -gzip                  Use gzip to compress resulting xml documents\n";
     188#      print STDOUT "                          (don't forget to include ZIPPlug in your plugin\n";
     189#      print STDOUT "                          list when building from compressed documents)\n";
     190#      print STDOUT "   -maxdocs number        Maximum number of documents to import\n";
     191#      print STDOUT "   -groupsize number      Number of import documents to group into one XML file\n";
     192#      print STDOUT "   -OIDtype hash|incremental The method to use when generating unique\n";
     193#      print STDOUT "                          identifiers for each document. \"hash\" (the\n";
     194#      print STDOUT "                          default) hashes the contents of the file and so\n";
     195#      print STDOUT "                          will be the same every time the collection is\n";
     196#      print STDOUT "                          imported. \"incremental\" is a simple document\n";
     197#      print STDOUT "                          count and so will be significantly faster than\n";
     198#      print STDOUT "                          \"hash\". It is not guaranteed to always assign\n";
     199#      print STDOUT "                          the same identifier to a given document though\n";
     200#      print STDOUT "                          and does not allow further documents to be added\n";
     201#      print STDOUT "                          to existing xml archives\n";
     202#      print STDOUT "   -sortmeta metadata     Sort documents alphabetically by metadata for\n";
     203#      print STDOUT "                          building. This will be disabled if groupsize > 1\n";
     204#      print STDOUT "   -debug                 Print imported text to STDOUT\n";
     205#      print STDOUT "   -collectdir directory  Collection directory (defaults to " .
     206#   &util::filename_cat ($ENV{'GSDLHOME'}, "collect") . ")\n";
     207#      print STDOUT "   -out name              Filename or handle to print output status to.\n";
     208#      print STDOUT "                          The default is STDERR\n";
     209#      print STDOUT "   -statsfile name        Filename or handle to print import statistics to.\n";
     210#      print STDOUT "                          The default is STDERR\n";
     211#      print STDOUT "   -faillog name          Fail log filename. This log receives the filenames\n";
     212#      print STDOUT "                          of any files which fail to be processed (defaults\n";
     213#      print STDOUT "                          to " .
     214#   &util::filename_cat("<collectdir>", "colname", "etc", "fail.log") . ")\n";
     215#      print STDOUT "  [Type \"perl -S import.pl | more\" if this help text scrolled off your screen]";
     216#      print STDOUT "\n" unless $ENV{'GSDLOS'} =~ /^windows$/i;
     217#  }
    93218
    94219&main();
     
    100225    $pluginfo, $sortmeta, $archive_info_filename, $statsfile,
    101226    $archive_info, $processor, $out, $faillog, $collectdir);
     227
     228    # ***** 11-04-03 - John Thompson *****
     229    my $xml = 0;
     230    # ************************************
    102231
    103232    # note that no defaults are passed for most options as they're set
     
    118247             'out/.*/STDERR', \$out,
    119248             'statsfile/.*/STDERR', \$statsfile,
    120              'faillog/.*/', \$faillog)) {
    121     &print_usage();
     249             'faillog/.*/', \$faillog,
     250             q^xml^, \$xml)) {
     251    &print_txt_usage();
     252    die "\n";
     253    }
     254
     255    if ($xml) {
     256        &print_xml_usage();
    122257    die "\n";
    123258    }
     
    136271    # get and check the collection name
    137272    if (($collection = &util::use_collection(@ARGV, $collectdir)) eq "") {
    138     &print_usage();
     273    &print_txt_usage();
    139274    die "\n";
    140275    }
  • trunk/gsdl/bin/script/mkcol.pl

    r2811 r4776  
    4242use util;
    4343use cfgread;
    44 
    45 sub print_usage {
    46     print STDOUT "\n";
    47     print STDOUT "mkcol.pl: Creates the directory structure for a new\n";
    48     print STDOUT "          Greenstone collection.\n\n";
    49     print STDOUT "  usage: $0 -creator email [options] collection-name\n\n";
    50     print STDOUT "  options:\n";
    51     print STDOUT "   -optionfile file    Get options from file, useful on systems where\n";
    52     print STDOUT "                       long command lines may cause problems\n";
    53     print STDOUT "   -collectdir         Directory where new collection will be created.\n";
    54     print STDOUT "                       Default is " .
    55     &util::filename_cat($ENV{'GSDLHOME'}, "collect") . "\n";
    56     print STDOUT "   -maintainer email   The collection maintainer's email address (if\n";
    57     print STDOUT "                       different from the creator)\n";
    58     print STDOUT "   -public true|false  If this collection has anonymous access\n";
    59     print STDOUT "   -title text         The title for the collection\n";
    60     print STDOUT "   -about text         The about text for the collection\n";
    61     print STDOUT "   -plugin text        perl plugin module to use (there may be multiple\n";
    62     print STDOUT "                       plugin entries)\n";
    63     print STDOUT "   -quiet              Operate quietly\n";
    64     print STDOUT "  Note that -creator must be specified. You can make changes to all\n";
    65     print STDOUT "  options later by editing the collect.cfg configuration file for your\n";
    66     print STDOUT "  new collection (it'll be in the \"etc\" directory).\n\n";
    67     print STDOUT "  [Type \"perl -S mkcol.pl | more\" if this help text scrolled off your screen]";
    68     print STDOUT "\n" unless $ENV{'GSDLOS'} =~ /^windows$/i;
    69 }
     44use printusage;
     45
     46my $arguments =
     47    [ { 'name' => "creator",
     48    'desc' => "The collection creator's e-mail address.",
     49    'type' => "string",
     50    'reqd' => "yes" },
     51      { 'name' => "optionfile",
     52    'desc' => "Get options from file, useful on systems where long command lines may cause problems.",
     53    'type' => "string",
     54    'reqd' => "no" },
     55      { 'name' => "maintainer",
     56    'desc' => "The collection maintainer's email address (if different from the creator).",
     57    'type' => "string",
     58    'reqd' => "no" },
     59      { 'name' => "collectdir",
     60    'desc' => "Directory where new collection will be created.",
     61    'type' => "string",
     62    'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
     63    'reqd' => "no" },
     64      { 'name' => "public",
     65    'desc' => "If this collection has anonymous access (true/false).",
     66    'type' => "string",
     67    'deft' => "true",
     68    'reqd' => "no" },
     69      { 'name' => "title",
     70    'desc' => "The title of the collection.",
     71    'type' => "string",
     72    'reqd' => "no" },
     73      { 'name' => "about",
     74    'desc' => "The about text for the collection.",
     75    'type' => "string",
     76    'reqd' => "no" },
     77      { 'name' => "plugin",
     78    'desc' => "Perl plugin module to use (there may be multiple plugin entries).",
     79    'type' => "string",
     80    'reqd' => "no" },
     81      { 'name' => "quiet",
     82    'desc' => "Operate quietly.",
     83    'type' => "flag",
     84    'reqd' => "no" } ];
     85
     86my $options = { 'name' => "mkcol.pl",
     87        'desc' => "PERL script used to create the directory structure for a new Greenstone collection.",
     88        'args' => $arguments };
     89
     90
     91sub print_xml_usage
     92{
     93    &PrintUsage::print_xml_header();
     94
     95    print STDERR "<Info>\n";
     96    print STDERR "  <Name>$options->{'name'}</Name>\n";
     97    print STDERR "  <Desc>$options->{'desc'}</Desc>\n";
     98    print STDERR "  <Arguments>\n";
     99    if (defined($options->{'args'})) {
     100    &PrintUsage::print_options_xml($options->{'args'});
     101    }
     102    print STDERR "  </Arguments>\n";
     103    print STDERR "</Info>\n";
     104}
     105
     106
     107sub print_txt_usage
     108{
     109    local $programname = $options->{'name'};
     110    local $programargs = $options->{'args'};
     111
     112    # Find the length of the longest option string
     113    local $descoffset = 0;
     114    if (defined($programargs)) {
     115    $descoffset = &PrintUsage::find_longest_option_string($programargs);
     116    }
     117
     118    # Produce the usage information using the data structure above
     119    print STDERR " usage: $programname [options] collection-name\n\n";
     120
     121    # Display the program options, if there are some
     122    if (defined($programargs)) {
     123    # Calculate the column offset of the option descriptions
     124    local $optiondescoffset = $descoffset + 2;  # 2 spaces between options & descriptions
     125
     126    print STDERR " options:\n";
     127
     128    # Display the program options
     129    &PrintUsage::print_options_txt($programargs, $optiondescoffset);
     130    }
     131}
     132
     133
     134#  sub print_usage {
     135#      print STDOUT "\n";
     136#      print STDOUT "mkcol.pl: Creates the directory structure for a new\n";
     137#      print STDOUT "          Greenstone collection.\n\n";
     138#      print STDOUT "  usage: $0 -creator email [options] collection-name\n\n";
     139#      print STDOUT "  options:\n";
     140#      print STDOUT "   -optionfile file    Get options from file, useful on systems where\n";
     141#      print STDOUT "                       long command lines may cause problems\n";
     142#      print STDOUT "   -collectdir         Directory where new collection will be created.\n";
     143#      print STDOUT "                       Default is " .
     144#   &util::filename_cat($ENV{'GSDLHOME'}, "collect") . "\n";
     145#      print STDOUT "   -maintainer email   The collection maintainer's email address (if\n";
     146#      print STDOUT "                       different from the creator)\n";
     147#      print STDOUT "   -public true|false  If this collection has anonymous access\n";
     148#      print STDOUT "   -title text         The title for the collection\n";
     149#      print STDOUT "   -about text         The about text for the collection\n";
     150#      print STDOUT "   -plugin text        perl plugin module to use (there may be multiple\n";
     151#      print STDOUT "                       plugin entries)\n";
     152#      print STDOUT "   -quiet              Operate quietly\n";
     153#      print STDOUT "  Note that -creator must be specified. You can make changes to all\n";
     154#      print STDOUT "  options later by editing the collect.cfg configuration file for your\n";
     155#      print STDOUT "  new collection (it'll be in the \"etc\" directory).\n\n";
     156#      print STDOUT "  [Type \"perl -S mkcol.pl | more\" if this help text scrolled off your screen]";
     157#      print STDOUT "\n" unless $ENV{'GSDLOS'} =~ /^windows$/i;
     158#  }
    70159
    71160sub traverse_dir
     
    141230              'plugin/.+', \@plugin,
    142231              'quiet', \$quiet,
     232              q^xml^, \$xml
    143233              )) {
    144     &print_usage();
     234    &print_txt_usage();
    145235    die "\n";
    146236    }
     
    150240
    151241    &parse_args (\@ARGV);
     242
     243    if ($xml) {
     244    &print_xml_usage();
     245    die "\n";
     246    }
     247
    152248    if ($optionfile =~ /\w/) {
    153249    open (OPTIONS, $optionfile) || die "Couldn't open $optionfile\n";
     
    172268    if (!defined($collection)) {
    173269    print STDOUT "ERROR: no collection name was specified\n";
    174     &print_usage();
     270    &print_txt_usage();
    175271    die "\n";
    176272    }
Note: See TracChangeset for help on using the changeset viewer.