Back to index

freevial  1.2
Public Member Functions | Public Attributes | Private Member Functions
common.uncompress.Uncompressor Class Reference

List of all members.

Public Member Functions

def __init__
def extractall

Public Attributes

 type
 fileobj

Private Member Functions

def _detect
def _unzipAll
def _open

Detailed Description

Provides an interface to handle files compressed with both, tar and zip format, the same way.\n 

Definition at line 27 of file uncompress.py.


Constructor & Destructor Documentation

def common.uncompress.Uncompressor.__init__ (   self,
  filename,
  mode = 'r' 
)

Definition at line 30 of file uncompress.py.

00030 
00031        def __init__(self, filename, mode='r'):
00032               
00033               self._open(filename, mode)
00034        
       

Here is the call graph for this function:


Member Function Documentation

def common.uncompress.Uncompressor._detect (   self,
  filename 
) [private]
Detect which module needs to be used for the given file, and returns an instace of it.\n 

Definition at line 35 of file uncompress.py.

00035 
00036        def _detect(self, filename):
00037               """ Detect which module needs to be used for the given file, and returns an instace of it.\n """
00038               
00039               ext = os.path.splitext(filename)[1][1:]   # Get the extension
00040               
00041               if ext in ('gz', 'bz2'):
00042                      return 'tar'
00043               
00044               elif ext == 'zip':
00045                      return 'zip'
00046               
00047               else:
00048                      raise ValueError, 'Unsuported file format, expected .tar.gz, .tar.bz or .zip.'
00049        
       
def common.uncompress.Uncompressor._open (   self,
  filename,
  mode = 'r' 
) [private]
Open a compressed file for reading, writing or appending. 

Definition at line 64 of file uncompress.py.

00064 
00065        def _open(self, filename, mode='r'):
00066               """ Open a compressed file for reading, writing or appending. """
00067               
00068               self.type = self._detect(filename)
00069               
00070               if self.type == 'tar':
00071                      import tarfile
00072                      self.fileobj = tarfile.open(filename, mode)
00073               
00074               elif self.type == 'zip':
00075                      import zipfile
00076                      self.fileobj = zipfile.ZipFile(filename, mode)
00077        
       

Here is the caller graph for this function:

def common.uncompress.Uncompressor._unzipAll (   directory) [private]
Extract all members of the current zip file to the given directory. 

Definition at line 50 of file uncompress.py.

00050 
00051        def _unzipAll(directory):
00052               """ Extract all members of the current zip file to the given directory. """
00053               
00054               for name in self.fileobj.namelist():
00055                      
00056                      if name.endswith('/'):
00057                             os.mkdir(os.path.join(directory, name))
00058                      
00059                      else:
00060                             outfile = open(os.path.join(directory, name), 'wb')
00061                             outfile.write(self.fileobj.read(name))
00062                             outfile.close()
00063        
       

Here is the caller graph for this function:

def common.uncompress.Uncompressor.extractall (   self,
  directory = './' 
)
Extract all members from the archive to the given directory.

Definition at line 78 of file uncompress.py.

00078 
00079        def extractall(self, directory='./'):
00080               """Extract all members from the archive to the given directory."""
00081               
00082               if self.type == 'tar':
00083                      return self.fileobj.extractall(directory)
00084               
00085               elif self.type == 'zip':
00086                      return self._unzipAll(directory)

Here is the call graph for this function:


Member Data Documentation

Definition at line 71 of file uncompress.py.

Definition at line 67 of file uncompress.py.


The documentation for this class was generated from the following file: