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() |
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.
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...)
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
start_dir | The root path where the search of patterns will start. |
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).
bpath | String to test if it has wpath as initial substr. | |
wpath | String to test if is initial substr of bpath |
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).
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 |
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.
def ConfigFileManager.ConfigFileManager.getWatchedFiles | ( | self | ) |
Gets the list of "must be watched" files.
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.
files | A List containing the files to add. |
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.
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.
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.
def ConfigFileManager.ConfigFileManager.getBlackList | ( | self | ) |
Gets the Paths blacklist.
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.
section | The section to retrieve the options from |
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.
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.
section | The section that may contain de option. | |
option | The searched option. |
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.
section | The section the caller wants to know if exists. |
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.
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. |
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.
option | Name of the option which value will be returned. | |
type | The type of the option. It can be ommited. |
NoOptionError | The searched option doesn't exist. |
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.
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 |
NoSectionError | The especified section does not exist | |
TypeError | Value must be a string |
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).
section | The section containing the option | |
option | The option to be deleted |
NoSectionError | The section especified doesn't exist. |
def ConfigFileManager.ConfigFileManager.removeSection | ( | self, | ||
section | ||||
) |
Delete a section from de config file.
Remove a section of the config file if it exists.
The | section to remove |
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..
section | The name of the section that will be added |
DuplicateSectionError | The section especified already exists! |
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] |