Ignore:
Timestamp:
2013-05-06T15:29:38+12:00 (11 years ago)
Author:
jmt12
Message:

Moving the critical file-related functions (copy, rm, etc) out of util.pm into their own proper class FileUtils. Use of the old functions in util.pm will prompt deprecated warning messages. There may be further functions that could be moved across in the future, but these are the critical ones when considering supporting other filesystems (HTTP, HDFS, WebDav, etc). Updated some key files to use the new functions so now deprecated messages thrown when importing/building demo collection 'out of the box'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugout.pm

    r14929 r27306  
    3131
    3232require util;
     33use FileUtils;
    3334use gsprintf 'gsprintf';
    3435
     
    4445my ($verbosity, $outhandle, $failhandle, $globaloptions);
    4546
     47# - significantly rewritten to support plugouts in extensions [jmt12]
    4648sub load_plugout{
    4749    my ($plugout) = shift @_;
     50    my $plugout_name = shift @$plugout;
     51    my $plugout_suffix = &FileUtils::filenameConcatenate('perllib', 'plugouts', $plugout_name . '.pm');
     52    my $plugout_found = 0;
    4853
    49     my $colplugdir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib/plugouts");
    50     unshift (@INC, $colplugdir);
    51    
    52     my $plugoutname = shift @$plugout;
     54    # add collection plugout directory to INC unless it is already there
     55    my $colplugdir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'},'perllib','plugouts');
     56    if (-d $colplugdir)
     57    {
     58      my $found_colplugdir = 0;
     59      foreach my $path (@INC)
     60      {
     61        if ($path eq $colplugdir)
     62        {
     63          $found_colplugdir = 1;
     64          last;
     65        }
     66      }
     67      if (!$found_colplugdir)
     68      {
     69        unshift (@INC, $colplugdir);
     70      }
     71    }
    5372
    54     # find the plugout
    55     my $customplugname;
     73    # To find the plugout we check a number of possible locations
     74    # - any plugout found in the collection itself is our first choice, with
     75    #   those located in 'custom' having precedence
    5676    if (defined($ENV{'GSDLCOLLECTION'}))
    5777    {
    58         $customplugname = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "custom", $ENV{'GSDLCOLLECTION'},
    59                          'perllib', 'plugouts', "${plugoutname}.pm");
     78      my $collect_dir = $ENV{'GSDLCOLLECTION'};
     79
     80      # (needed for Veridian?)
     81      my $custom_plugout = &FileUtils::filenameConcatenate($collect_dir, "custom", $collect_dir, $plugout_suffix);
     82      if (&FileUtils::fileExists($custom_plugout))
     83      {
     84        require $custom_plugout;
     85        $plugout_found = 1;
     86      }
     87      else
     88      {
     89        # typical collection override
     90        my $collection_plugout = &FileUtils::filenameConcatenate($collect_dir, $plugout_suffix);
     91        if (&FileUtils::fileExists($collection_plugout))
     92        {
     93          require $custom_plugout;
     94          $plugout_found = 1;
     95        }
     96      }
     97    }
     98    # - we then search for overridden version provided by any registered GS3
     99    #   extensions (check in order of extension definition)
     100    if (!$plugout_found && defined $ENV{'GSDL3EXTS'})
     101    {
     102      my $ext_prefix = &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'}, "ext");
     103      my @extensions = split(/:/,$ENV{'GSDL3EXTS'});
     104      foreach my $e (@extensions)
     105      {
     106        my $extension_plugout = &FileUtils::filenameConcatenate($ext_prefix, $e, $plugout_suffix);
     107        if (&FileUtils::fileExists($extension_plugout))
     108        {
     109          require $extension_plugout;
     110          $plugout_found = 1;
     111        }
     112      }
     113    }
     114    # - similar for GS2 extensions
     115    if (!$plugout_found && defined $ENV{'GSDLEXTS'})
     116    {
     117      my $ext_prefix = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, "ext");
     118      my @extensions = split(/:/,$ENV{'GSDLEXTS'});
     119      foreach my $e (@extensions)
     120      {
     121        my $extension_plugout = &FileUtils::filenameConcatenate($ext_prefix, $e, $plugout_suffix);
     122        if (&FileUtils::fileExists($extension_plugout))
     123        {
     124          require $extension_plugout;
     125          $plugout_found = 1;
     126        }
     127      }
     128    }
     129    # - and the default is the main Greenstone version of the plugout
     130    if (!$plugout_found)
     131    {
     132      my $main_plugout = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, $plugout_suffix);
     133      if (&FileUtils::fileExists($main_plugout))
     134      {
     135        require $main_plugout;
     136        $plugout_found = 1;
     137      }
    60138    }
    61139
    62     my $colplugname = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, 'perllib', 'plugouts',
    63                       "${plugoutname}.pm");
    64     my $mainplugname = &util::filename_cat($ENV{'GSDLHOME'}, 'perllib', 'plugouts',
    65                       "${plugoutname}.pm");
    66     if (defined($customplugname) && -e $customplugname) { require $customplugname; }
    67     elsif (-e $colplugname) { require $colplugname; }
    68     elsif (-e $mainplugname) { require $mainplugname; }
    69     else {
    70     gsprintf($outhandle, "{plugout.could_not_find_plugout}\n",
    71          $plugoutname);
    72         die "\n";
     140    # - no plugout found with this name
     141    if (!$plugout_found)
     142    {
     143      gsprintf($outhandle, "{plugout.could_not_find_plugout}\n", $plugout_name);
     144      die "\n";
    73145    }
    74146
    75     # create a plugout object
     147    # - create a plugout object
    76148    my ($plugobj);
    77149
    78     eval ("\$plugobj = new \$plugoutname([],\$plugout)");
     150    eval ("\$plugobj = new \$plugout_name([],\$plugout)");
    79151    die "$@" if $@;
    80152
Note: See TracChangeset for help on using the changeset viewer.