Back to index

freevial  1.2
Public Member Functions | Public Attributes | Private Member Functions
questions.LoadDatabase Class Reference

List of all members.

Public Member Functions

def __init__
def get

Public Attributes

 files

Private Member Functions

def _get_real_path
def _extract
def _get_temp
def _xml_in_path
def _files_in_path

Detailed Description

Definition at line 37 of file questions.py.


Constructor & Destructor Documentation

def questions.LoadDatabase.__init__ (   self,
  directory 
)
Load a question database (directory or compressed file). 

Definition at line 39 of file questions.py.

00039 
00040        def __init__(self, directory):
00041               """ Load a question database (directory or compressed file). """
00042               
00043               try:
00044                      self.files = self._xml_in_path(self._get_real_path(directory))
00045               
00046               except IOError:
00047                      print _('Error: Couldn\'t find the current questions database.')
00048                      print _('You can provide the location to that one you want to use by passing the --database option.')
00049                      print _('For example: freevial --database ~/questions.tar.gz')
00050                      sys.exit(1)
       

Member Function Documentation

def questions.LoadDatabase._extract (   self,
  directory 
) [private]
Extracts a compressed file to a temporal directory and returns
the URL to it. 

Definition at line 74 of file questions.py.

00074 
00075        def _extract(self, directory):
00076               """ Extracts a compressed file to a temporal directory and returns
00077               the URL to it. """
00078               
00079               file = Uncompressor(directory)
00080               tempdir = self._get_temp()
00081               
00082               file.extractall(tempdir)
00083               return tempdir
       

Here is the call graph for this function:

Here is the caller graph for this function:

def questions.LoadDatabase._files_in_path (   self,
  directory 
) [private]
Returns a list with the name of all the files in the given directory. 

Definition at line 99 of file questions.py.

00099 
00100        def _files_in_path(self, directory):
00101               """ Returns a list with the name of all the files in the given directory. """
00102               
00103               for files in (files for dirpath, dirnames, files in os.walk(directory)):
00104                      return [ '%s' % os.path.abspath(os.path.join(directory, file)) for file in files ]
00105 
00106 
# Create the XML parser

Here is the caller graph for this function:

def questions.LoadDatabase._get_real_path (   self,
  directory 
) [private]
If the given path is directory it is returned as-is, if it's
is a compressed file the path to a extracted version to it (on a
temporal directory) is returned. Else ValueError is raised; if
the directory/file doesn't exist at all, it raises IOError.

Definition at line 55 of file questions.py.

00055 
00056        def _get_real_path(self, directory):
00057               """ If the given path is directory it is returned as-is, if it's
00058               is a compressed file the path to a extracted version to it (on a
00059               temporal directory) is returned. Else ValueError is raised; if
00060               the directory/file doesn't exist at all, it raises IOError."""
00061               
00062               if not os.path.exists(directory):
00063                      raise IOError, _('Indicated directory of file doesn\'t exist or has wrong permissions.')
00064               
00065               if os.path.isdir(directory):
00066                      return directory
00067               
00068               ext = os.path.splitext(directory)[1][1:]  # Get the extension
00069               
00070               if ext in ('gz', 'bz2', 'zip'):
00071                      return self._extract(directory)
00072               
00073               raise ValueError, _('Expected a directory or compressed file.')
       

Here is the call graph for this function:

def questions.LoadDatabase._get_temp (   self) [private]
Creates a temporary directory.

Definition at line 84 of file questions.py.

00084 
00085        def _get_temp(self):
00086               """ Creates a temporary directory."""
00087               
00088               import tempfile
00089               return tempfile.mkdtemp('', 'freevial-') + '/'
       

Here is the caller graph for this function:

def questions.LoadDatabase._xml_in_path (   self,
  directory 
) [private]

Definition at line 90 of file questions.py.

00090 
00091        def _xml_in_path(self, directory):
00092               
00093               files = []
00094               
00095               for file in self._files_in_path(directory):
00096                      if file[-4:] == '.xml': files.append(file)
00097               
00098               return files
       

Here is the call graph for this function:

Definition at line 51 of file questions.py.

00051 
00052        def get(self):
00053               
00054               return self.files
       

Member Data Documentation

Definition at line 43 of file questions.py.


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