ConfigFileManager.ConfigFileManager Class Reference

Manage config parameters and file. More...

List of all members.

Public Member Functions

def __init__
def findFiles
 Starts the search of the files to be watched.
def getWatchedFiles
 Gets the list of "must be watched" files.
def addWatchedFiles
 Adds some files/dirs to the watched ones.
def getReWhiteList
 Gets the patterns whitelist.
def getReBlackList
 Gets the patterns blacklist.
def getWhiteList
 Gets the paths whitelist.
def getBlackList
 Gets the Paths blacklist.
def getOptions
 Obtains a list of the options in the section especified.
def getSections
 Obtains a list of the sections in the config file.
def hasOption
 Determines if the section given has te option especified.
def hasSection
 Determines if the section given exists in the config file.
def getOptionValue
 : Obtains the value of the given option in the given section.
def getFileOptionValue
 Obtains the value of the given option if exists whithin any section.
def addConfigItem
 Add new option to the config file.
def removeConfigItem
 Delete a config param from the config file.
def removeSection
 Delete a section from de config file.
def addSection
 Add new section to the config file.

Private Member Functions

def __mergeFileLists
 Obtains the list of files/dirs to be watched/backuped.
def __substr
 Determines if wpath is initial substr of bpath.
def __visitor
 Find the matches given with the filelist.
def __writeConfigObject
 Writes the Config File Object to the File itself.

Private Attributes

 __whitelist
 __watchedList

Static Private Attributes

tuple __watchedList = set()
 Files to be watched and backuped.
string __configFilePath = './prueba.cfg'
 Path to the config file.
tuple __config = ConfigParser.ConfigParser()
 ConfigParser instance, to manage the file.
tuple __reBlacklist = set()
 Patterns lists.
tuple __reWhitelist = set()
tuple __blacklist = set()
 Paths lists.
tuple __whitelist = set()


Detailed Description

Manage config parameters and file.

Wrapper around ConfigParser to provide hdlorean a simple interface with the configuration provided by the user and the program defaults. It also makes some operations on the config to make hdlorean easier manage of the config.

Author:
Adrián

Member Function Documentation

def ConfigFileManager.ConfigFileManager.__init__ (   self,
  start_find = False 
)

def ConfigFileManager.ConfigFileManager.findFiles (   self  ) 

Starts the search of the files to be watched.

If the files have not been searched yet, finds them and put the correct values in all the lists (black, white, watched...)

Returns:
True if the files are searched, False if they were previusly found.
Author:
Adrián

def ConfigFileManager.ConfigFileManager.__mergeFileLists (   self,
  start_dir 
) [private]

Obtains the list of files/dirs to be watched/backuped.

Unify both whitelist and blacklist (of patterns and of paths) in a new list containing only the files that must be watched/backuped by hdlorean. The method includes pattern expansion provided by fnmatch. The list is saved into watchedList

Parameters:
start_dir The root path where the search of patterns will start.
Author:
Adrián

def ConfigFileManager.ConfigFileManager.__substr (   self,
  bpath,
  wpath 
) [private]

Determines if wpath is initial substr of bpath.

Uses find to determine if the position in bpath of wpath is 0 and then return 1 (true). Otherwise it returns 0 (false).

Parameters:
bpath String to test if it has wpath as initial substr.
wpath String to test if is initial substr of bpath
Returns:
1 if wpath is substr of bpath. 0 Otherwise.
Author:
Adrián

def ConfigFileManager.ConfigFileManager.__visitor (   self,
  regexmatrix,
  dirname,
  filelist 
) [private]

Find the matches given with the filelist.

Internal function to be used in conjunction with os.path.walk. Each time this function is invoked, finds matches between the regexmatrix patterns and the list of files contained in the filelist arg. Returns each match file in the corresponding list (whitelist or blacklist).

Parameters:
regexmatrix A matrix containing in the first row the patterns of the blacklist and in the second row the patterns of the whitelist. This argument is provided to os.path.walk by the caller.
dirname The current dir. Provided by os.path.walk.
filelist All the files contained in dirname. Provided by os.path.walk
See also:
os.path.walk

Author:
Adrián TODO: Don't match regex against dirs?. Avoid repeated patterns between blacklist and whitelist

def ConfigFileManager.ConfigFileManager.__writeConfigObject (   self  )  [private]

Writes the Config File Object to the File itself.

Write all the changes made in the dynamic config file object to the disk.

Author:
Adrián

def ConfigFileManager.ConfigFileManager.getWatchedFiles (   self  ) 

Gets the list of "must be watched" files.

See also:
__mergeFileList
Returns:
The list of files that must be watched/backup-ed
Author:
Adrián

def ConfigFileManager.ConfigFileManager.addWatchedFiles (   self,
  files 
)

Adds some files/dirs to the watched ones.

Assumes that user really wants this files to be backuped so we insert them into the watched list and in the whitelist.

Parameters:
files A List containing the files to add.
Author:
Adrián

def ConfigFileManager.ConfigFileManager.getReWhiteList (   self  ) 

Gets the patterns whitelist.

The state of the patterns whitelist changes along the execution of this class, be carefull when you get the list.

Returns:
A Set containing the whitelisted patterns

def ConfigFileManager.ConfigFileManager.getReBlackList (   self  ) 

Gets the patterns blacklist.

The state of the patterns blacklist changes along the execution of this class, be carefull when you get the list.

Returns:
A Set containing the blacklisted patterns

def ConfigFileManager.ConfigFileManager.getWhiteList (   self  ) 

Gets the paths whitelist.

Keep in mind that the whitelist is not the filtered list of the files that should be watched. It's an aux structure used to obtain the final watchedList.

See also:
getWatchedList
Returns:
A Set containing the paths whitelist.

def ConfigFileManager.ConfigFileManager.getBlackList (   self  ) 

Gets the Paths blacklist.

See also:
getReBlacklist
Returns:
A Set containing the paths blacklisted

def ConfigFileManager.ConfigFileManager.getOptions (   self,
  section 
)

Obtains a list of the options in the section especified.

Returns in a list the options defined in the section especified.

Parameters:
section The section to retrieve the options from
Returns:
A list filled with the options names contained in the section.
Author:
Adrián

def ConfigFileManager.ConfigFileManager.getSections (   self  ) 

Obtains a list of the sections in the config file.

Returns in a list the sections available in the config file.

Returns:
A list filled with the sections names contained in the file.
Author:
Adrián

def ConfigFileManager.ConfigFileManager.hasOption (   self,
  section,
  option 
)

Determines if the section given has te option especified.

Search in the given section for the option passed as argument and return a boolean.

Parameters:
section The section that may contain de option.
option The searched option.
Returns:
True if the option exists whithin the given section and False Otherwise
Author:
Adrián

def ConfigFileManager.ConfigFileManager.hasSection (   self,
  section 
)

Determines if the section given exists in the config file.

Search in the config file for the section passed as argument and return a boolean.

Parameters:
section The section the caller wants to know if exists.
Returns:
True if the section exists and False Otherwise
Author:
Adrián

def ConfigFileManager.ConfigFileManager.getOptionValue (   self,
  section,
  option,
  type = None 
)

: Obtains the value of the given option in the given section.

If the caller needs the option in float, int or bool, it can call the function with that arg in the last place (type). Supported types are float, int and bool. Call the function with just three arguments to get the option without type changes.

Parameters:
section Name of the section which contains the option.
option Name of the option which value will be returned.
type The type of the option. It can be ommited.
Returns:
The value of the especified option with the type especified.
Author:
Adrián

def ConfigFileManager.ConfigFileManager.getFileOptionValue (   self,
  option,
  type = None 
)

Obtains the value of the given option if exists whithin any section.

Moves through all the sections in the Config File looking for the given option name. If it exists somewhere, its value is returned. Otherwise a NoOptionError exception is raised. If the name of the section is known, getOptionValue should be used instead of this method, because its much more efficient.

Parameters:
option Name of the option which value will be returned.
type The type of the option. It can be ommited.
Returns:
The value of the especified option with the type especified.
Exceptions:
NoOptionError The searched option doesn't exist.
See also:
getOptionValue
Author:
Adrián

def ConfigFileManager.ConfigFileManager.addConfigItem (   self,
  section,
  option,
  value 
)

Add new option to the config file.

This method tries to add a new option with its value to the section especified. If the section doesn't exist raise an exception. Otherwise it adds the option to the dynamic estructures and to the config file.

Parameters:
section The name of the section in which the option will be added
option The name of the option that will be added
value The value of the new option added
Exceptions:
NoSectionError The especified section does not exist
TypeError Value must be a string
Author:
Adrián

def ConfigFileManager.ConfigFileManager.removeConfigItem (   self,
  section,
  option 
)

Delete a config param from the config file.

Remove the option especified from the section given in the config file (dynamic and static).

Parameters:
section The section containing the option
option The option to be deleted
Exceptions:
NoSectionError The section especified doesn't exist.
Author:
Adrián

def ConfigFileManager.ConfigFileManager.removeSection (   self,
  section 
)

Delete a section from de config file.

Remove a section of the config file if it exists.

Parameters:
The section to remove
Returns:
True if the section really exists and went deleted properly. False otherwise.
Author:
Adrián

def ConfigFileManager.ConfigFileManager.addSection (   self,
  section 
)

Add new section to the config file.

This method add a new section to the dynamic structures and writes it to the config file..

Parameters:
section The name of the section that will be added
Exceptions:
DuplicateSectionError The section especified already exists!
Author:
Adrián


Member Data Documentation

tuple ConfigFileManager.ConfigFileManager.__watchedList = set() [static, private]

Files to be watched and backuped.

string ConfigFileManager.ConfigFileManager.__configFilePath = './prueba.cfg' [static, private]

Path to the config file.

tuple ConfigFileManager.ConfigFileManager.__config = ConfigParser.ConfigParser() [static, private]

ConfigParser instance, to manage the file.

tuple ConfigFileManager.ConfigFileManager.__reBlacklist = set() [static, private]

Patterns lists.

tuple ConfigFileManager.ConfigFileManager.__reWhitelist = set() [static, private]

tuple ConfigFileManager.ConfigFileManager.__blacklist = set() [static, private]

Paths lists.

tuple ConfigFileManager.ConfigFileManager.__whitelist = set() [static, private]

ConfigFileManager.ConfigFileManager.__whitelist [private]

ConfigFileManager.ConfigFileManager.__watchedList [private]


Generated on Wed Dec 19 19:25:04 2007 for HdLorean by  doxygen 1.5.4