logical puzzle: how to generate reasonable archive file names from file and directory names

fBechmann fBechmann at web.de
Thu Jun 10 03:13:15 EDT 2004


I'm writing a module to convert between filesystem nodes 
(directory,file) and various archives (gz, zip, tgz).

For this I want to automatically create reasonable file names for the 
archives where these file names depend from the type of the file system 
node to be archived and from the type of the archive to be created.

I want the following transformations to take place:

Dir
   abc     =(gz)=>      *not allowed*
           =(zip,tgz)=> abz.zip,abc.tgz
   abc.XY  =(gz)=>      *not allowed*
           =(zip,tgz)=> abc.XY.zip,abc.XY.tgz

File
   abc     =(gz)=>      abc.gz
           =(zip,tgz)=> abz.zip,abc.tgz
   abc.ext =(gz)=>      abc.ext.gz
           =(zip,tgz)=> abc.zip,abc.tgz

For the decision to remove the extension from the file or directory this 
  gives me the following table:

            gz          zip,tgz
    Dir     *n.a.*      no
    File    no          yes

I have the classes Dir, File, ArchiveGZ and MultiFileArchive (base class 
for ArchiveTGZ and ArchiveZIP, which share behaviour w/ respect to that 
naming transformation).

I've found a way which looks quite cruel (and which I'll post later), so 
I have the hope that someone here finds a nice snippet of code for this.

thx in advance



More information about the Python-list mailing list