I am new to Perl and would like to figure out how to change this import script to import PDF's instead of Images.
here i the script:
#!/usr/bin/perl
package Egrail;
###########################################################
##
## $Id: importassets.pl,v 1.5 2002/07/11 09:24:11 achoi Exp $
##
##
## Author: unknown
##
## Created: unknown
##
## Description: Bulk image upload
##
## Outputs: none
##
## Returns: none
##
## Side-effects: insertion of assets
##
## Status: none
##
## Comments:
## usage: importassets.pl [-d] [-ddb]
## [-parent parent_folder] [-ext relativeroot] ## site importdir
##
## -d : debug mode
## -ddb : database debug mode
## -parent parent_folder : insert assets under a specific parent folder
## -ext relativeroot : create assets as external assets url
## site : site name
## importdir : directory where are stored the assets
##
## Teamtrack Id: BUG02006
##
###########################################################
$parent_folder = '';
$external = '';
$check = shift;
while ($check =~ /^-/) {
if ($check =~ /usehtml/) {
$usehtml = 1;
} elsif ($check =~/d$/) {
$Debug = 1;
} elsif ($check =~/ddb$/) {
$DBDebug = 1;
} elsif ($check =~/parent$/) {
$parent_folder = shift;
} elsif ($check =~/ext$/) {
$external = shift;
}
$check = shift;
}
$phpdir = $check;
$import_dir = shift;
die "Usage: $0 [-usehtml] [-d] [-ddb] [-parent parent_folder] [-ext relativeroot] site importdir\n" unless ($phpdir && $import_dir);
$EGRAIL_CONFIG = "/usr/local/eGrail/config";
$EGRAIL_CONFIG = $ENV{"EGRAIL_CONFIG"} if ($ENV{"EGRAIL_CONFIG"});
if (-r "$EGRAIL_CONFIG/config.pl" {
require "$EGRAIL_CONFIG/config.pl";
} else {
$HOME = $ENV{"HOME"};
$EGRAIL_CONFIG = "$HOME/eGrail";
if (-r "$EGRAIL_CONFIG/config.pl" {
require "$EGRAIL_CONFIG/config.pl";
} else {
die "Unable to load configuration file, config.pl";
}
}
# Load in the defaults
require "$ScriptRoot/$ScriptDir/perl-lib/common.pl";
require "$ScriptRoot/$ScriptDir/perl-lib/systemcall.pl";
# FUNCTION Defaults
$image_import = 1;
$image_external = 1; # Import them externally
$image_folderroot = 2;
$import_imagesonly = 1;
$OutputErrors = 1;
$pcid = 0;
if ($parent_folder) {
$pcid = &Egrail::Assets::GetFolder($parent_folder);
}
# Run the Thing;
find(\&ImportAssets, $import_dir);
exit; # go away peacefully
# Only functions below this line
sub ImportAssets {
my($name, $dir, $file) = ($File::Find::name, $File::Find::dir, $_);
my($mydir) = substr $dir, length($import_dir); # This gives us the relative root /image/etc
my($am_content) = '';
# We don't want CVS files
$File::Find:rune = 1 if ($_ =~ /^CVS$/);
return if ($_ =~ /^CVS$/);
# No directories this far
return if (-d "$dir/$file"
if (($file =~ /gif$/i) || ($file =~ /jpeg$/i) || ($file =~ /png$/i) || ($file =~ /jpg$/i)) { # Image
print "Examining $name, $dir, $file ... ";
if ($external) { $ext_url = "$external$mydir/$file"; } else { $ext_url = ""; }
if ($pcid) {
$aid = &Egrail::Assets::SubmitAsset($file, $file, $file, "$parent_folder/$mydir", $ext_url);
if ($Egrail:ebug) { print "\nIMPORTED: ($aid) $mydir/$file -> $parent_folder as $file\n"; }
} else {
$aid = &Egrail::Assets::SubmitAsset($file, $file, "$dir/$file", $mydir, $ext_url);
if ($Egrail:ebug) { print "\nIMPORTED: ($aid) $mydir/$file -> $mydir as $file\n"; }
}
}
print "OK.\n";
return;
}
Thanks for any help you can offer.
-=Rick Cruz=-
here i the script:
#!/usr/bin/perl
package Egrail;
###########################################################
##
## $Id: importassets.pl,v 1.5 2002/07/11 09:24:11 achoi Exp $
##
##
## Author: unknown
##
## Created: unknown
##
## Description: Bulk image upload
##
## Outputs: none
##
## Returns: none
##
## Side-effects: insertion of assets
##
## Status: none
##
## Comments:
## usage: importassets.pl [-d] [-ddb]
## [-parent parent_folder] [-ext relativeroot] ## site importdir
##
## -d : debug mode
## -ddb : database debug mode
## -parent parent_folder : insert assets under a specific parent folder
## -ext relativeroot : create assets as external assets url
## site : site name
## importdir : directory where are stored the assets
##
## Teamtrack Id: BUG02006
##
###########################################################
$parent_folder = '';
$external = '';
$check = shift;
while ($check =~ /^-/) {
if ($check =~ /usehtml/) {
$usehtml = 1;
} elsif ($check =~/d$/) {
$Debug = 1;
} elsif ($check =~/ddb$/) {
$DBDebug = 1;
} elsif ($check =~/parent$/) {
$parent_folder = shift;
} elsif ($check =~/ext$/) {
$external = shift;
}
$check = shift;
}
$phpdir = $check;
$import_dir = shift;
die "Usage: $0 [-usehtml] [-d] [-ddb] [-parent parent_folder] [-ext relativeroot] site importdir\n" unless ($phpdir && $import_dir);
$EGRAIL_CONFIG = "/usr/local/eGrail/config";
$EGRAIL_CONFIG = $ENV{"EGRAIL_CONFIG"} if ($ENV{"EGRAIL_CONFIG"});
if (-r "$EGRAIL_CONFIG/config.pl" {
require "$EGRAIL_CONFIG/config.pl";
} else {
$HOME = $ENV{"HOME"};
$EGRAIL_CONFIG = "$HOME/eGrail";
if (-r "$EGRAIL_CONFIG/config.pl" {
require "$EGRAIL_CONFIG/config.pl";
} else {
die "Unable to load configuration file, config.pl";
}
}
# Load in the defaults
require "$ScriptRoot/$ScriptDir/perl-lib/common.pl";
require "$ScriptRoot/$ScriptDir/perl-lib/systemcall.pl";
# FUNCTION Defaults
$image_import = 1;
$image_external = 1; # Import them externally
$image_folderroot = 2;
$import_imagesonly = 1;
$OutputErrors = 1;
$pcid = 0;
if ($parent_folder) {
$pcid = &Egrail::Assets::GetFolder($parent_folder);
}
# Run the Thing;
find(\&ImportAssets, $import_dir);
exit; # go away peacefully
# Only functions below this line
sub ImportAssets {
my($name, $dir, $file) = ($File::Find::name, $File::Find::dir, $_);
my($mydir) = substr $dir, length($import_dir); # This gives us the relative root /image/etc
my($am_content) = '';
# We don't want CVS files
$File::Find:rune = 1 if ($_ =~ /^CVS$/);
return if ($_ =~ /^CVS$/);
# No directories this far
return if (-d "$dir/$file"
if (($file =~ /gif$/i) || ($file =~ /jpeg$/i) || ($file =~ /png$/i) || ($file =~ /jpg$/i)) { # Image
print "Examining $name, $dir, $file ... ";
if ($external) { $ext_url = "$external$mydir/$file"; } else { $ext_url = ""; }
if ($pcid) {
$aid = &Egrail::Assets::SubmitAsset($file, $file, $file, "$parent_folder/$mydir", $ext_url);
if ($Egrail:ebug) { print "\nIMPORTED: ($aid) $mydir/$file -> $parent_folder as $file\n"; }
} else {
$aid = &Egrail::Assets::SubmitAsset($file, $file, "$dir/$file", $mydir, $ext_url);
if ($Egrail:ebug) { print "\nIMPORTED: ($aid) $mydir/$file -> $mydir as $file\n"; }
}
}
print "OK.\n";
return;
}
Thanks for any help you can offer.
-=Rick Cruz=-