"""__init__: the config file reader is initialized with 4 members : a filename and the 2 dictionnaries where the information will be stored plus the dictionnary of arguments to return """
"""read: this function read the information in the config file and store it in the self.dict. In the future the error message can be enhanced by providing the list of valid options for example et eventuellement sortir du programme"""
config_file=open(self.filename,'r')
# read the configuration file line by line from the start
config_line=config_file.readline()
whileconfig_line:
# cont will switch to false if an option is not valid, then the option is not stored
cont=True
# short and long argument names are initialized
arg_long=''
arg_short=''
# the argument name is extracted from the current line of the configuration file
argument=config_line.split('\t')[0]
# if it is the long name
ifargument[:2]=='--':
arg_long=argument.replace('--','')
# check if the option name is valid
# if not print an error message
ifarg_longnotinself.dict:
print'error : ',arg_long,' is not a valid option.'
# if yes the short option name is extracted from the conversion dictionnary
else:
arg_short=self.conversion_dict[arg_long]
# same if the option name is the short version
elifargument[:1]=='-':
arg_short=argument.replace('-','')
ifarg_shortnotinself.conversion_dict.values():
print'error : ',arg_short,' is not a valid option.'
else:
forkeyinself.conversion_dict:
ifself.conversion_dict[key]==arg_short:
arg_long=key
# if it is not valid, print an error message and set cont to False