def OnInit (self): aFilename = None # no config file found so far if _cfg is None: _log.Log(gmLog.lData, "No config file found. Use command line option --conf-file=<file name>") # get file name via file select dialog aWildcard = "%s (*.conf)|*.conf|%s (*.*)|*.*" % (_("config files"), _("all files")) aDefDir = os.path.abspath(os.path.expanduser('~')) dlg = wxFileDialog( parent = NULL, message = _("Choose a config file"), defaultDir = aDefDir, defaultFile = "", wildcard = aWildcard, style = wxOPEN | wxFILE_MUST_EXIST ) if dlg.ShowModal() == wxID_OK: aFilename = dlg.GetPath() dlg.Destroy() _log.Log(gmLog.lData, 'selected [%s]' % aFilename) tmp = gmCfg.cCfgFile(aFile=aFilename) else: tmp = _cfg frame = wxFrame( parent=NULL, id = -1, title = _("configfile editor"), size = wxSize(800,600) ) pnl = gmConfigEditorPanel(frame,aCfg=tmp) pnl.Populate() frame.Show(1) return 1
def OnInit(self): aFilename = None # no config file found so far if _cfg is None: _log.Log( gmLog.lData, "No config file found. Use command line option --conf-file=<file name>" ) # get file name via file select dialog aWildcard = "%s (*.conf)|*.conf|%s (*.*)|*.*" % ( _("config files"), _("all files")) aDefDir = os.path.abspath(os.path.expanduser('~')) dlg = wxFileDialog(parent=NULL, message=_("Choose a config file"), defaultDir=aDefDir, defaultFile="", wildcard=aWildcard, style=wxOPEN | wxFILE_MUST_EXIST) if dlg.ShowModal() == wxID_OK: aFilename = dlg.GetPath() dlg.Destroy() _log.Log(gmLog.lData, 'selected [%s]' % aFilename) tmp = gmCfg.cCfgFile(aFile=aFilename) else: tmp = _cfg frame = wxFrame(parent=NULL, id=-1, title=_("configfile editor"), size=wxSize(800, 600)) pnl = gmConfigEditorPanel(frame, aCfg=tmp) pnl.Populate() frame.Show(1) return 1
def __getFormatInfo(self): """get info on how to format parameters returned by query groups""" # open configuration source try: cfgSource = gmCfg.cCfgFile(aFile=self.dbConfFile) # handle all exceptions including 'config file not found' except: exc = sys.exc_info() _log.LogException("Unhandled exception while opening config file [%s]" % self.dbConfFile, exc, fatal=1) return None cfgData = cfgSource.getCfg() groups = cfgSource.getGroups() # every info holds # -an format string (presented as an list) # -a heading # -a format type ('none','single' or 'list') # -a position in the product info (int >= 0) # -the query group name that supplies the variables that are to be # matched to the format string # format infos are identified by the item 'type=format' for entry_group in groups: entry_type = cfgSource.get(entry_group, "type") # groups not containing format strings are silently ignored if entry_type != "format": continue # group name qname = cfgSource.get(entry_group, "querygroup") if qname is None: _log.Log(gmLog.lWarn, "query definition invalid in entry_group %s." % entry_group) continue # group format type ftype = cfgSource.get(entry_group, "formattype") if ftype is None: _log.Log(gmLog.lWarn, "query definition invalid in entry_group %s." % entry_group) continue fposstring = cfgSource.get(entry_group, "position") # check that the position is an valid int number try: fpos = int(fposstring) except TypeError: fpos = -1 if fpos is None or fpos < 0: _log.Log(gmLog.lWarn, "query definition invalid in entry_group %s." % entry_group) continue if ftype != "heading": format = cfgSource.get(entry_group, "format") if format is None or not type(format) == types.ListType: _log.Log(gmLog.lWarn, "query definition invalid in entry_group %s." % entry_group) continue usedVars = cfgSource.get(entry_group, "usedvars") if usedVars is None: _log.Log(gmLog.lWarn, "query definition invalid in entry_group %s." % entry_group) continue if ftype != "noheading": heading = cfgSource.get(entry_group, "heading") if format is None or not type(format) == types.ListType: _log.Log(gmLog.lWarn, "query definition invalid in entry_group %s." % entry_group) continue # set the parameters read from config file self.__mGroupPos[fpos] = qname self.__mFormatType[fpos] = ftype if ftype != "heading": fstring = string.join(format, "") self.__mFormatString[fpos] = fstring usedVarsList = string.split(usedVars, ",") self.__mUsedVars[fpos] = usedVarsList if ftype != "noheading": fheading = string.join(heading, "") self.__mHeading[fpos] = fheading return 1
def __getFormatInfo(self): """get info on how to format parameters returned by query groups""" # open configuration source try: cfgSource = gmCfg.cCfgFile(aFile=self.dbConfFile) # handle all exceptions including 'config file not found' except: exc = sys.exc_info() _log.LogException( "Unhandled exception while opening config file [%s]" % self.dbConfFile, exc, fatal=1) return None cfgData = cfgSource.getCfg() groups = cfgSource.getGroups() # every info holds # -an format string (presented as an list) # -a heading # -a format type ('none','single' or 'list') # -a position in the product info (int >= 0) # -the query group name that supplies the variables that are to be # matched to the format string # format infos are identified by the item 'type=format' for entry_group in groups: entry_type = cfgSource.get(entry_group, "type") # groups not containing format strings are silently ignored if entry_type != 'format': continue # group name qname = cfgSource.get(entry_group, "querygroup") if qname is None: _log.Log( gmLog.lWarn, "query definition invalid in entry_group %s." % entry_group) continue # group format type ftype = cfgSource.get(entry_group, "formattype") if ftype is None: _log.Log( gmLog.lWarn, "query definition invalid in entry_group %s." % entry_group) continue fposstring = cfgSource.get(entry_group, "position") # check that the position is an valid int number try: fpos = int(fposstring) except TypeError: fpos = -1 if fpos is None or fpos < 0: _log.Log( gmLog.lWarn, "query definition invalid in entry_group %s." % entry_group) continue if ftype != 'heading': format = cfgSource.get(entry_group, "format") if format is None or not type(format) == types.ListType: _log.Log( gmLog.lWarn, "query definition invalid in entry_group %s." % entry_group) continue usedVars = cfgSource.get(entry_group, "usedvars") if usedVars is None: _log.Log( gmLog.lWarn, "query definition invalid in entry_group %s." % entry_group) continue if ftype != 'noheading': heading = cfgSource.get(entry_group, "heading") if format is None or not type(format) == types.ListType: _log.Log( gmLog.lWarn, "query definition invalid in entry_group %s." % entry_group) continue # set the parameters read from config file self.__mGroupPos[fpos] = qname self.__mFormatType[fpos] = ftype if ftype != 'heading': fstring = string.join(format, '') self.__mFormatString[fpos] = fstring usedVarsList = string.split(usedVars, ',') self.__mUsedVars[fpos] = usedVarsList if ftype != 'noheading': fheading = string.join(heading, '') self.__mHeading[fpos] = fheading return 1
def __getQueries(self): """get query strings and initialize query group objects""" # open configuration source try: cfgSource = gmCfg.cCfgFile(aFile = self.__mQueryCfgSource) # handle all exceptions including 'config file not found' except: exc = sys.exc_info() _log.LogException("Unhandled exception while opening config file [%s]" % self.__mQueryCfgSource, exc, fatal=1) return None cfgData = cfgSource.getCfg() groups = cfgSource.getGroups() # every group holds one query consisting of three items: variables, the # query itself and the mappings # queries are identified by the item 'type=query' for entry_group in groups: gtype = cfgSource.get(entry_group, "type") # groups not containing queries are silently ignored if gtype != 'query': continue qname = cfgSource.get(entry_group, "querygroup") if qname is None: _log.Log(gmLog.lWarn,"query definition invalid in entry_group %s." % entry_group) continue qvars = cfgSource.get(entry_group, "variables") if qvars is None: _log.Log(gmLog.lWarn,"query definition invalid in entry_group %s." % entry_group) continue # query is gonna be a list because of issues # with special characters in simple string items query = cfgSource.get(entry_group, "query") if query is None or not type(query) == types.ListType: _log.Log(gmLog.lWarn,"query definition invalid in entry_group %s." % entry_group) continue qstring = query[0] qmappings = cfgSource.get(entry_group, "mappings") if qmappings is None: _log.Log(gmLog.lWarn,"query definition invalid in entry_group %s." % entry_group) continue # add new query group to QueryGroups dictionary if not self.__mQueryGroups.has_key(qname): self.__mQueryGroups[qname] = QueryGroup() self.__mQueryGroups[qname].addEntry(entry_group) # set the parameters read from config file self.__mQueryGroups[qname].mVarNames[entry_group] = string.split(qvars, ',') self.__mQueryGroups[qname].mMappings[entry_group] = string.split(qmappings, ',') self.__mQueryGroups[qname].mQueryStrings[entry_group] = qstring # inititalize variables used for mapping for v in string.split(qmappings, ','): # print "var %s" % v if v != '': self.mVars[v] = None # initialize new QueryGroupHandler objects using configuration data for so in self.__mQueryGroups.keys(): self.__mQueryGroupHandlers[so] = QueryGroupHandler(self, so, self.__mQueryGroups[so]) return 1