[Bio] / FigKernelScripts / Packager.pl Repository:
ViewVC logotype

Diff of /FigKernelScripts/Packager.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Tue Aug 16 22:38:36 2005 UTC revision 1.5, Mon Dec 5 18:56:37 2005 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    #
3    # Copyright (c) 2003-2006 University of Chicago and Fellowship
4    # for Interpretations of Genomes. All Rights Reserved.
5    #
6    # This file is part of the SEED Toolkit.
7    #
8    # The SEED Toolkit is free software. You can redistribute
9    # it and/or modify it under the terms of the SEED Toolkit
10    # Public License.
11    #
12    # You should have received a copy of the SEED Toolkit Public License
13    # along with this program; if not write to the University of Chicago
14    # at info@ci.uchicago.edu or the Fellowship for Interpretation of
15    # Genomes at veronika@thefig.info or download a copy from
16    # http://www.theseed.org/LICENSE.TXT.
17    #
18    
19    
20  =head1 Packager  =head1 Packager
21    
22    C<Packager> [I<options>] C<scan>|C<pack>|C<unpack> I<directoryRoot> I<packageFile>
23    
24  Package all the files in a directory tree for transport or recreate the directory  Package all the files in a directory tree for transport or recreate the directory
25  tree from the packaged files.  tree from the packaged files.
26    
27  This method takes as input three positional parameters: a command, the name of the  This method takes as input three positional parameters.
28  root for the directory tree and the name of the package files. If the command is  
29  C<pack>, the files are packaged into one or more text files. If the command is  =over 4
30  C<unpack>, the files are unpackaged from the text files. If the command is  
31  C<scan>, the files are examined to determine the file types.  =item command
32    
33    C<pack> to package the files into a single package file, <unpack> to restore
34    the files from the package file, or C<scan> to scan the files to determine
35    file types.
36    
37    =item directoryRoot
38    
39    Root directory of the directory tree. If scanning or packing, all files in this
40    tree will be packaged. If unpacking, the files are unpacked into this tree.
41    
42    =item packageFile
43    
44    Name of the package file. If packing, this is the output file. If unpacking,
45    this is the input file.
46    
47    =back
48    
49  File and directory names should be specified using Unix conventions, with a  File and directory names should be specified using Unix conventions, with a
50  forward slash (C</>) instead of a backslash (C<\>).  forward slash (C</>) instead of a backslash (C<\>).
51    
 File names ending in a tilde (C<~>) or C<.bak> will be ignored when scanning or  
 packaging. These files are presumed to be temporary backups.  
   
52  The process of packaging is straightforward. We write out the name of the input file,  The process of packaging is straightforward. We write out the name of the input file,
53  its type (text or binary), the file data itself, and an MD5 digest. Each file is  its type (text or binary), the file data itself, and an MD5 digest. Each file is
54  compressed using the PERL C<Compress::Zlib> libary.  compressed using the PERL C<Compress::Zlib> libary.
# Line 42  Line 74 
74    
75  Temporary files in the directory tree are skipped when scanning or packaging. A file  Temporary files in the directory tree are skipped when scanning or packaging. A file
76  is considered temporary if its name ends in a tilde (C<~>) or pound sign C<#>,  is considered temporary if its name ends in a tilde (C<~>) or pound sign C<#>,
77  or it has an extension of C<.bak> or C<.tgz>.  or it has an extension of C<.bak> or C<.tgz>. In addition, directories with names
78    ending in C<.old> will be skipped.
79    
80  =cut  =cut
81    
# Line 275  Line 308 
308              # These are counters for various file types.              # These are counters for various file types.
309              tempCount => 0,              tempCount => 0,
310              dirCount => 0,              dirCount => 0,
311                dirSkip => 0,
312              foundCount => 0              foundCount => 0
313          };          };
314  }  }
# Line 304  Line 338 
338              # Here we've found a real file. Now we need to check for a temporary file name.              # Here we've found a real file. Now we need to check for a temporary file name.
339              if ($nextName =~ /(~|#|\.bak|\.tgz)$/) {              if ($nextName =~ /(~|#|\.bak|\.tgz)$/) {
340                  # We have a temporary file name, so we count it and keep going.                  # We have a temporary file name, so we count it and keep going.
341                  $dirObject->{tempCount}++;                  $dirObject->{dirSkip}++;
342              } else {              } else {
343                  # Here we have a non-temporary name, so we're done.                  # Here we have a non-temporary name, so we're done.
344                  $done = 1;                  $done = 1;
# Line 316  Line 350 
350                  my ($path, $suffix) = NameParse($nextName);                  my ($path, $suffix) = NameParse($nextName);
351                  $dirObject->{suffix} = lc $suffix;                  $dirObject->{suffix} = lc $suffix;
352              }              }
353            } elsif ($nextName =~ /\.old$/) {
354                # Here we have a backup directory.
355                $dirObject->{dirSkip}++;
356          } else {          } else {
357              # Here we have a directory. We need to push all its members on the stack.              # Here we have a directory. We need to push all its members on the stack.
358              # Note that file names beginning with a period are ignored.              # Note that file names beginning with a period are ignored.
# Line 342  Line 379 
379      my $dirCount = $dirObject->{dirCount};      my $dirCount = $dirObject->{dirCount};
380      my $tempCount = $dirObject->{tempCount};      my $tempCount = $dirObject->{tempCount};
381      my $foundCount = $dirObject->{foundCount};      my $foundCount = $dirObject->{foundCount};
382      return "$foundCount files found, $tempCount temporary files ignored, $dirCount directories processed.\n";      my $dirSkip = $dirObject->{dirSkip};
383        return "$foundCount files found, $tempCount temporary files ignored, $dirCount directories processed, $dirSkip directories skipped.\n";
384  }  }
385    
386  =head3 NameParse  =head3 NameParse
# Line 719  Line 757 
757  one end record.  one end record.
758    
759  To prevent file system compatibility problems, the name is automatically cleaned  To prevent file system compatibility problems, the name is automatically cleaned
760  before the file is created: all spaces and colons are converted to underscores.  before the file is created: all spaces and colons are converted to underscores,
761    and question marks are converted to the double letter C<QQ>.
762    
763  Text files are open in text mode and binary files in binary mode. As a result, the  Text files are open in text mode and binary files in binary mode. As a result, the
764  line-end characters in a text file are automatically translated to the line-end  line-end characters in a text file are automatically translated to the line-end
# Line 924  Line 963 
963    
964  sub CreateFile {  sub CreateFile {
965      my ($fileName, $mode, $directory, $compObject) = @_;      my ($fileName, $mode, $directory, $compObject) = @_;
966      # Clear the file name.      # Clean the file name.
967      $fileName =~ tr/: /__/;      $fileName =~ tr/: /__/;
968        $fileName =~ s/\?/QQ/g;
969      # Add the file name to the directory to get the fully-qualified file name.      # Add the file name to the directory to get the fully-qualified file name.
970      my $fullName = "$directory/$fileName";      my $fullName = "$directory/$fileName";
971      # Extract the path.      # Extract the path.

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.5

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3