CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

betterConfigParser::BetterConfigParser Class Reference

List of all members.

Public Member Functions

def __init__
def checkInput
def exists
def getAlignments
def getCompares
def getGeneral
def getResultingSection
def getSep
def optionxform

Private Member Functions

def __updateDict

Private Attributes

 _sep

Detailed Description

Definition at line 43 of file betterConfigParser.py.


Constructor & Destructor Documentation

def betterConfigParser::BetterConfigParser::__init__ (   self)

Definition at line 44 of file betterConfigParser.py.

00045                       :
00046         ConfigParser.ConfigParser.__init__(self,dict_type=AdaptedDict)
00047         dummyDict = AdaptedDict()
00048         self._sep = dummyDict.getSep()
00049         del dummyDict


Member Function Documentation

def betterConfigParser::BetterConfigParser::__updateDict (   self,
  dictionary,
  section 
) [private]

Definition at line 66 of file betterConfigParser.py.

00067                                                  :
00068         result = dictionary
00069         try:
00070             for option in self.options( section ):
00071                 result[option] = self.get( section, option )
00072             if "local"+section.title() in self.sections():
00073                 for option in self.options( "local"+section.title() ):
00074                     result[option] = self.get( "local"+section.title(),
00075                                                    option )
00076         except ConfigParser.NoSectionError, section:
00077             msg = ("%s in configuration files. This section is mandatory."
00078                    %(str(section).replace(":", "", 1)))
00079             raise AllInOneError(msg)
00080         return result

def betterConfigParser::BetterConfigParser::checkInput (   self,
  section,
  knownSimpleOptions = [],
  knownKeywords = [],
  ignoreOptions = [] 
)
Method which checks, if the given options in `section` are in the
list of `knownSimpleOptions` or match an item of `knownKeywords`.
This is basically a check for typos and wrong parameters.

Arguments:
- `section`: Section of a configuration file
- `knownSimpleOptions`: List of allowed simple options in `section`.
- `knownKeywords`: List of allowed keywords in `section`.

Definition at line 148 of file betterConfigParser.py.

00150                                     :
00151         """
00152         Method which checks, if the given options in `section` are in the
00153         list of `knownSimpleOptions` or match an item of `knownKeywords`.
00154         This is basically a check for typos and wrong parameters.
00155         
00156         Arguments:
00157         - `section`: Section of a configuration file
00158         - `knownSimpleOptions`: List of allowed simple options in `section`.
00159         - `knownKeywords`: List of allowed keywords in `section`.
00160         """
00161 
00162         for option in self.options( section ):
00163             if option in knownSimpleOptions:
00164                 continue
00165             elif option.split()[0] in knownKeywords:
00166                 continue
00167             elif option in ignoreOptions:
00168                 print ("Ignoring option '%s' in section '[%s]'."
00169                        %(option, section))
00170             else:
00171                 msg = ("Invalid or unknown parameter '%s' in section '%s'!"
00172                        %(option, section))
00173                 raise AllInOneError(msg)
00174 
def betterConfigParser::BetterConfigParser::exists (   self,
  section,
  option 
)

Definition at line 56 of file betterConfigParser.py.

00057                                       :
00058         try:
00059             items = self.items(section) 
00060         except ConfigParser.NoSectionError:
00061             return False
00062         for item in items:
00063             if item[0] == option:
00064                 return True
00065         return False
        
def betterConfigParser::BetterConfigParser::getAlignments (   self)

Definition at line 110 of file betterConfigParser.py.

00111                              :
00112         alignments = []
00113         for section in self.sections():
00114             if "alignment:" in section:
00115                 alignments.append( Alignment( section.split( "alignment:" )[1],
00116                                               self ) )
00117         return alignments

def betterConfigParser::BetterConfigParser::getCompares (   self)

Definition at line 118 of file betterConfigParser.py.

00119                            :
00120         compares = {}
00121         for section in self.sections():
00122             if "compare:" in section:
00123                 self.checkInput(section,
00124                                 knownSimpleOptions = ["levels", "dbOutput",
00125                                                       "jobmode"])
00126                 levels = self.get( section, "levels" )
00127                 dbOutput = self.get( section, "dbOutput" )
00128                 compares[section.split(":")[1]] = ( levels, dbOutput )
00129         return compares

def betterConfigParser::BetterConfigParser::getGeneral (   self)

Definition at line 130 of file betterConfigParser.py.

00131                           :
00132         defaults = {
00133             "jobmode":"interactive",
00134             "datadir":os.getcwd(),
00135             "logdir":os.getcwd(),
00136             "eosdir": "",
00137             "email":"true"
00138             }
00139         self.checkInput("general", knownSimpleOptions = defaults.keys())
00140         general = self.getResultingSection( "general", defaultDict = defaults )
00141         internal_section = "internals"
00142         if not self.has_section(internal_section):
00143             self.add_section(internal_section)
00144         if not self.has_option(internal_section, "workdir"):
00145             self.set(internal_section, "workdir", "/tmp/$USER")
00146         general["workdir"] = self.get(internal_section, "workdir")
00147         return general
    
def betterConfigParser::BetterConfigParser::getResultingSection (   self,
  section,
  defaultDict = {},
  demandPars = [] 
)

Definition at line 81 of file betterConfigParser.py.

00081                                                           {}, demandPars = [] ):
00082         result = copy.deepcopy(defaultDict)
00083         for option in demandPars:
00084             try:
00085                 result[option] = self.get( section, option )
00086             except ConfigParser.NoOptionError, globalSectionError:
00087                 globalSection = str( globalSectionError ).split( "'" )[-2]
00088                 splittedSectionName = section.split( ":" )
00089                 if len( splittedSectionName ) > 1:
00090                     localSection = ("local"+section.split( ":" )[0].title()+":"
00091                                     +section.split(":")[1])
00092                 else:
00093                     localSection = ("local"+section.split( ":" )[0].title())
00094                 if self.has_section( localSection ):
00095                     try:
00096                         result[option] = self.get( localSection, option )
00097                     except ConfigParser.NoOptionError, option:
00098                         msg = ("%s. This option is mandatory."
00099                                %(str(option).replace(":", "", 1).replace(
00100                                     "section",
00101                                     "section '"+globalSection+"' or", 1)))
00102                         raise AllInOneError(msg)
00103                 else:
00104                     msg = ("%s. This option is mandatory."
00105                            %(str(globalSectionError).replace(":", "", 1)))
00106                     raise AllInOneError(msg)
00107         result = self.__updateDict( result, section )
00108         return result
00109 
def betterConfigParser::BetterConfigParser::getSep (   self)

Definition at line 50 of file betterConfigParser.py.

00051                     :
00052         return self._sep

def betterConfigParser::BetterConfigParser::optionxform (   self,
  optionstr 
)

Definition at line 53 of file betterConfigParser.py.

00054                                     :
00055         return optionstr
    

Member Data Documentation

Definition at line 44 of file betterConfigParser.py.