[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.2, Wed Aug 17 02:37:07 2005 UTC revision 1.7, Thu Dec 6 14:00:37 2007 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 137  Line 169 
169    
170  =head3 ScanTree  =head3 ScanTree
171    
172  C<< ScanTree($directory); >>      ScanTree($directory);
173    
174  Scan all files in the specified directory and create an C<extensions.txt> file  Scan all files in the specified directory and create an C<extensions.txt> file
175  listing the extensions of files that are binary.  listing the extensions of files that are binary.
# Line 197  Line 229 
229    
230  =head3 ScanFile  =head3 ScanFile
231    
232  C<< my $type = ScanFile($fileName, $size); >>      my $type = ScanFile($fileName, $size);
233    
234  Survey the specified file of the specified size to determine whether it is  Survey the specified file of the specified size to determine whether it is
235  text or binary. A file is binary if it has a lot of control characters or  text or binary. A file is binary if it has a lot of control characters or
# Line 257  Line 289 
289    
290  =head3 OpenDirectory  =head3 OpenDirectory
291    
292  C<< my $dirObject = OpenDirectory($directoryName); >>      my $dirObject = OpenDirectory($directoryName);
293    
294  This method returns an object that can be used to find all the files in a directory  This method returns an object that can be used to find all the files in a directory
295  tree. The incoming parameter is the directory tree name, properly cleaned and with  tree. The incoming parameter is the directory tree name, properly cleaned and with
# Line 283  Line 315 
315    
316  =head3 GetFileName  =head3 GetFileName
317    
318  C<< my $fileName = GetFileName($dirObject); >>      my $fileName = GetFileName($dirObject);
319    
320  This method returns the next file name for a directory tree. The incoming parameter is  This method returns the next file name for a directory tree. The incoming parameter is
321  a directory object returned by OpenDirectory. If all the files have been processed, the  a directory object returned by OpenDirectory. If all the files have been processed, the
# Line 336  Line 368 
368    
369  =head3 InSummary  =head3 InSummary
370    
371  C<< print InSummary($dirObject); >>      print InSummary($dirObject);
372    
373  Return a summary of the files processed by a directory object.  Return a summary of the files processed by a directory object.
374    
# Line 353  Line 385 
385    
386  =head3 NameParse  =head3 NameParse
387    
388  C<< my ($path, $suffix) = NameParse($fileName); >>      my ($path, $suffix) = NameParse($fileName);
389    
390  Separate the directory path and suffix out of a file name. Note that if the suffix  Separate the directory path and suffix out of a file name. Note that if the suffix
391  is entirely numeric, we return a suffix of "#".  is entirely numeric, we return a suffix of "#".
# Line 381  Line 413 
413    
414  =head3 StartFile  =head3 StartFile
415    
416  C<< StartFile($mode, $fileName); >>      StartFile($mode, $fileName);
417    
418  Open the specified file for compression input. The file handle used is CLEARFILE.  Open the specified file for compression input. The file handle used is CLEARFILE.
419    
# Line 403  Line 435 
435    
436  =head3 GetCharacters  =head3 GetCharacters
437    
438  C<< my $characters = GetCharacters($mode); >>      my $characters = GetCharacters($mode);
439    
440  Get some characters to compress from the current input file. If we have reached  Get some characters to compress from the current input file. If we have reached
441  end-of-file, returns an empty list.  end-of-file, returns an empty list.
# Line 448  Line 480 
480    
481  =head3 GetExtensions  =head3 GetExtensions
482    
483  C<< my %extHash = GetExtensions($directory); >>      my %extHash = GetExtensions($directory);
484    
485  Create a hash containing the extensions of the binary files in the specified  Create a hash containing the extensions of the binary files in the specified
486  directory tree.  directory tree.
# Line 478  Line 510 
510    
511  =head3 StartPackaging  =head3 StartPackaging
512    
513  C<< my $packObject = StartPackaging($packageFileName); >>      my $packObject = StartPackaging($packageFileName);
514    
515  Prepare to create the package file.  Prepare to create the package file.
516    
# Line 501  Line 533 
533    
534  =head3 WritePackageLine  =head3 WritePackageLine
535    
536  C<< WritePackageLine($packObject, $line); >>      WritePackageLine($packObject, $line);
537    
538  Write a line of text data to the package file. A text line is preceded by a space character  Write a line of text data to the package file. A text line is preceded by a space character
539  and is terminated by a line feed character.  and is terminated by a line feed character.
# Line 519  Line 551 
551    
552  =head3 FinishPackaging  =head3 FinishPackaging
553    
554  C<< FinishPackaging($packObject); >>      FinishPackaging($packObject);
555    
556  Finish the packaging process. This basically closes the package file.  Finish the packaging process. This basically closes the package file.
557    
# Line 531  Line 563 
563    
564  =head3 StartCompressedData  =head3 StartCompressedData
565    
566  C<< StartCompressedData($packObject, $compTable); >>      StartCompressedData($packObject, $compTable);
567    
568  Initialize for writing compressed file data. Compressed file data is output in fixed-  Initialize for writing compressed file data. Compressed file data is output in fixed-
569  length blocks preceded by a C<b> character. (This distinguishes them from text lines,  length blocks preceded by a C<b> character. (This distinguishes them from text lines,
# Line 555  Line 587 
587    
588  =head3 WriteCompressedData  =head3 WriteCompressedData
589    
590  C<< WriteCompressedData($packObject, $data, $status); >>      WriteCompressedData($packObject, $data, $status);
591    
592  Add a block of data to the compressed output. The data is accumulated until we fill  Add a block of data to the compressed output. The data is accumulated until we fill
593  an entire block, at which time it is written to the file with the appropriate marker.  an entire block, at which time it is written to the file with the appropriate marker.
# Line 598  Line 630 
630    
631  =head3 WriteEndMark  =head3 WriteEndMark
632    
633  C<< my $outCount = WriteEndMark($packObject); >>      my $outCount = WriteEndMark($packObject);
634    
635  Write out the last block of a compressed data stream and return the total number of bytes  Write out the last block of a compressed data stream and return the total number of bytes
636  in the stream.  in the stream.
# Line 628  Line 660 
660    
661  =head3 PackTree  =head3 PackTree
662    
663  C<< PackTree($directory, $packageFileName); >>      PackTree($directory, $packageFileName);
664    
665  Package all files in a directory tree into a package file.  Package all files in a directory tree into a package file.
666    
# Line 675  Line 707 
707    
708  =head3 PackFile  =head3 PackFile
709    
710  C<< PackFile($fileName, $packObject, $mode); >>      PackFile($fileName, $packObject, $mode);
711    
712  Compress the specified file to the specified package file in the specified mode.  Compress the specified file to the specified package file in the specified mode.
713    
# Line 712  Line 744 
744    
745  =head3 UnPackTree  =head3 UnPackTree
746    
747  C<< UnPackTree($directory, $packageFile); >>      UnPackTree($directory, $packageFile);
748    
749  Read file data from a package file and put it into a directory tree.  Read file data from a package file and put it into a directory tree.
750    
# Line 725  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 776  Line 809 
809    
810  =head3 StartUnPacking  =head3 StartUnPacking
811    
812  C<< my $packObject = StartUnPacking($packageFile); >>      my $packObject = StartUnPacking($packageFile);
813    
814  Prepare to read from a package file.  Prepare to read from a package file.
815    
# Line 796  Line 829 
829    
830  =head3 GetTextRecord  =head3 GetTextRecord
831    
832  C<< my $data = GetTextRecord($packObject); >>      my $data = GetTextRecord($packObject);
833    
834  Read a text record from the package file. The text record begins with a space and  Read a text record from the package file. The text record begins with a space and
835  ends with a new-line character.  ends with a new-line character.
# Line 844  Line 877 
877    
878  =head3 GetBlock  =head3 GetBlock
879    
880  C<< my $block = GetBlock($packObject); >>      my $block = GetBlock($packObject);
881    
882  Read a block of compressed data from the package file. If the end of the compressed data  Read a block of compressed data from the package file. If the end of the compressed data
883  has been reached, will return an undefined value.  has been reached, will return an undefined value.
# Line 922  Line 955 
955    
956  =head3 CreateFile  =head3 CreateFile
957    
958  C<< my $fileObject = CreateFile($fileName, $mode, $directory, $compObject); >>      my $fileObject = CreateFile($fileName, $mode, $directory, $compObject);
959    
960  Create a file into which packaged data can be unpacked.  Create a file into which packaged data can be unpacked.
961    
# Line 930  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.
# Line 964  Line 998 
998    
999  =head3 WriteData  =head3 WriteData
1000    
1001  C<< WriteData($fileObject, $data, $status); >>      WriteData($fileObject, $data, $status);
1002    
1003  Write a block of data to the output file.  Write a block of data to the output file.
1004    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.7

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3