Changeset 29678
- Timestamp:
- 2015-01-09T14:24:10+13:00 (9 years ago)
- Location:
- main/trunk/package-kits/scripts
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/package-kits/scripts/gs-servlet.pl
r29674 r29678 9 9 10 10 use lib 'perllib'; 11 use XML::Tidy;11 use Greenstone::XML::Tidy; 12 12 13 13 my $hash; … … 39 39 "Parses XML from a file into the internal state\n input_file (- for STDIN)", 40 40 sub { 41 my $file = shift @ARGV; 42 my $new; 43 if ($file eq '-') { 44 if (isatty *STDIN) { 45 print STDERR "Reading XML from STDIN. Press ^D to end\n"; 46 } 47 $new = read_xml *STDIN; 48 } else { 49 open FH, '<', $file; 50 $new = read_xml *FH; 51 close FH; 52 } 41 my $new = read_xml shift @ARGV; 53 42 # Append the new data to the current data 54 43 for my $key (keys %$new) { … … 73 62 "Writes the current internal state as XML to a file\n output_file (- for STDOUT)", 74 63 sub { 75 my $file = shift @ARGV; 76 if ($file eq '-') { 77 write_xml $hash, *STDOUT; 78 } else { 79 open FH, '>', $file; 80 write_xml $hash, *FH; 81 close FH; 82 } 64 write_xml $hash, shift @ARGV; 83 65 }, 84 66 1, -
main/trunk/package-kits/scripts/perllib/Greenstone/Config.pm
r29675 r29678 10 10 our $GSDLHOME = defined $ENV{GSDLHOME} ? $ENV{GSDLHOME} : $defaultGSDLHOME; 11 11 our $GSDL3HOME= defined $ENV{GSDL3HOME}? $ENV{GSDL3HOME}: $defaultGSDL3HOME; 12 13 1; -
main/trunk/package-kits/scripts/perllib/Greenstone/Directory.pm
r29677 r29678 14 14 my ($parent, $class, $name, %args) = @_; 15 15 ref $class and die "Constructor used as object method\n"; 16 defined $name or die " A site must have a name\n";16 defined $name or die "Must have a name\n"; 17 17 my $self = bless ( 18 18 { … … 31 31 my $parent = shift; 32 32 ref $parent and die "Static method called on object\n"; 33 my $ sites = {};33 my $dirs = {}; 34 34 my $dir = "$Greenstone::Config::GSDL3HOME/$parent"; 35 opendir DH, $dir or die "Could not open sitesdirectory '$dir'\n";36 while (my $ site= readdir DH) {35 opendir DH, $dir or die "Could not open directory '$dir'\n"; 36 while (my $entry = readdir DH) { 37 37 # skip hidden files and current/parent directory 38 $ site=~ /^\./ and next;38 $entry =~ /^\./ and next; 39 39 # skip non-directories 40 -d "$dir/$ site" or next;41 # We don't really need to store anything more than the fact that the siteexists40 -d "$dir/$entry" or next; 41 # We don't really need to store anything more than the fact that the directory exists 42 42 # So we just store nothing, which is enough to put the key in the hash 43 43 # (i.e. it acts as a hashset) 44 $ sites->{$site} = ();44 $dirs->{$entry} = (); 45 45 } 46 46 closedir DH; 47 return $ sites;47 return $dirs; 48 48 } 49 49 50 50 sub exists { 51 51 my $self = shift; 52 my $ sites = list $self->{parent};53 return exists $ sites->{$self->{name}};52 my $dirs = list $self->{parent}; 53 return exists $dirs->{$self->{name}}; 54 54 } 55 55 -
main/trunk/package-kits/scripts/perllib/Greenstone/Site.pm
r29677 r29678 25 25 my $dir = $self->dir; 26 26 mkdir "$dir/collect" or die "Failed to create collections directory: $!\n"; 27 open FH, '>', "$dir/siteConfig.xml" or die "Failed to create site config: $!\n"; 28 write_xml $configTemplate, *FH; 29 close FH; 30 return 1; 27 return write_xml $configTemplate, "$dir/siteConfig.xml"; 31 28 } 32 29 -
main/trunk/package-kits/scripts/perllib/Greenstone/XML/Tidy.pm
r29677 r29678 5 5 use utf8; 6 6 use XML::Parser; 7 use POSIX 'isatty'; 7 8 use base 'Exporter'; 8 9 … … 53 54 =cut 54 55 sub read_xml { 55 my $FH = shift; 56 local $/ = undef; 57 my $xml = <$FH>; 58 # The xml needs a root element, so we wrap it in one 59 $xml='<__root__>' . $xml . '</__root__>'; 56 my $file = shift; 57 my $xml; 58 if ($file eq '-') { 59 if (isatty *STDIN) { 60 print STDERR "Reading XML from STDIN. Press ^D to end\n"; 61 } 62 local $/ = undef; 63 $xml = '<__root__>' . <STDIN> . '</__root__>'; 64 } else { 65 $xml = '<!DOCTYPE doc [<!ENTITY real_doc SYSTEM "' . $file . '">]> 66 <__root__>&real_doc;</__root__>'; 67 } 60 68 # Parse the data using XML::Parser 61 69 my $data = new XML::Parser (Style => 'Tree')->parse ($xml); … … 98 106 # Writes a data structure to an XML file 99 107 sub write_xml { 100 my ($hash, $FH) = @_; 101 select $FH; 108 my ($hash, $file) = @_; 109 my $FH; 110 if ($file ne '-') { 111 unless (open $FH, '>:utf8', $file) { 112 print STDERR "Failed to open output file '$file': $!\n"; 113 return 0; 114 } 115 select $FH; 116 } 102 117 sub open_tag { 103 118 my ($indent, $tag, $attr) = @_; … … 155 170 } 156 171 write_element ("", $hash); 157 select STDOUT; 172 if ($file ne '-') { 173 select STDOUT; 174 close $FH; 175 } 176 return 1; 158 177 } 178 179 1;
Note:
See TracChangeset
for help on using the changeset viewer.