def testGetConfig(self): data = GetHTTPData(TestWbAccess._wbAddress,"/WbCfg.xml") assert data, "No page data returned: "+TestWbAccess._wbAddress+"/WbCfg.xml" dom = parseXmlString(data) root = dom.documentElement assert root.nodeName == "WebbrickConfig", "Wrong root element tag: "+root.nodeName assert root.getAttribute("Ver") in TestWbConfig.WbVersions, "Wrong WebBrick version: "+root.getAttribute("Ver")
def GetHTTPXmlDom(adrs,uri): """ Return content of an HTTP resource as an XML DOM object. """ xmlstr = GetHTTPData(adrs, uri) # return parseXmlString(xmlstr) # alternative if xmlstr: try: return parseXmlString(xmlstr) except Exception, ex: # Warn("XML error %s : (%s,%s) %s " % (ex, adrs,uri, xmlstr) ,"WebBrickLibs.WbAccess.GetHTTPXmlDom")
def UpdateConfig(self, adrs, cnfxml, override): """ Update configuration of specified WebBrick from specified file. Returns None if the operation is completed successfully, otherwise returns a page to be displayed describing the reason for non-completion. 'adrs' is the IP address of the WebBrick top be updated. 'cnfxml' is the text of the WebBrick XML configuration file to be uploaded. 'override' is a dictionary of values that can be used to override values in the supplied DOM when generating the configuration commands; e.g. "password" - overrides password used with "LG" command "IP" - overrides IP addresss set with "IA" command """ #TODO: may need to add logic to allow rejection of commands/command forms # not supported by older WebBricks? try: wbcfg = WebBrickConfig() dom = parseXmlString(cnfxml) configcmds = wbcfg.makeConfigCommands(dom, override) # configcmds.append("RU") # Reboot WebBrick to work around RU command bug in some WebBrick firmware versions # TODO: # Consider: should the RU command be withdrawn? # How many buggy webbricks are in the wild? configcmds.append("RB") errs = "" for line in configcmds: if line[0] != '#': SendHTTPCmd(adrs,line) err = Wb6Status(adrs).getCmdStatus() msg = None if err == ERR_NotLoggedIn: msg = "Incorrect WebBrick password ("+line+")" err = 0 if err: errs += "WebBrick command error: "+str(err)+", ("+line+")\n" if msg: Warn(msg, "WbCfgManagerForm.UpdateConfig") raise WbAccessException(msg) except Exception, e: return self.wbConfigError( "Failed to update WebBrick at %s" % (adrs), escapeTextForHtml(str(e)))
def copy(configsetname, node, tgtconfigsetname, tgtnode): """ Copy specified configuration, updating the node number containmed in its body """ cnfxml = read(configsetname, node) if node == tgtnode: newxml = cnfxml else: cnfdom = parseXmlString(cnfxml) wbroot = cnfdom.documentElement wbsn = getNamedNode(wbroot, "SN") if not wbsn: return "Config file has no <SN> element (node number)" replaceChildrenText(wbsn, tgtnode) newxml = getElemPrettyXml(cnfdom) # newxml = cnfdom.toprettyxml(indent=" ",newl="\n") return write(tgtconfigsetname, tgtnode, newxml)
def status( self, medianame='name-required', status='item-required' ): """ Return status of a media server """ result = ClientProfiles.makeStandardResponse( cherrypy.request ) self.__log.debug( 'MediaAccess.status %s, %s ' % (medianame, status) ) result['stserr'] = None result['mediaName'] = medianame try : if ( status == 'vol' ): xmlStr = MediaSet.volume( self, medianame ) elif ( status == 'playlist' ): xmlStr = MediaSet.playlist( self, medianame ) elif ( status == 'playlists' ): xmlStr = MediaSet.playlists( self, medianame ) elif ( status == 'position' ): xmlStr = MediaSet.status( self, medianame ) else: xmlStr = MediaSet.status( self, medianame ) self.__log.debug( '%s:%s - xmlString %s' % (medianame, status, xmlStr) ) xml = parseXmlString( xmlStr ) if ( status == 'position' ): result['position'] = getNamedNodeText( xml, 'position' ) result['duration'] = getNamedNodeText( xml, 'duration' ) elif ( status == 'vol' ): result['vol'] = getNamedNodeText( xml, status ) elif ( status == 'playlist' ): result['playlist'] = getElemXml( getNamedElem( xml, status ) ) elif ( status == 'playlists' ): result['playlists'] = getElemXml( getNamedElem( xml, status ) ) elif ( status == 'track' ): result['track'] = getNamedNodeText( xml, status ) else: result[str(status)] = getNamedNodeText( xml, status ) except Exception, ex : self.__log.exception( 'Error %s, %s ' % (medianame, status) ) result['stserr'] = "unknown"
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