def loadFromFile( self, fileName ): """ Load any handlers specified in the file. """ errCount = 0 if fileName.endswith( ".xml" ): _log.info( "load from file %s" % fileName ) try: xmlDom = parseXmlFile( fileName ) cfgDict = getDictFromXml( xmlDom ) thisCount = self.loadHandlers( cfgDict ) if thisCount > 0: errCount = errCount + thisCount _log.error( "Error configuring event routing using %s" % (fileName) ) except Exception, ex : _log.exception( "Error in %s" % (fileName) ) errCount = errCount + 1
def jsondata(self, logfile = None, propfile = None): """ """ result = "" # for debugging only # logPath = "/home/webbrick" # propPath = "/home/webbrick" # get the location of log files logPath = turbogears.config.get ('siteLogRoot', None, False, 'DEFAULT') # get the location of css files staticRoot = str(turbogears.config.get("static_filter.root", None, False, "global" )) staticCss = str(turbogears.config.get("static_filter.dir", None, False, "/static/css" )) if staticCss[0] != "/": propPath = staticRoot + staticCss else: propPath = staticCss if logfile and propfile: # does the log folder exist if logPath: # try to read the log file try: processeddata = {} xmldatastring = "<entrys>" + "".join(file(logPath + "/" + logfile).readlines()) + "</entrys>" xmldatablob = parseXmlString(xmldatastring) datadict = getDictFromXml(xmldatablob, typecast=True) for item in datadict["entrys"][0]: processeddata[item] = [] for entry in datadict["entrys"]: processeddata[item].append(entry[item][0]) result = str(processeddata) except: _log.error( "log file: %s does not exist on Path: %s" %(logfile, logPath) ) if propPath: # try to read the prop file try: xmlpropstring = "".join(file(propPath + "/" + propfile).readlines()) xmlpropblob = parseXmlString(xmlpropstring) propdict = getDictFromXml(xmlpropblob, typecast=True) propdict = propdict['graphprop'] #result = json.dumps(propdict) #result = str(propdict) except: _log.error( "log file: %s does not exist on Path: %s" %(propfile, propPath) ) if processeddata and propdict: try: propdict["datasets"] = [] for item in processeddata: if item != "time" and item != "date": propdict["datasets"].append({"text": item.replace(".", " "), "values":processeddata.get(item)}) elif item == "time": propdict["x_axis"]["labels"]["times"] = processeddata.get(item) elif item == "date": propdict["x_axis"]["labels"]["dates"] = processeddata.get(item) except: _log.error( "Could not add data to chart" ) result = json.dumps(propdict) else: _log.error( "Not enough arguments passed to allow processing" ) return result