def setGlobalLanguageParameters( language = "" ): """ @summary : Sets up all the needed global language tranlator so that it can be used everywhere in this program. @Note : The scope of the global _ function is restrained to this module only and does not cover the entire project. @param language : language to set. @return: None """ global _ global SUPPORTED_RX_DATATYPES global SUPPORTED_TX_DATATYPES if language == "": _ = LanguageTools.getTranslatorForModule( CURRENT_MODULE_ABS_PATH ) else : _ = LanguageTools.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, language ) SUPPORTED_RX_DATATYPES = { "bytecount":_("bytecount") , "filecount": _("filecount"), "errors":_("errors") } SUPPORTED_TX_DATATYPES = { "latency" :_("latency"), "filesOverMaxLatency":_("filesOverMaxLatency"), "bytecount":_("bytecount"), "filecount" :_("filecount"), "errors":_("errors") }
def setLanguage( language ): """ @summary : sets specified language as the language used for translations throughout the entire class. """ if language in LanguageTools.getSupportedLanguages() : global _ _ = LanguageTools.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, language )
def setLanguage(language): """ @summary : sets specified language as the language used for translations throughout the entire class. """ if language in LanguageTools.getSupportedLanguages(): global _ _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, language)
def __init__(self, languages=None): """ @param languages: list of languages for which to generate the doc web pages. """ global _ self.mainLanguage = LanguageTools.getMainApplicationLanguage() self.languages = languages or LanguageTools.getSupportedLanguages()
def __init__( self, languages = None ): """ @param languages: list of languages for which to generate the doc web pages. """ global _ self.mainLanguage = LanguageTools.getMainApplicationLanguage() self.languages = languages or LanguageTools.getSupportedLanguages()
def __init__(self, querierLanguage, queryParameters = None, replyParameters = None,\ graphicProducer = None ): """ @summary: GnuQueryBroker constructor. @param querierLanguage : Language spoken by the qerier at the time of the query. @param queryParameters: _QueryParameters instance wich contains the query parameters. @param replyParameters : @param graphicProducer : """ self.queryParameters = queryParameters self.graphicProducer = graphicProducer self.replyParameters = replyParameters self.querierLanguage = querierLanguage if self.querierLanguage not in LanguageTools.getSupportedLanguages(): raise Exception( "Error. Unsupported language detected in GnuQueryBroker. %s is not a supported language."%( self.querierLanguage ) ) else:#language is supposed to be supported global _ _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.querierLanguage )
def addOptions( parser ): """ @summary : This method is used to add all available options to the option parser. """ parser.add_option("-c", "--combine", action="store_true", dest = "combine", default=False, \ help=_("Combine data from all specified machines.") ) parser.add_option("-d", "--date", action="store", type="string", dest="date", default=StatsDateLib.getIsoFromEpoch( time.time() ),\ help=_("Decide current time. Usefull for testing.") ) parser.add_option("-i", "--individual", action="store_true", dest = "individual", default=False, \ help=_("Create individual graphics for all specified machines.") ) parser.add_option( "-l", "--logins", action="store", type="string", dest="logins", default="pds",\ help = _("Logins to be used to connect to machines.") ) parser.add_option( "-m", "--machines", action="store", type="string", dest="machines", default=LOCAL_MACHINE,\ help = _("Machines for wich you want to collect data.") ) parser.add_option("-o", "--outputLanguage", action="store", type="string", dest="outputLanguage",\ default=LanguageTools.getMainApplicationLanguage(), help = _("Language in which the graphics are outputted.") ) parser.add_option("-s", "--span", action="store",type ="int", dest = "timespan", default=24, \ help=_("timespan( in hours) of the graphic."))
def __init__(self, querierLanguage, queryParameters = None, replyParameters = None,\ graphicProducer = None ): """ @summary: GnuQueryBroker constructor. @param querierLanguage : Language spoken by the qerier at the time of the query. @param queryParameters: _QueryParameters instance wich contains the query parameters. @param replyParameters : @param graphicProducer : """ self.queryParameters = queryParameters self.graphicProducer = graphicProducer self.replyParameters = replyParameters self.querierLanguage = querierLanguage if self.querierLanguage not in LanguageTools.getSupportedLanguages(): raise Exception( "Error. Unsupported language detected in GnuQueryBroker. %s is not a supported language." % (self.querierLanguage)) else: #language is supposed to be supported global _ _ = self.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, self.querierLanguage)
def addOptions(parser): """ @summary : This method is used to add all available options to the option parser. """ parser.add_option("-c", "--combine", action="store_true", dest = "combine", default=False, \ help=_("Combine data from all specified machines.") ) parser.add_option("-d", "--date", action="store", type="string", dest="date", default=StatsDateLib.getIsoFromEpoch( time.time() ),\ help=_("Decide current time. Usefull for testing.") ) parser.add_option("-i", "--individual", action="store_true", dest = "individual", default=False, \ help=_("Create individual graphics for all specified machines.") ) parser.add_option( "-l", "--logins", action="store", type="string", dest="logins", default="pds",\ help = _("Logins to be used to connect to machines.") ) parser.add_option( "-m", "--machines", action="store", type="string", dest="machines", default=LOCAL_MACHINE,\ help = _("Machines for wich you want to collect data.") ) parser.add_option("-o", "--outputLanguage", action="store", type="string", dest="outputLanguage",\ default=LanguageTools.getMainApplicationLanguage(), help = _("Language in which the graphics are outputted.") ) parser.add_option("-s", "--span", action="store",type ="int", dest = "timespan", default=24, \ help=_("timespan( in hours) of the graphic."))
def updateWordsFromDB(wordType, word, language): """ @summary: Updates words within the db depending on the specified type ofdatabases @param wordType : Type of word : "products" or "groupName" @parameter language : Language that is currently used by the caller. @param word : Word to add to the database @return : None """ _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, language) statsPaths = StatsPaths() statsPaths.setPaths(language) if wordType == "products": updateWordsFromFile(statsPaths.STATSWEBWORDDATABASES + _('products'), word) elif wordType == "groupName": updateWordsFromFile(statsPaths.STATSWEBWORDDATABASES + _('groupNames'), word)
def main(): """ @summary: Based on the plotter specified in the received form, executes query using a broker that's specific to the said plotter. """ try: form = getForm() language = getLanguage(form) if language == "": # unspecified language. querier = getQuerierLocation(form) reply = "images=;error=" + "Error in query broker. Cannot proceed with query. No language was specified." #No language, do not translate. returnToQueriersLocationWithReply(querier, reply) elif language not in LanguageTools.getSupportedLanguages( ): # unsupported language querier = getQuerierLocation(form) reply = "images=;error=" + "Error in query broker. Cannot proceed with query. %s is not a supported language." % language #Unsupported language, do not translate. returnToQueriersLocationWithReply(querier, reply) else: #params seem ok setGlobalLanguageParameters(language) handlePlotRequest(form, language) except Exception, instance: #temp file helpfull for debugging! fileHandle = open('graphicsRequestBrokerDebuggingOutput', 'w') fileHandle.write(str(instance)) fileHandle.close()
def prepareQuery(self): """ @summary : Buildup the query to be executed. @SIDE_EFFECT : modifies self.query value. """ global _ if self.queryParameters.combine == 'true': totals = True mergerType = "regular" else: totals = False mergerType = "" fixedCurrent = False fixedPrevious = False if _("current") in str(self.queryParameters.fixedSpan).lower() : fixedCurrent = True elif _("previous") in str(self.queryParameters.fixedSpan).lower(): fixedPrevious = True else: fixedCurrent = False fixedPrevious = False hour = self.queryParameters.endTime.split(" ")[1] splitDate = self.queryParameters.endTime.split(" ")[0].split( '-' ) date = splitDate[2] + '-' + splitDate[1] + '-' + splitDate[0] + " " + hour if self.queryParameters.span == "": timespan = 0 else: timespan = int(self.queryParameters.span ) StatsDateLib.setLanguage( self.querierLanguage ) startTime, endTime = StatsDateLib.getStartEndInIsoFormat(date, timespan, self.queryParameters.specificSpan, fixedCurrent, fixedPrevious ) timespan = int( StatsDateLib.getSecondsSinceEpoch( endTime ) - StatsDateLib.getSecondsSinceEpoch( startTime ) ) / 3600 combinedMachineName = "" for machine in self.queryParameters.machines: combinedMachineName = combinedMachineName + machine machines = [ combinedMachineName ] self.graphicProducer = RRDGraphicProducer( self.queryParameters.fileTypes[0], self.queryParameters.statsTypes ,\ totals, self.queryParameters.specificSpan,\ self.queryParameters.sourLients, timespan,\ startTime, endTime, machines, False, mergerType, True, self.querierLanguage, self.querierLanguage ) StatsDateLib.setLanguage( LanguageTools.getMainApplicationLanguage() )
def searchForParameterErrors(self): """ @summary : Validates parameters. @return : Returns the first error found within the current query parameters. """ global _ error = "" try : if self.queryParameters.plotter != "gnuplot": error = _("Internal error. GnuQueryBroker was not called to plota gnuplot graphic.") raise for fileType in self.queryParameters.fileTypes : if fileType != "tx" and fileType != "rx": error = _("Error. FileType needs to be either rx or tx.") raise if self.queryParameters.sourLients == []: if self.queryParameters.groupName == "": error = _("Error. At least one sourlient name needs to be specified.") else: error = _("Error. When specifying a group name without any sourlients names, the group must be a pre-existing group.") if self.queryParameters.machines == []: error = _("Error. At least one machine name needs to be specified.") if self.queryParameters.combine != 'true' and self.queryParameters.combine != 'false': error = _("Error. Combine sourlients option needs to be either true or false." ) if self.queryParameters.statsTypes == []: error = _("Error. At Leat one statsType needs to be specified.") try: int(self.queryParameters.span) except: error = _("Error. Span(in hours) value needs to be numeric.") if self.queryParameters.language == "" : error = _("Error. No language was specified by the querier. Please speciffy a language. Ex : lang=fr") elif self.queryParameters.language not in LanguageTools.getSupportedLanguages() : error = _("Error. Unsupported language detected in GnuQueryBroker. %s is not a supported language.")%( self.queryParameters.language) except: pass return error
def giveOutPermissionsToFolders(currentlyUsedLanguages): """ @summary : opens up permissions to folders that might be required by the web user. @param currentlyUsedLanguages: Languages currently set to be displayed in the web interface """ for language in currentlyUsedLanguages: _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, language) paths = StatsPaths() paths.setPaths(language) pathsToOpenUp = [] pathsToOpenUp.append(paths.STATSLOGGING) pathsToOpenUp.append(paths.STATSPICKLES) pathsToOpenUp.append(paths.STATSDB) pathsToOpenUp.append(paths.STATSCURRENTDB) pathsToOpenUp.append(paths.STATSCURRENTDB + _("bytecount")) pathsToOpenUp.append(paths.STATSCURRENTDB + _("errors")) pathsToOpenUp.append(paths.STATSCURRENTDB + _("filecount")) pathsToOpenUp.append(paths.STATSCURRENTDB + _("filesOverMaxLatency")) pathsToOpenUp.append(paths.STATSCURRENTDB + _("latency")) pathsToOpenUp.append(paths.STATSCURRENTDBUPDATES) pathsToOpenUp.append(paths.STATSCURRENTDBUPDATES + _("rx")) pathsToOpenUp.append(paths.STATSCURRENTDBUPDATES + _("tx")) pathsToOpenUp.append(paths.STATSCURRENTDBUPDATES + _("totals")) pathsToOpenUp.append(paths.STATSDBBACKUPS) pathsToOpenUp.append(paths.STATSDBBACKUPS + "*/" + _("rx")) pathsToOpenUp.append(paths.STATSDBBACKUPS + "*/" + _("tx")) pathsToOpenUp.append(paths.STATSDBBACKUPS + "*/" + _("totals")) pathsToOpenUp.append(paths.STATSGRAPHS) pathsToOpenUp.append(paths.STATSGRAPHS + _("others/")) pathsToOpenUp.append(paths.STATSGRAPHS + _("others/") + "gnuplot/") pathsToOpenUp.append(paths.STATSGRAPHS + _("others/") + "rrd/") pathsToOpenUp.append(paths.STATSWEBPAGESHTML + "/popUps/") for path in pathsToOpenUp: if not os.path.isdir(path): os.makedirs(path, 0777) commands.getstatusoutput("chmod 0777 %s" % path) commands.getstatusoutput("chmod 0777 %s/*" % path)
def buildCsvFileName(infos): """ @summary: Builds and returns the file name to use for the csv file. @param infos: _CvsInfos instance containing the required information to build up the file name. @return: Return the built up file name. """ global _ StatsDateLib.setLanguage(infos.outputLanguage) paths = StatsPaths() paths.setPaths(infos.outputLanguage) machinesStr = str(infos.machinesForLabels).replace('[', '').replace( ']', '').replace(',', '').replace("'", "").replace('"', '').replace(' ', '') currentYear, currentMonth, currentDay = StatsDateLib.getYearMonthDayInStrfTime( StatsDateLib.getSecondsSinceEpoch(infos.start)) currentWeek = time.strftime( "%W", time.gmtime(StatsDateLib.getSecondsSinceEpoch(infos.start))) fileName = paths.STATSCSVFILES if infos.span == "daily": fileName = fileName + "/" + _( "daily/") + infos.fileType + "/%s/%s/%s/%s.csv" % ( machinesStr, currentYear, currentMonth, currentDay) elif infos.span == "weekly": fileName = fileName + "/" + _( "weekly/") + infos.fileType + "/%s/%s/%s.csv" % ( machinesStr, currentYear, currentWeek) elif infos.span == "monthly": fileName = fileName + "/" + _( "monthly/") + infos.fileType + "/%s/%s/%s.csv" % ( machinesStr, currentYear, currentMonth) elif infos.span == "yearly": fileName = fileName + "/" + _( "yearly/") + infos.fileType + "/%s/%s.csv" % (machinesStr, currentYear) StatsDateLib.setLanguage(LanguageTools.getMainApplicationLanguage()) return fileName
def giveOutPermissionsToFolders( currentlyUsedLanguages ): """ @summary : opens up permissions to folders that might be required by the web user. @param currentlyUsedLanguages: Languages currently set to be displayed in the web interface """ for language in currentlyUsedLanguages: _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, language) paths = StatsPaths() paths.setPaths(language) pathsToOpenUp = [] pathsToOpenUp.append( paths.STATSLOGGING) pathsToOpenUp.append( paths.STATSPICKLES ) pathsToOpenUp.append( paths.STATSDB) pathsToOpenUp.append( paths.STATSCURRENTDB ) pathsToOpenUp.append( paths.STATSCURRENTDB + _("bytecount") ) pathsToOpenUp.append( paths.STATSCURRENTDB + _("errors") ) pathsToOpenUp.append( paths.STATSCURRENTDB + _("filecount") ) pathsToOpenUp.append( paths.STATSCURRENTDB + _("filesOverMaxLatency")) pathsToOpenUp.append( paths.STATSCURRENTDB + _("latency")) pathsToOpenUp.append( paths.STATSCURRENTDBUPDATES) pathsToOpenUp.append( paths.STATSCURRENTDBUPDATES + _("rx") ) pathsToOpenUp.append( paths.STATSCURRENTDBUPDATES + _("tx") ) pathsToOpenUp.append( paths.STATSCURRENTDBUPDATES + _("totals") ) pathsToOpenUp.append( paths.STATSDBBACKUPS ) pathsToOpenUp.append( paths.STATSDBBACKUPS + "*/" + _("rx") ) pathsToOpenUp.append( paths.STATSDBBACKUPS + "*/" + _("tx") ) pathsToOpenUp.append( paths.STATSDBBACKUPS + "*/" + _("totals") ) pathsToOpenUp.append( paths.STATSGRAPHS ) pathsToOpenUp.append( paths.STATSGRAPHS +_("others/")) pathsToOpenUp.append( paths.STATSGRAPHS +_("others/") + "gnuplot/") pathsToOpenUp.append( paths.STATSGRAPHS +_("others/") + "rrd/") pathsToOpenUp.append( paths.STATSWEBPAGESHTML + "/popUps/") for path in pathsToOpenUp: if not os.path.isdir(path): os.makedirs(path, 0777) commands.getstatusoutput( "chmod 0777 %s" %path ) commands.getstatusoutput( "chmod 0777 %s/*" %path )
def setPaths(self, language=None): global _ from pxStats.lib.LanguageTools import LanguageTools _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, language) """ Sets all the paths that can not be translated. """ self.setBasicPaths() """ Translatable paths. """ self.STATSDATA = self.STATSROOT + _('data/') self.STATSDOC = self.STATSROOT + _('doc/') self.STATSLOGGING = self.STATSROOT + _('logs/') self.STATSMAN = self.STATSROOT + _('man/') self.STATSTEMP = self.STATSROOT + _("temp/") #csvfiles self.STATSCSVFILES = self.STATSDATA + _("csvFiles/") #Databases related paths. self.STATSDB = self.STATSDATA + _('databases/') self.STATSCURRENTDB = self.STATSDB + _('currentDatabases/') self.STATSCURRENTDBUPDATES = self.STATSDB + _( 'currentDatabasesTimeOfUpdates/') self.STATSDBBACKUPS = self.STATSDB + _('databasesBackups/') self.STATSDBUPDATESBACKUPS = self.STATSDB + _( 'databasesTimeOfUpdatesBackups/') #Various paths under pxStats/data/ self.STATSFILEVERSIONS = self.STATSDATA + _('fileAcessVersions/') self.STATSLOGACCESS = self.STATSDATA + _('logFileAccess/') self.STATSMONITORING = self.STATSDATA + _('monitoring/') self.STATSPICKLES = self.STATSDATA + _('pickles/') self.STATSLOGS = self.STATSDATA + _('logFiles/') self.STATSWEBPAGES = self.STATSDATA + _('webPages/') self.STATSWEBPAGESHTML = self.STATSWEBPAGES + _('html/') self.STATSWEBPAGESWORDDBS = self.STATSWEBPAGES + _('wordDatabases/') self.STATSGRAPHS = self.STATSDATA + _('graphics/') self.STATSWEBGRAPHS = self.STATSGRAPHS + _('webGraphics/') self.STATSWEBWORDDATABASES = self.STATSWEBPAGES + _('wordDatabases/') self.STATSGRAPHSARCHIVES = self.STATSWEBGRAPHS + _('archives/') self.STATSCOLGRAPHS = self.STATSWEBGRAPHS + _('columbo/') self.STATSPICKLESTIMEOFUPDATES = self.STATSDATA + _( 'picklesTimeOfUpdates/') self.STATSPREVIOUSMACHINEPARAMS = self.STATSDATA + _( 'previousMachineParameters') self.STATSTEMPLOCKFILES = self.STATSTEMP + _("lockFiles/") self.STATSTEMPAUTUPDTLOGS = self.STATSTEMP + _("automaticUpdatesLogs/")
def generateTopWebPage(self): """ @summary : Generates the top web page based on the """ configParameters = StatsConfigParameters() configParameters.getAllParameters() machineParameters = MachineConfigParameters() machineParameters.getParametersFromMachineConfigurationFile() supportedLanguages = LanguageTools.getSupportedLanguages() self.__createTheWebPage( configParameters.sourceMachinesTags, supportedLanguages )
def buildTitle( self, clientIndex, statType, typeCount, pairs ): """ @summary : This method is used to build the title we'll print on the graphic. Title is built with the current time and the name of the client where we collected the data. Also contains the mean and absolute min and max found in the data used to build the graphic. """ _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.workingLanguage ) maximum = self.getMaxPairValue( pairs ) minimum = self.getMinPairValue( pairs ) if maximum != None : if statType == _("latency"): maximum = "%.2f" %maximum else: maximum = int(maximum) if minimum != None : if statType == _("latency"): minimum = "%.2f" %minimum else: minimum = int(minimum) if statType == _("latency"): _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.outputLanguage ) explanation = _("With values rounded for every minutes.") else: _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.outputLanguage ) explanation = _("With the total value of every minutes.") statType = LanguageTools.translateTerm(statType, self.workingLanguage, self.outputLanguage, CURRENT_MODULE_ABS_PATH) statType = statType[0].upper() + statType[1:] if self.groupName == "": entityName = self.clientNames[clientIndex] else: entityName = self.groupName _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.outputLanguage ) title = _("%s for %s for a span of %s hours ending at %s")\ %( statType, entityName, self.timespan, self.currentTime) + "\\n%s\\n\\n" %explanation +_("MAX: ") + str(maximum) + " " +\ _("MEAN: ") + "%3.2f"%(self.means[clientIndex][typeCount]) + " " + _("MIN: ") +str(minimum) return title
def setGlobalLanguageParameters(language=""): """ @summary : Sets up all the needed global language tranlator so that it can be used everywhere in this program. @Note : The scope of the global _ function is restrained to this module only and does not cover the entire project. @param language : language to set. @return: None """ global _ global SUPPORTED_RX_DATATYPES global SUPPORTED_TX_DATATYPES if language == "": _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH) else: _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, language) SUPPORTED_RX_DATATYPES = { "bytecount": _("bytecount"), "filecount": _("filecount"), "errors": _("errors") } SUPPORTED_TX_DATATYPES = { "latency": _("latency"), "filesOverMaxLatency": _("filesOverMaxLatency"), "bytecount": _("bytecount"), "filecount": _("filecount"), "errors": _("errors") }
def __init__(self, timeOfRequest, outputLanguage): """ @param timeOfRequest : Time at which the graphics are requested. @param outputLanguage : Language in which to output the graphics. """ self.timeOfRequest = timeOfRequest self.outputLanguage = outputLanguage if outputLanguage not in LanguageTools.getSupportedLanguages(): raise Exception("Usage of unsuported language detected in timeOfRequest constructor.")
def __init__( self, outputLanguage ): """ @param outputLanguage: Language that will be displayed on the web page. """ self.outputLanguage = outputLanguage if self.outputLanguage not in LanguageTools.getSupportedLanguages(): raise Exception( "Error. Unsupported language detected in TopWebPageGenerator. %s is not a supported language." %(self.outputLanguage) ) else: global _ #Global translator for this module. _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.outputLanguage )
def getTranslatorForModule(self, moduleName, language=None): """ @summary : Sets up all the needed global language tranlator so that it can be used everywhere in this program. @Note : The scope of the global _ function is restrained to this class and the one in. @return: None """ return LanguageTools.getTranslatorForModule(moduleName, language)
def setPaths( self, language = None ): global _ from pxStats.lib.LanguageTools import LanguageTools _ = LanguageTools.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, language ) """ Sets all the paths that can not be translated. """ self.setBasicPaths() """ Translatable paths. """ self.STATSDATA = self.STATSROOT + _('data/') self.STATSDOC = self.STATSROOT + _( 'doc/' ) self.STATSLOGGING = self.STATSROOT + _( 'logs/' ) self.STATSMAN = self.STATSROOT + _( 'man/' ) self.STATSTEMP = self.STATSROOT + _( "temp/" ) #csvfiles self.STATSCSVFILES = self.STATSDATA + _("csvFiles/") #Databases related paths. self.STATSDB = self.STATSDATA + _( 'databases/' ) self.STATSCURRENTDB = self.STATSDB + _( 'currentDatabases/' ) self.STATSCURRENTDBUPDATES = self.STATSDB + _( 'currentDatabasesTimeOfUpdates/' ) self.STATSDBBACKUPS = self.STATSDB + _( 'databasesBackups/' ) self.STATSDBUPDATESBACKUPS = self.STATSDB + _( 'databasesTimeOfUpdatesBackups/' ) #Various paths under pxStats/data/ self.STATSFILEVERSIONS = self.STATSDATA + _( 'fileAcessVersions/' ) self.STATSLOGACCESS = self.STATSDATA + _( 'logFileAccess/' ) self.STATSMONITORING = self.STATSDATA + _( 'monitoring/' ) self.STATSPICKLES = self.STATSDATA + _( 'pickles/' ) self.STATSLOGS = self.STATSDATA + _( 'logFiles/' ) self.STATSWEBPAGES = self.STATSDATA + _( 'webPages/' ) self.STATSWEBPAGESHTML = self.STATSWEBPAGES + _( 'html/' ) self.STATSWEBPAGESWORDDBS = self.STATSWEBPAGES + _( 'wordDatabases/' ) self.STATSGRAPHS = self.STATSDATA + _( 'graphics/' ) self.STATSWEBGRAPHS = self.STATSGRAPHS + _( 'webGraphics/' ) self.STATSWEBWORDDATABASES = self.STATSWEBPAGES + _( 'wordDatabases/' ) self.STATSGRAPHSARCHIVES = self.STATSWEBGRAPHS + _( 'archives/' ) self.STATSCOLGRAPHS = self.STATSWEBGRAPHS + _( 'columbo/' ) self.STATSPICKLESTIMEOFUPDATES = self.STATSDATA + _( 'picklesTimeOfUpdates/' ) self.STATSPREVIOUSMACHINEPARAMS = self.STATSDATA + _( 'previousMachineParameters' ) self.STATSTEMPLOCKFILES = self.STATSTEMP + _( "lockFiles/" ) self.STATSTEMPAUTUPDTLOGS = self.STATSTEMP + _( "automaticUpdatesLogs/" )
def generateTopWebPage(self): """ @summary : Generates the top web page based on the """ configParameters = StatsConfigParameters() configParameters.getAllParameters() machineParameters = MachineConfigParameters() machineParameters.getParametersFromMachineConfigurationFile() supportedLanguages = LanguageTools.getSupportedLanguages() self.__createTheWebPage(configParameters.sourceMachinesTags, supportedLanguages)
def getTranslatorForModule(self, moduleName, language = None ): """ @summary : Sets up all the needed global language tranlator so that it can be used everywhere in this program. @Note : The scope of the global _ function is restrained to this class and the one in. @return: None """ return LanguageTools.getTranslatorForModule( moduleName, language )
def main(): """ Generates the web page based on the received machines and file type parameters. """ error = '' form = getForm() #print form try: wordType = form['wordType'] if wordType != 'products' and wordType != 'groupName': error = "Error. Word type needs to be either products or groupName." except: wordType = "" try: language = form['lang'] if language not in LanguageTools.getSupportedLanguages(): raise except: language = LanguageTools.getMainApplicationLanguage() try: word = form['word'] word = word.replace(' ', '') except: error = "Error. Word needs to be specified." word = "" if word != "": updateWordsFromDB(wordType, word, language) returnReply(error)
def main(): """ Generates the web page based on the received machines and file type parameters. """ error = "" form = getForm() # print form try: wordType = form["wordType"] if wordType != "products" and wordType != "groupName": error = "Error. Word type needs to be either products or groupName." except: wordType = "" try: language = form["lang"] if language not in LanguageTools.getSupportedLanguages(): raise except: language = LanguageTools.getMainApplicationLanguage() try: word = form["word"] word = word.replace(" ", "") except: error = "Error. Word needs to be specified." word = "" if word != "": updateWordsFromDB(wordType, word, language) returnReply(error)
def __init__(self, timeOfRequest, outputLanguage): """ @param timeOfRequest : Time at which the graphics are requested. @param outputLanguage : Language in which to output the graphics. """ self.timeOfRequest = timeOfRequest self.outputLanguage = outputLanguage if outputLanguage not in LanguageTools.getSupportedLanguages(): raise Exception( "Usage of unsuported language detected in timeOfRequest constructor." )
def setGlobalLanguageParameters(language): """ @summary : Sets up all the needed global language variables so that they can be used everywhere in this program. @param language: language with whom this script was called. @return: None """ global _ _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, language)
def setGlobalLanguageParameters( language ): """ @summary : Sets up all the needed global language variables so that they can be used everywhere in this program. @param language: language with whom this script was called. @return: None """ global _ _ = LanguageTools.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, language)
def setGlobalLanguageParameters(): """ @summary : Sets up all the needed global language tranlator so that it can be used everywhere in this program. @Note : The scope of the global _ function is restrained to this module only and does not cover the entire project. @return: None """ global _ _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH)
def setGlobalLanguageParameters(): """ @summary : Sets up all the needed global language tranlator so that it can be used everywhere in this program. @Note : The scope of the global _ function is restrained to this module only and does not cover the entire project. @return: None """ global _ _ = LanguageTools.getTranslatorForModule( CURRENT_MODULE_ABS_PATH )
def __init__(self, outputLanguage): """ @param outputLanguage: Language that will be displayed on the web page. """ self.outputLanguage = outputLanguage if self.outputLanguage not in LanguageTools.getSupportedLanguages(): raise Exception( "Error. Unsupported language detected in TopWebPageGenerator. %s is not a supported language." % (self.outputLanguage)) else: global _ #Global translator for this module. _ = self.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, self.outputLanguage)
def buildCsvFileName( infos ): """ @summary: Builds and returns the file name to use for the csv file. @param infos: _CvsInfos instance containing the required information to build up the file name. @return: Return the built up file name. """ global _ StatsDateLib.setLanguage(infos.outputLanguage) paths = StatsPaths() paths.setPaths( infos.outputLanguage ) machinesStr = str(infos.machinesForLabels).replace('[','').replace( ']','' ).replace(',', '').replace("'","").replace( '"','').replace( ' ','' ) currentYear, currentMonth, currentDay = StatsDateLib.getYearMonthDayInStrfTime( StatsDateLib.getSecondsSinceEpoch (infos.start) ) currentWeek = time.strftime( "%W", time.gmtime( StatsDateLib.getSecondsSinceEpoch (infos.start) ) ) fileName = paths.STATSCSVFILES if infos.span == "daily": fileName = fileName + "/" + _("daily/") + infos.fileType + "/%s/%s/%s/%s.csv" %( machinesStr, currentYear, currentMonth, currentDay ) elif infos.span == "weekly": fileName = fileName + "/" + _("weekly/") + infos.fileType + "/%s/%s/%s.csv" %( machinesStr, currentYear, currentWeek ) elif infos.span == "monthly": fileName = fileName + "/" + _("monthly/") + infos.fileType + "/%s/%s/%s.csv" %( machinesStr, currentYear, currentMonth ) elif infos.span == "yearly": fileName = fileName + "/" + _("yearly/") + infos.fileType + "/%s/%s.csv" %( machinesStr, currentYear ) StatsDateLib.setLanguage( LanguageTools.getMainApplicationLanguage() ) return fileName
def getImagesLangFromForm(): """ @summary : Parses form with whom this program was called. @return: Returns the images and language found within the form. """ lang = LanguageTools.getMainApplicationLanguage() images = [] newForm = {} form = cgi.FieldStorage() for key in form.keys(): value = form.getvalue(key, "") if isinstance(value, list): newvalue = ",".join(value) else: newvalue = value newForm[key.replace("?","")]= newvalue try: images = newForm["images"] images = images.split(';') except: pass try: lang = newForm["lang"] except: pass return images, lang
def __getFileNameFromExecutionOutput( self, output ): """ @summary : Parses an execution output coming from the csvDataConversion.py file and searchs for the filename that was generated. """ global _ _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, self.outputLanguage ) fileName = "" lines = str( output ).splitlines() for line in lines: if _( "generated filename : " ) in str(line).lower(): fileName = line.split( _( "generated filename : " ) )[1].replace(' ','') break return fileName
def createSubFolders( path, currentlyUsedLanguages ): """ @summary : Creates all the required sub folders. @param path : Paths in which we are installing the web interface. @param currentlyUsedLanguages: Languages currently set to be displayed in the web interface. """ global _ subFolders = [ "scripts" ] for language in currentlyUsedLanguages : _ = LanguageTools.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, language ) subFolders.append( _("wordDatabases") ) for subFolder in subFolders : if not os.path.isdir( path + '/'+ subFolder ): os.makedirs( path + '/' + subFolder )
def createSubFolders(path, currentlyUsedLanguages): """ @summary : Creates all the required sub folders. @param path : Paths in which we are installing the web interface. @param currentlyUsedLanguages: Languages currently set to be displayed in the web interface. """ global _ subFolders = ["scripts"] for language in currentlyUsedLanguages: _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, language) subFolders.append(_("wordDatabases")) for subFolder in subFolders: if not os.path.isdir(path + '/' + subFolder): os.makedirs(path + '/' + subFolder)
def addOptions( parser ): """ @summary : This method is used to add all available options to the option parser. """ parser.add_option("-c", "--clients", action="store", type="string", dest="clients", default="", help=_("Clients' names") ) parser.add_option( "--copy", action="store_true", dest = "copy", default=False, help=_("Create a copy file for the generated image.") ) parser.add_option( "--combineClients", action="store_true", dest = "combineClients", default=False, \ help=_("Combine the data of all client into a single graphics for each graphic type.") ) parser.add_option("-d", "--date", action="store", type="string", dest="currentTime", \ default=StatsDateLib.getIsoFromEpoch( time.time() ), help=_("Decide current time. Usefull for testing.") ) parser.add_option("-f", "--fileType", action="store", type="string", dest="fileType", default='tx',\ help=_("Type of log files wanted.") ) parser.add_option( "-g", "--groupName", action="store", type="string", dest="groupName", default="", help=_("Specify a name for the combined graphics of numerous client/sources. Note : requires the --combinedClients options to work." ) ) parser.add_option( "-m", "--machines", action="store", type="string", dest="machines", default=LOCAL_MACHINE,\ help = _("Machines for wich you want to collect data.") ) parser.add_option("-n", "--collectUpToNow", action="store_true", dest = "collectUpToNow", default=False, \ help=_("Collect data up to current second.") ) parser.add_option("-o", "--outputLanguage", action="store", type="string", dest="outputLanguage",\ default=LanguageTools.getMainApplicationLanguage(), help = _("Language in which the graphics are outputted.") ) parser.add_option("-p", "--products", action="store", type = "string", dest = "productTypes", default=_("All"), \ help=_("Specific product types to look for in the data collected.") ) parser.add_option("-s", "--span", action="store",type ="int", dest = "timespan", default=12, help=_("timespan( in hours) of the graphic.") ) parser.add_option("-t", "--types", type="string", dest="types", default=_("All"),help=_("Types of data to look for.") )
def getFormatedProductTypesForLabel(self): """ @summary : Returns the product type in a format that can be displayed on of of the graphcis labels. @note : If Productype is * or _("All") it will be translated. @return : the product type in a format that can be displayed on of of the graphcis labels. """ _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.workingLanguage ) formattedProductType = "" if self.productTypes[0] == _("All") or self.productTypes[0] == "*": formattedProductType = LanguageTools.translateTerm(_("All"), self.workingLanguage, self.outputLanguage, CURRENT_MODULE_ABS_PATH) else: formattedProductType = self.productTypes[0] formattedProductType = "%-25s" %( (str)( formattedProductType ) ).replace('[','' ).replace( ']', '' ).replace("'","") return formattedProductType
def main(): """ @summary: Based on the plotter specified in the received form, executes query using a broker that's specific to the said plotter. """ try: form = getForm() language = getLanguage( form ) if language == "" : # unspecified language. querier = getQuerierLocation( form ) reply = "images=;error=" + "Error in query broker. Cannot proceed with query. No language was specified." #No language, do not translate. returnToQueriersLocationWithReply( querier, reply ) elif language not in LanguageTools.getSupportedLanguages(): # unsupported language querier = getQuerierLocation( form ) reply = "images=;error=" + "Error in query broker. Cannot proceed with query. %s is not a supported language." %language #Unsupported language, do not translate. returnToQueriersLocationWithReply( querier, reply ) else: #params seem ok setGlobalLanguageParameters( language ) handlePlotRequest( form, language ) except Exception, instance : #temp file helpfull for debugging! fileHandle= open('graphicsRequestBrokerDebuggingOutput','w') fileHandle.write( str(instance) ) fileHandle.close()
def __getFileNameFromExecutionOutput(self, output): """ @summary : Parses an execution output coming from the csvDataConversion.py file and searchs for the filename that was generated. """ global _ _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, self.outputLanguage) fileName = "" lines = str(output).splitlines() for line in lines: if _("generated filename : ") in str(line).lower(): fileName = line.split(_("generated filename : "))[1].replace( ' ', '') break return fileName
def updateWordsFromDB(wordType, word, language): """ @summary: Updates words within the db depending on the specified type ofdatabases @param wordType : Type of word : "products" or "groupName" @parameter language : Language that is currently used by the caller. @param word : Word to add to the database @return : None """ _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, language) statsPaths = StatsPaths() statsPaths.setPaths(language) if wordType == "products": updateWordsFromFile(statsPaths.STATSWEBWORDDATABASES + _("products"), word) elif wordType == "groupName": updateWordsFromFile(statsPaths.STATSWEBWORDDATABASES + _("groupNames"), word)
def getDataFromDatabases( sourlients, dataTypes, infos ): """ @summary: Gathers up all the requried data from allthe concerned databases @param sourlients: List of sources clients for wich we need to gather up data. @param machines: Machines on which the clients reside. @param dataTypes: Datatypes for which we need to collect data. @return : Return the data dictionary filled with all the collected data. """ data = {} for sourlient in sourlients.keys() : data[sourlient] = {} sourlientsMachines = sourlients[sourlient] for machine in infos.machinesToSearch : if infos.machinesAreClusters == True: machineConfig = MachineConfigParameters() machineConfig.getParametersFromMachineConfigurationFile() machines = machineConfig.getMachinesAssociatedWith( machine ) oldMachine = machine machine = str(machines).replace('[','').replace(']', '').replace(',','').replace( "'",'' ).replace('"','' ).replace(" ",'')\ .replace('[','').replace(']', '').replace(',','').replace( "'",'' ).replace('"','' ).replace(" ",'') if machine == '': #print "trouvaille !!!" machine = oldMachine if machine in sourlientsMachines: data[sourlient][machine] = {} for dataType in dataTypes : if infos.outputLanguage != 'en' : translatedDataType = LanguageTools.translateDataType( dataType, "en", infos.outputLanguage ) else : translatedDataType = dataType databaseName = RrdUtilities.buildRRDFileName( dataType = translatedDataType, clients= [sourlient], machines = [machine], fileType = infos.fileType ) if not os.path.isfile( databaseName ): if infos.includegroups == True: databaseName = RrdUtilities.buildRRDFileName(dataType = translatedDataType, groupName = sourlient, machines = [machine], fileType = infos.fileType, usage = "group" ) lastUpdate = RrdUtilities.getDatabaseTimeOfUpdate( databaseName, infos.fileType ) fetchedInterval = getInterval( int(StatsDateLib.getSecondsSinceEpoch(infos.start)), lastUpdate, dataType, goal = "fetchData" ) desiredInterval = getInterval( int(StatsDateLib.getSecondsSinceEpoch(infos.start)), lastUpdate, dataType, goal = "plotGraphic" ) interval = desiredInterval minimum, maximum, mean, total = getGraphicsMinMaxMeanTotal( databaseName, int(StatsDateLib.getSecondsSinceEpoch(infos.start)),\ int(StatsDateLib.getSecondsSinceEpoch(infos.end)), infos.span,\ fetchedInterval,desiredInterval, type = "average" ) data[sourlient][machine][dataType] = {} data[sourlient][machine][dataType]["min"] = minimum data[sourlient][machine][dataType]["max"] = maximum data[sourlient][machine][dataType]["mean"] = mean data[sourlient][machine][dataType]["total"] = total return data
# ############################################################################################## """ import commands, os, sys sys.path.append(1, os.path.dirname(os.path.abspath(__file__)) + "/../../../") from optparse import OptionParser from pxStats.lib.StatsPaths import StatsPaths from pxStats.lib.LanguageTools import LanguageTools """ Small function that adds pxlib to the environment path. """ STATSPATHS = StatsPaths() STATSPATHS.setPaths(LanguageTools.getMainApplicationLanguage()) sys.path.append(STATSPATHS.PXLIB) """ Imports Logger requires pxlib """ from Logger import * LOCAL_MACHINE = os.uname()[1] CURRENT_MODULE_ABS_PATH = os.path.abspath(__file__).replace(".pyc", ".py") def getOptionsFromParser(parser): """ This method parses the argv received when the program was called
STATSPATHS = StatsPaths() STATSPATHS.setPaths() sys.path.append(STATSPATHS.PXLIB) """ Imports which require pxlib """ import PXManager import PXPaths from PXManager import * #Constants LOCAL_MACHINE = os.uname()[1] CURRENT_MODULE_ABS_PATH = os.path.abspath(__file__).replace(".pyc", ".py") global _ _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH) class GeneralStatsLibraryMethods: def createLockFile(processName): """ @summary : Creates a lock file associated with the specified processName. @param processName : Name of the process for which to create the lock file. @return : None """ fileName = STATSPATHS.STATSTEMPLOCKFILES + str(processName) + _(
def buildRRDFileName( dataType = 'errors', clients = None , machines = None,\ groupName = "", fileType = "", usage = "regular" ): """ @summary : Returns the name of the round robin database bases on the parameters. @param dataType: byteocunt, errors, filecount, filesOverMaxLatency and latency. @param clients: list of clients/sources names. If only one is wanted, include it in a list. @param machines: list of machines associated with client/sources names. If only one is wanted, include it in a list. @param fileType : Useless for regular and group databases. Obligatory for totalForMachine databases. @param groupName: optional. Use only if the list of client/sources has a KNOWN group name. @param usage: regular, group or totalForMachine. @return: Returns the name of the round robin database bases on the parameters. """ _ = LanguageTools.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, LanguageTools.getMainApplicationLanguage()) clients = clients or ['client1', 'client1'] machines = machines or ['machine1', 'machine2'] fileName = "" combinedMachineName = "" for machine in machines: combinedMachineName = combinedMachineName + machine combinedClientsName = "" for client in clients: combinedClientsName = combinedClientsName + client if len(clients) == 1: if usage == "regular": fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" % ( dataType, combinedClientsName, combinedMachineName) elif usage == "group": fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" % ( dataType, groupName, combinedMachineName) elif usage == "totalForMachine": fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" % ( dataType, fileType, combinedMachineName) else: if usage == "regular": fileName = STATSPATHS.STATSCURRENTDB + _( "%s/combined/%s_%s") % (dataType, combinedClientsName, combinedMachineName) elif usage == "group": #fileName = STATSPATHS.STATSCURRENTDB + _("%s/combined/%s_%s") %( dataType, groupName, combinedMachineName ) try: existingFiles = os.listdir(STATSPATHS.STATSCURRENTDB + "%s/combined/" % (dataType)) for file in existingFiles: if fnmatch.fnmatch(file, groupName + "*"): fileName = file break except: pass if fileName == "": #no preexisitng file exist for this group fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" % ( dataType, groupName, combinedMachineName) else: #else fileName = STATSPATHS.STATSCURRENTDB + "%s/combined/" % ( dataType) + fileName elif usage == "totalForMachine": fileName = STATSPATHS.STATSCURRENTDB + _( "%s/combined/%s_%s") % (dataType, fileType, combinedMachineName) #print "before ", fileName #fileName = fileName.replace("année","year").replace("nbreDeBytes","bytecount").replace("nbreDeFichiers","filecount").replace("erreurs","errors").replace("latence","latency").replace("fichiersAvecLatenceInnacceptable","filesOverMaxLatency").replace("heures","hours").replace("mois","month").replace("jour","day").replace("","") #print "after ", fileName return fileName
def getOptionsFromParser( parser ): """ @summary : This method parses the argv received when the program was called. It takes the params wich have been passed by the user and sets them in the corresponding fields of the infos variable. @note : If errors are encountered in parameters used, it will immediatly terminate the application. """ currentTime = [] ( options, args )= parser.parse_args() collectUpToNow = options.collectUpToNow timespan = options.timespan machines = options.machines.replace( ' ','').split(',') clientNames = options.clients.replace( ' ','' ).split(',') types = options.types.replace( ' ', '').split(',') currentTime = options.currentTime.replace('"','').replace("'",'') fileType = options.fileType.replace("'",'') collectUpToNow = options.collectUpToNow copy = options.copy combineClients = options.combineClients productTypes = options.productTypes.replace( ' ', '' ).split( ',' ) groupName = options.groupName.replace( ' ','' ) outputLanguage = options.outputLanguage try: # Makes sure date is of valid format. # Makes sure only one space is kept between date and hour. t = time.strptime( currentTime, '%Y-%m-%d %H:%M:%S' ) split = currentTime.split() currentTime = "%s %s" %( split[0], split[1] ) except: print _("Error. The date format must be YYYY-MM-DD HH:MM:SS" ) print _("Use -h for help.") print _("Program terminated.") sys.exit() try: if int( timespan ) < 1 : raise except: print _("Error. The timespan value needs to be an integer one above 0." ) print _("Use -h for help.") print _("Program terminated.") sys.exit() if fileType != "tx" and fileType != "rx": print _("Error. File type must be either tx or rx.") print _('Multiple types are not accepted.' ) print _("Use -h for additional help.") print _("Program terminated.") sys.exit() if groupName != "" and combineClients == False : print _("Error. -g|--groupeName option requires the --combineClients options.") print _('Group names are otherwise irrelevant.' ) print _("Use -h for additional help.") print _("Program terminated.") sys.exit() try : if fileType == "tx": validTypes = [ _("errors"), _("filecount"), _("bytecount"), _("latency") ] if types[0] == _("All"): types = validTypes else : for t in types : if t not in validTypes: raise Exception("") else: validTypes = [ _("errors"), _("filecount"), _("bytecount") ] if types[0] == _("All"): types = validTypes else : for t in types : if t not in validTypes: raise Exception("") except: print _("Error. With %s fileType, possible data types values are : %s.") %( fileType,validTypes ) print _('For multiple types use this syntax : -t "type1,type2"') print _("Use -h for additional help.") print _("Program terminated.") sys.exit() if outputLanguage not in LanguageTools.getSupportedLanguages(): print _("Error. %s is not one of the supproted languages") print _("Use one of the following languages : %s" % str( LanguageTools.getSupportedLanguages() ).replace("[","").replace("]","") ) print _("Use -h for additional help.") print _("Program terminated.") clientNames = GeneralStatsLibraryMethods.filterClientsNamesUsingWilcardFilters( currentTime, timespan, clientNames, machines, [fileType]) directory = GeneralStatsLibraryMethods.getPathToLogFiles( LOCAL_MACHINE, machines[0] ) infos = _GraphicsInfos( collectUpToNow = collectUpToNow, currentTime = currentTime, clientNames = clientNames,\ groupName = groupName, directory = directory , types = types, fileType = fileType, \ timespan = timespan, productTypes = productTypes, machines = machines, copy = copy, \ combineClients = combineClients, outputLanguage = outputLanguage ) if collectUpToNow == False: infos.endTime = StatsDateLib.getIsoWithRoundedHours( infos.currentTime ) return infos
class PickleMerging: global _ _ = LanguageTools.getTranslatorForModule(CURRENT_MODULE_ABS_PATH) def entryListIsValid(entryList): """ @summary : Returns whether or not an entry list of pickles contains a list of pickles that can be merged. @return : True or False """ isValid = True if entryList != []: i = 0 startTime = entryList[0].startTime totalWidth = entryList[0].totalWidth interval = entryList[0].interval statsTypes = entryList[0].statsTypes while i < len(entryList) and isValid == True: if startTime != entryList[ i].startTime or totalWidth != entryList[ i].totalWidth or interval != entryList[i].interval: isValid = False else: for type in statsTypes: if type not in entryList[i].statsTypes: isValid = False i = i + 1 else: isValid = False return isValid entryListIsValid = staticmethod(entryListIsValid) def fillWithEmptyEntries(nbEmptyEntries, entries): """ @summary : Append certain number of empty entries to the entry list. """ for i in xrange(nbEmptyEntries): entries[i] = _FileStatsEntry() return entries fillWithEmptyEntries = staticmethod(fillWithEmptyEntries) def mergePicklesFromDifferentHours( logger = None , startTime = "2006-07-31 13:00:00",\ endTime = "2006-07-31 19:00:00", client = "satnet",\ machine = "pdsPM", fileType = "tx" ): """ @summary : This method merges entire hourly pickles files together. @None : This does not support merging part of the data of pickles. """ if logger != None: logger.debug(_("Call to mergeHourlyPickles received.")) logging = True else: logging = False pickles = [] entries = {} width = StatsDateLib.getSecondsSinceEpoch( endTime) - StatsDateLib.getSecondsSinceEpoch(startTime) startTime = StatsDateLib.getIsoWithRoundedHours(startTime) seperators = [startTime] seperators.extend( StatsDateLib.getSeparatorsWithStartTime(startTime=startTime, width=width, interval=60 * StatsDateLib.MINUTE)[:-1]) for seperator in seperators: pickles.append( StatsPickler.buildThisHoursFileName(client=client, offset=0, currentTime=seperator, machine=machine, fileType=fileType)) startingNumberOfEntries = 0 #print "prior to loading and merging pickles : %s " %( StatsDateLib.getIsoFromEpoch( time.time() ) ) for pickle in pickles: if os.path.isfile(pickle): tempCollection = CpickleWrapper.load(pickle) if tempCollection != None: for i in xrange(len(tempCollection.fileEntries)): entries[startingNumberOfEntries + i] = tempCollection.fileEntries[i] startingNumberOfEntries = startingNumberOfEntries + len( tempCollection.fileEntries) else: sys.exit() else: emptyEntries = PickleMerging.fillWithEmptyEntries( nbEmptyEntries=60, entries={}) for i in xrange(60): entries[i + startingNumberOfEntries] = emptyEntries[i] startingNumberOfEntries = startingNumberOfEntries + 60 #print "after the loading and merging og pickles : %s " %( StatsDateLib.getIsoFromEpoch( time.time() ) ) statsCollection = FileStatsCollector(startTime=startTime, endTime=endTime, interval=StatsDateLib.MINUTE, totalWidth=width, fileEntries=entries, fileType=fileType, logger=logger, logging=logging) return statsCollection mergePicklesFromDifferentHours = staticmethod( mergePicklesFromDifferentHours) def mergePicklesFromSameHour( logger = None , pickleNames = None, mergedPickleName = "",\ clientName = "" , combinedMachineName = "", currentTime = "",\ fileType = "tx" ): """ @summary: This methods receives a list of filenames referring to pickled FileStatsEntries. After the merger pickles get saved since they might be reused somewhere else. @precondition: Pickle should be of the same timespan and bucket width. If not no merging will occur. """ if logger != None: logger.debug(_("Call to mergePickles received.")) logging = True else: logging = False entryList = [] for pickle in pickleNames: #for every pickle we eneed to merge if os.path.isfile(pickle): entryList.append(CpickleWrapper.load(pickle)) else: #Use empty entry if there is no existing pickle of that name endTime = StatsDateLib.getIsoFromEpoch( StatsDateLib.getSecondsSinceEpoch(currentTime) + StatsDateLib.HOUR) entryList.append( FileStatsCollector(startTime=currentTime, endTime=endTime, logger=logger, logging=logging)) if logger != None: logger.warning( _("Pickle named %s did not exist. Empty entry was used instead." ) % pickle) #start off with a carbon copy of first pickle in list. newFSC = FileStatsCollector( files = entryList[0].files , statsTypes = entryList[0].statsTypes, startTime = entryList[0].startTime,\ endTime = entryList[0].endTime, interval=entryList[0].interval, totalWidth = entryList[0].totalWidth,\ firstFilledEntry = entryList[0].firstFilledEntry, lastFilledEntry = entryList[0].lastFilledEntry,\ maxLatency = entryList[0].maxLatency, fileEntries = entryList[0].fileEntries,logger = logger,\ logging = logging ) if PickleMerging.entryListIsValid(entryList) == True: for i in range(1, len(entryList)): #add other entries for file in entryList[i].files: if file not in newFSC.files: newFSC.files.append(file) for j in range(len(newFSC.fileEntries)): # add all entries newFSC.fileEntries[j].values.productTypes.extend( entryList[i].fileEntries[j].values.productTypes) newFSC.fileEntries[j].files.extend( entryList[i].fileEntries[j].files) newFSC.fileEntries[j].times.extend( entryList[i].fileEntries[j].times) newFSC.fileEntries[j].nbFiles = newFSC.fileEntries[ j].nbFiles + (newFSC.fileEntries[j].nbFiles) for type in newFSC.statsTypes: newFSC.fileEntries[j].values.dictionary[type].extend( entryList[i].fileEntries[j].values.dictionary[type] ) newFSC.fileEntries[j].values.rows = newFSC.fileEntries[ j].values.rows + entryList[i].fileEntries[j].values.rows newFSC = newFSC.setMinMaxMeanMedians( startingBucket=0, finishingBucket=newFSC.nbEntries - 1) else: #Did not merge pickles named. Pickle list was not valid." if logger != None: logger.warning( _("Did not merge pickles named : %s. Pickle list was not valid." ) % pickleNames) logger.warning( _("Filled with empty entries instead.") % pickleNames) newFSC.fileEntries = PickleMerging.fillWithEmptyEntries( nbEmptyEntries=60, entries={}) #prevents us from having ro remerge file later on. temp = newFSC.logger del newFSC.logger CpickleWrapper.save(newFSC, mergedPickleName) try: os.chmod(mergedPickleName, 0777) except: pass #print "saved :%s" %mergedPickleName newFSC.logger = temp return newFSC mergePicklesFromSameHour = staticmethod(mergePicklesFromSameHour) def createNonMergedPicklesList(currentTime, machines, fileType, clients): """ @summary : Create a list of all pickles names concerning different machines for a certain hour. """ pickleList = [] #print machines #print clients for machine in machines: for client in clients: pickleList.append( StatsPickler.buildThisHoursFileName( client=client, currentTime=currentTime, fileType=fileType, machine=machine)) return pickleList createNonMergedPicklesList = staticmethod(createNonMergedPicklesList) def createMergedPicklesList(startTime, endTime, clients, groupName, fileType, machines, seperators): """ @param machines: Machines must be an array containing the list of machines to use. If only one machine is to be used still use an array containing a single item. """ pickleList = [] combinedMachineName = "" combinedMachineName = combinedMachineName.join( [machine for machine in machines]) if groupName == "" or groupName is None: groupName = groupName.join([client for client in clients]) for seperator in seperators: pickleList.append( StatsPickler.buildThisHoursFileName( client=groupName, currentTime=seperator, fileType=fileType, machine=combinedMachineName)) return pickleList createMergedPicklesList = staticmethod(createMergedPicklesList) def mergePicklesFromDifferentSources( logger = None , startTime = "2006-07-31 13:00:00",\ endTime = "2006-07-31 19:00:00", clients = ["someclient"],\ fileType = "tx", machines = [], groupName = "" ): """ @summary : This method allows user to merge pickles coming from numerous machines covering as many hours as wanted, into a single FileStatsCollector entry. Very usefull when creating graphics on a central server with pickle files coming from remote locations. """ combinedMachineName = "" combinedClientName = "" combinedMachineName = combinedMachineName.join( [machine for machine in machines]) combinedClientName = combinedClientName.join( [client for client in clients]) if groupName != "": clientsForVersionManagement = groupName else: clientsForVersionManagement = clients vc = PickleVersionChecker() vc.getClientsCurrentFileList(clients) vc.getSavedList(user=combinedMachineName, clients=clientsForVersionManagement) width = StatsDateLib.getSecondsSinceEpoch( endTime) - StatsDateLib.getSecondsSinceEpoch(startTime) startTime = StatsDateLib.getIsoWithRoundedHours(startTime) seperators = [startTime] seperators.extend( StatsDateLib.getSeparatorsWithStartTime(startTime=startTime, width=width, interval=60 * StatsDateLib.MINUTE)[:-1]) mergedPickleNames = PickleMerging.createMergedPicklesList( startTime = startTime, endTime = endTime, machines = machines,\ fileType = fileType, clients = clients, groupName = groupName,\ seperators = seperators ) #Resulting list of the merger. for i in xrange(len(mergedPickleNames)): #for every merger needed needToMergeSameHoursPickle = False pickleNames = PickleMerging.createNonMergedPicklesList( currentTime=seperators[i], machines=machines, fileType=fileType, clients=clients) if not os.path.isfile(mergedPickleNames[i]): needToMergeSameHoursPickle = True else: for pickle in pickleNames: #Verify every pickle implicated in merger. # if for some reason pickle has changed since last time if vc.isDifferentFile( file=pickle, user=combinedMachineName, clients=clientsForVersionManagement) == True: needToMergeSameHoursPickle = True break if needToMergeSameHoursPickle == True: #First time or one element has changed PickleMerging.mergePicklesFromSameHour( logger = logger , pickleNames = pickleNames , clientName = combinedClientName,\ combinedMachineName = combinedMachineName, currentTime = seperators[i],\ mergedPickleName = mergedPickleNames[i], fileType = fileType ) for pickle in pickleNames: vc.updateFileInList(file=pickle) vc.saveList(user=combinedMachineName, clients=clientsForVersionManagement) # Once all machines have merges the necessary pickles we merge all pickles # into a single file stats entry. if groupName != "": nameToUseForMerger = groupName else: nameToUseForMerger = "" nameToUseForMerger = nameToUseForMerger.join( [client for client in clients]) newFSC = PickleMerging.mergePicklesFromDifferentHours( logger = logger , startTime = startTime, endTime = endTime, client = nameToUseForMerger,\ machine = combinedMachineName,fileType = fileType ) return newFSC mergePicklesFromDifferentSources = staticmethod( mergePicklesFromDifferentSources)
def generateWebPage( sourlientNames, groups, fileType, outputFileName, language ): """ @summary: Generates popupAdder web page named after the received outputFileName and based on the list of sourlients names received @param sourlientNames : List of sources or clients that need to be printed. @param groups : List of groups that need to be printed. @param fileType: tx or rx @param outputFileName : Filename that needs to be created. @return : None """ statsPaths = StatsPaths() statsPaths.setPaths(language) _ = LanguageTools.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, language ) if not os.path.isdir( os.path.dirname(outputFileName) ): os.makedirs( os.path.dirname(outputFileName) ) """ Redirect the output""" #print outputFileName fileHandle = open( outputFileName, "w" ) oldStdOut = sys.stdout #save previous stdout sys.stdout = fileHandle print """ <html> <head> <title>Add items to list.</title> <meta name="Author" content="Nicholas Lemay"> <meta name="Description" content="Small popup window used to add items into a list. To be used with graphicsResquests.py"> <meta name="Keywords" content=""> <style type="text/css"> div.selectObject{ width:300px; height: auto; } </style> <link rel="stylesheet" type="text/css" href="/css/style.css"> <script type="text/javascript" language="JavaScript"> function popupAddingWindow( url ) { var newWindow; var props = 'scrollBars=no,resizable=no,toolbar=no,menubar=no,location=no,directories=no,width=700,height=300'; newWindow = window.open(url, "Add_from_Src_to_Dest", props); } function closeWindow(){ window.close(); } // Fill the selcted item list with the items already present in parent. function copyLists( srcList, destList ) { var len = destList.length; for(var i = 0; i < srcList.length; i++) { if ( srcList.options[i] != null ) { //Check if this value already exist in the destList or not //if not then add it otherwise do not add it. var found = false; for(var count = 0; count < len; count++) { if (destList.options[count] != null) { if (srcList.options[i].text == destList.options[count].text) { found = true; break; } } } if (found != true) { destList.options[len] = new Option(srcList.options[i].text); len++; } } } } // Add the SELECTED items from the source to destination list // will only add the items wich are not allready present in dest list. function addSrcToDestList( srcList, destList ) { var len = destList.length; for(var i = 0; i < srcList.length; i++) { if ((srcList.options[i] != null) && (srcList.options[i].selected)) { //Check if this value already exist in the destList or not //if not then add it otherwise do not add it. var found = false; for(var count = 0; count < len; count++) { if (destList.options[count] != null) { if (srcList.options[i].text == destList.options[count].text) { found = true; break; } } } if (found != true) { destList.options[len] = new Option(srcList.options[i].text); len++; } } } } // Deletes from the destination list. function deleteFromList( list ) { var len = list.options.length; for(var i = (len-1); i >= 0; i--) { if ((list.options[i] != null) && (list.options[i].selected == true)) { list.options[i] = null; } } } </script> </head> <body text="#FFFFFF" link="#FFFFFF" vlink="000000" bgcolor="#7ACC7A"> <center> <form name="adderForm" method="POST"> <table bgcolor="#FFF4E5" > <tr> <font color ="white"> <td bgcolor="#006699" width="300" >""" + _("Available") + """</td> <td bgcolor="#006699" > </td> <td bgcolor="#006699" width="300" >""" + _("Selected") + """</td> </font> </tr> <tr> <td bgcolor="#7ACC7A" width="300"> <select size="12" style="width: 300px;height: 225px;font: 14px;" name="srcList" multiple> """ startingIndex = 1 if len(groups) > 0 : print """ <optgroup label=""" + '"' + _("Groups:") + """">""" + _("Groups:") + """</optgroup> """ for i in range(len(groups)): print """ <option value="%s">%s</option> """%( i+startingIndex, groups[i] ) startingIndex = i if len( sourlientNames ) > 0: if fileType == "tx": print """ <optgroup label=""" + '"'+ _("TX clients :") + """">""" + _("TX clients :") + """ </optgroup> """ elif fileType == "rx": print """ <optgroup label=""" + '"'+ _("RX sources :") + """">""" + _("RX sources :") + """ </optgroup> """ else: print """ <optgroup label=""" + '"'+ _("Sourlients :") + """">""" + _("Sourlients :") +""" </optgroup> """ for i in range(len(sourlientNames)): print """ <option value="%s">%s</option> """%( i+startingIndex, sourlientNames[i] ) print """ </select> </td> <td bgcolor="#FFF4E5" width="74" align="center"> <input type="button" value=" >> " style="font: 14px;" onClick="javascript:addSrcToDestList( document.forms['adderForm'].elements['srcList'], document.forms['adderForm'].elements['destList'] )"> <br><br> <input type="button" value=" << " style="font: 14px;" onclick="javascript:deleteFromList( document.forms['adderForm'].elements['destList'] );"> <br><br> <input type="button" value=""" + '"' + _("Done") + '"' + """ style="font: 14px;" onClick ="javascript:window.opener.copyLists(document.forms['adderForm'].elements['destList'], window.opener.document.forms['inputForm'].elements['sourlientList']);javascript:closeWindow();"> </td> <td bgcolor="#7ACC7A" width="300"> <select size="12" style="width: 300px;height: 225px;font: 14px;" name="destList" multiple> </select> </td> </tr> </table> </form> </body> </html> """ fileHandle.close() sys.stdout = oldStdOut #resets standard output
def printWebPage( self ): """ @summary : prints out the entire bottom web page @precondition: Requires _ translator to have been set prior to calling this function. """ global _ paths = StatsPaths() paths.setPaths( LanguageTools.getMainApplicationLanguage() ) fileName = paths.STATSWEBPAGES + "bottom.html" fileHandle = open( fileName, "w" ) fileHandle.write(""" <html> <head> """) self.__printJavaScript(fileHandle) fileHandle.write(""" </head> """) fileHandle.write(""" <body bgcolor="#FFD684"> <div style="position:absolute;top:20%%;vertical-align: middle;text-align:center;left:15%%;bottom:0%%;"> <img name="logo" id="logo" src="images/mainLogo_%s.gif" ></img> </div> """ %self.mainLanguage) fileHandle.write( """ <div name="linksSection" id="linksSection" style="position:absolute;top:67%;vertical-align: middle;text-align:center;left:45%;bottom:0%;"> """) for i in range( len( self.otherLanguages ) ): _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.otherLanguages[i] ) try: fileHandle.write("""<a href="top_%s.html" target="top" onclick="JavaScript:%sVersionWasClicked()">"""%( self.otherLanguages[i],self.otherLanguages[i]) + _("English version.")+ """</a>""") except: print _( "Error.Unsupported language detected." ) print _( "Make sure %s is a supported language") %( self.otherLanguages[i] ) print _( "Program terminated") sys.exit() if i != len(self.otherLanguages)-1 : fileHandle.write( "<br>" ) fileHandle.write( """ </div> </body> </html> """) fileHandle.close()
def getGraphicProducerFromParserOptions( parser ): """ This method parses the argv received when the program was called It takes the params wich have been passed by the user and sets them in the corresponding fields of the infos variable. If errors are encountered in parameters used, it will immediatly terminate the application. """ graphicType = _("other") mergerType = "" ( options, args )= parser.parse_args() timespan = options.timespan machines = options.machines.replace( ' ','').split(',') clientNames = options.clients.replace( ' ','' ).split(',') types = options.types.replace( ' ', '').split(',') date = options.date.replace('"','').replace("'",'') fileType = options.fileType.replace("'",'') havingRun = options.havingRun individual = options.individual totals = options.totals daily = options.daily weekly = options.weekly monthly = options.monthly yearly = options.yearly fixedCurrent = options.fixedCurrent fixedPrevious = options.fixedPrevious copy = options.copy turnOffLogging = options.turnOffLogging outputLanguage = options.outputLanguage if outputLanguage == "": outputLanguage = LanguageTools.getMainApplicationLanguage() else : if outputLanguage not in LanguageTools.getSupportedLanguages(): print _("Error. The specified language is not currently supported by this application.") print _("Please specify one of the following languages %s or use the default value()" %( str( LanguageTools.getSupportedLanguages() ).replace("[","").replace("]",""), LanguageTools.getMainApplicationLanguage() ) ) print _("Program terminated.") sys.exit() counter = 0 specialParameters = [daily, monthly, weekly, yearly] for specialParameter in specialParameters: if specialParameter: counter = counter + 1 if counter > 1 : print _("Error. Only one of the daily, weekly and yearly options can be use at a time ") print _("Use -h for help.") print _("Program terminated.") sys.exit() elif counter == 1 and timespan != None : print _("Error. When using the daily, the weekly or the yearly options timespan cannot be specified. " ) print _("Use -h for help.") print _("Program terminated.") sys.exit() elif counter == 0: if fixedPrevious or fixedCurrent: print _("Error. When using one of the fixed options, please use either the -d -m -w or -y options. " ) print _("Use -h for help.") print _("Program terminated.") sys.exit() if copy : if daily or not( weekly or monthly or yearly ): print _("Error. Copying can only be used with the -m -w or -y options. ") print _("Use -h for help.") print _("Program terminated.") if counter == 0 and timespan == None : timespan = 12 if fixedPrevious and fixedCurrent: print _("Error. Please use only one of the fixed options,either fixedPrevious or fixedCurrent. ") print _("Use -h for help.") print _("Program terminated.") sys.exit() if individual and totals: print _("Error. Please use only one of the group options,either individual or totals. ") print _("Use -h for help.") print _("Program terminated.") sys.exit() try: # Makes sure date is of valid format. # Makes sure only one space is kept between date and hour. t = time.strptime( date, '%Y-%m-%d %H:%M:%S' ) split = date.split() date = "%s %s" %( split[0], split[1] ) except: print _("Error. The date format must be YYYY-MM-DD HH:MM:SS") print _("Use -h for help.") print _("Program terminated.") sys.exit() #Set graphic type based on parameters. Only one tpye is allowed at once based on previous validation. if daily : graphicType = _("daily") if fixedPrevious == False and fixedCurrent == False : timespan = 24 elif weekly: graphicType = _("weekly") if fixedPrevious == False and fixedCurrent == False : timespan = 24 * 7 elif monthly: graphicType = _("monthly") if fixedPrevious == False and fixedCurrent == False : timespan = 24 * 30 elif yearly: graphicType = _("yearly") if fixedPrevious == False and fixedCurrent == False : timespan = 24 * 365 start, end = StatsDateLib.getStartEndInIsoFormat(date, timespan, graphicType, fixedCurrent, fixedPrevious ) timespan = int( StatsDateLib.getSecondsSinceEpoch( end ) - StatsDateLib.getSecondsSinceEpoch( start ) ) / 3600 #print "timespan %s" %timespan try: if int( timespan ) < 1 : raise except: print _("Error. The timespan value needs to be an integer one above 0.") print _("Use -h for help.") print _("Program terminated.") sys.exit() if fileType != "tx" and fileType != "rx": print _("Error. File type must be either tx or rx.") print "Specified file type was : ", fileType print _("Multiple types are not accepted.") print _("Use -h for additional help.") print _("Program terminated.") sys.exit() if havingRun == True and clientNames[0] != _("ALL"): print _("Error. Cannot use the havingRun option while specifying client/source names.") print _("To use havingRun, do not use -c|--client option.") print _("Use -h for additional help.") print _("Program terminated.") sys.exit() if clientNames[0] == _("ALL"): # Get all of the client/sources that have run between graph's start and end. if totals == True or havingRun == True : #print start, end, machines rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNamesHavingRunDuringPeriod( start, end, machines,None, havingrunOnAllMachines = True ) mergerType = _("totalForMachine") else:#Build graphs only for currently runningclient/sources. rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNames( LOCAL_MACHINE, machines[0] ) mergerType = _("group") if fileType == _("tx"): clientNames = txNames #print clientNames else: clientNames = rxNames else: if totals == True : mergerType = _("regular") #--------------------------------------------------------------------- try : if fileType == _("tx"): validTypes = [ _("latency"), _("bytecount"), _("errors"), _("filesOverMaxLatency"), _("filecount") ] if types[0] == _("All") : types = validTypes else : for t in types : if t not in validTypes: raise Exception("%s is not a valid type" %t) else: validTypes = [ _("bytecount"), _("errors"), _("filecount") ] if types[0] == _("All"): types = validTypes else : for t in types : if t not in validTypes: raise Exception("") #------------------------------------------------------------------- except: #----------------------------------------------------------- print types # print _("Error. With %s fileType, possible data types values are : %s.") %( fileType, validTypes ) #---- print _("For multiple types use this syntax : -t 'type1','type2'") #-------------------------------- print _("Use -h for additional help.") #---------------------------------------- print _("Program terminated.") #------------------------------------------------------------ sys.exit() if individual != True : combinedMachineName = "" for machine in machines: combinedMachineName = combinedMachineName + machine machines = [ combinedMachineName ] if len(clientNames) <1: print _("Error. No client/sources were found that matched the specified parameters") %( fileType, validTypes ) print _("Verify parameters used, especially the machines parameter.") print _("Use -h for additional help.") print _("Program terminated.") sys.exit() if len(clientNames) <1: print _("Error. No client/sources were found that matched the specified parameters") print _("Verify parameters used, especially the machines parameter.") print _("Use -h for additional help.") print _("Program terminated.") sys.exit() elif len(clientNames) == 1 and totals == True: print _("Error. Cannot use totals option with only one client/source name.") print _("Either remove --total option or use more than one client/source..") print _("Use -h for additional help.") print _("Program terminated.") sys.exit() end = StatsDateLib.getIsoWithRoundedHours( end ) graphicsProducer = RRDGraphicProducer( startTime = start, endTime = end, graphicType = graphicType, clientNames = clientNames, types = types, timespan = timespan, machines = machines, fileType = fileType,\ totals = totals, copy = copy, mergerType = mergerType,turnOffLogging = turnOffLogging, inputLanguage = LanguageTools.getMainApplicationLanguage() , outputLanguage = outputLanguage ) return graphicsProducer
""" sys.path.insert(1, os.path.dirname( os.path.abspath(__file__) ) + '/../../') from pxStats.lib.StatsDateLib import StatsDateLib from pxStats.lib.RrdUtilities import RrdUtilities from pxStats.lib.GeneralStatsLibraryMethods import GeneralStatsLibraryMethods from pxStats.lib.StatsPaths import StatsPaths from pxStats.lib.LanguageTools import LanguageTools from pxStats.lib.RRDGraphicProducer import RRDGraphicProducer """ - Small function that adds pxLib to sys path. """ STATSPATHS = StatsPaths( ) STATSPATHS.setPaths( LanguageTools.getMainApplicationLanguage() ) sys.path.append( STATSPATHS.PXLIB ) # These Imports require pxlib from PXManager import * from Logger import * LOCAL_MACHINE = os.uname()[1] CURRENT_MODULE_ABS_PATH = os.path.abspath(__file__).replace( ".pyc", ".py" ) def getGraphicProducerFromParserOptions( parser ): """ This method parses the argv received when the program was called
def getOptionsFromParser(parser): """ @summary : This method parses the argv received when the program was called It takes the params wich have been passed by the user and sets them in the corresponding fields of the infos variable. If errors are encountered in parameters used, it will immediatly terminate the application. """ (options, args) = parser.parse_args() timespan = options.timespan machines = options.machines.replace(' ', '').split(',') combinedName = options.machines.replace(' ', '').replace('[', '').replace(']', '') date = options.date.replace('"', '').replace("'", '') logins = options.logins.replace('"', '').replace(" ", "").split(',') combine = options.combine individual = options.individual outputLanguage = options.outputLanguage try: # Makes sure date is of valid format. # Makes sure only one space is kept between date and hour. t = time.strptime( date, '%Y-%m-%d %H:%M:%S') #will raise exception if format is wrong. split = date.split() currentTime = "%s %s" % (split[0], split[1]) except: print _("Error. The date format must be YYYY-MM-DD HH:MM:SS") print _("Use -h for help.") print _("Program terminated.") sys.exit() try: if int(timespan) < 1: raise except: print _( "Error. The timespan value needs to be an integer one above 0.") print _("Use -h for help.") print _("Program terminated.") sys.exit() if len(logins) != len(machines): print _("Error. Number of logins does not match number of machines.") print _("Use -l 'login1,login2,loginX' for multiple machines.") print _("Program terminated.") sys.exit() if outputLanguage not in LanguageTools.getSupportedLanguages(): print _("Error. %s is not one of the supproted languages") print _("Use one of the following languages : %s") % str( LanguageTools.getSupportedLanguages()).replace("[", "").replace( "]", "") print _("Use -h for additional help.") print _("Program terminated.") if len(machines) == 1: combine = False individual = True elif combine == False and individual == False: #no option specified + len >1 combine = True infos = _Infos( date = date, machines = machines, timespan = timespan, logins = logins,\ combine = combine, individual = individual, combinedName = combinedName,\ outputLanguage = outputLanguage ) return infos
def getOptionsFromParser( parser ): """ @summary : This method parses the argv received when the program was called It takes the params wich have been passed by the user and sets them in the corresponding fields of the infos variable. If errors are encountered in parameters used, it will immediatly terminate the application. """ ( options, args )= parser.parse_args() timespan = options.timespan machines = options.machines.replace( ' ','' ).split( ',' ) combinedName = options.machines.replace( ' ','' ).replace( '[','' ).replace( ']', '' ) date = options.date.replace( '"','' ).replace( "'",'') logins = options.logins.replace( '"', '' ).replace( " ","" ).split( ',' ) combine = options.combine individual = options.individual outputLanguage = options.outputLanguage try: # Makes sure date is of valid format. # Makes sure only one space is kept between date and hour. t = time.strptime( date, '%Y-%m-%d %H:%M:%S' )#will raise exception if format is wrong. split = date.split() currentTime = "%s %s" %( split[0], split[1] ) except: print _( "Error. The date format must be YYYY-MM-DD HH:MM:SS" ) print _( "Use -h for help." ) print _( "Program terminated." ) sys.exit() try: if int( timespan ) < 1 : raise except: print _( "Error. The timespan value needs to be an integer one above 0." ) print _( "Use -h for help." ) print _( "Program terminated." ) sys.exit() if len( logins ) != len( machines ) : print _( "Error. Number of logins does not match number of machines." ) print _( "Use -l 'login1,login2,loginX' for multiple machines." ) print _( "Program terminated." ) sys.exit() if outputLanguage not in LanguageTools.getSupportedLanguages(): print _("Error. %s is not one of the supproted languages") print _("Use one of the following languages : %s") % str( LanguageTools.getSupportedLanguages() ).replace("[","").replace("]","") print _("Use -h for additional help.") print _("Program terminated.") if len( machines ) == 1: combine = False individual = True elif combine == False and individual == False :#no option specified + len >1 combine = True infos = _Infos( date = date, machines = machines, timespan = timespan, logins = logins,\ combine = combine, individual = individual, combinedName = combinedName,\ outputLanguage = outputLanguage ) return infos
def searchForParameterErrors(self): """ @summary : Validates parameters. @return : Returns the first error found within the current query parameters. """ global _ error = "" try: if self.queryParameters.plotter != "gnuplot": error = _( "Internal error. GnuQueryBroker was not called to plota gnuplot graphic." ) raise for fileType in self.queryParameters.fileTypes: if fileType != "tx" and fileType != "rx": error = _("Error. FileType needs to be either rx or tx.") raise if self.queryParameters.sourLients == []: if self.queryParameters.groupName == "": error = _( "Error. At least one sourlient name needs to be specified." ) else: error = _( "Error. When specifying a group name without any sourlients names, the group must be a pre-existing group." ) if self.queryParameters.machines == []: error = _( "Error. At least one machine name needs to be specified.") if self.queryParameters.combine != 'true' and self.queryParameters.combine != 'false': error = _( "Error. Combine sourlients option needs to be either true or false." ) if self.queryParameters.statsTypes == []: error = _( "Error. At Leat one statsType needs to be specified.") try: int(self.queryParameters.span) except: error = _("Error. Span(in hours) value needs to be numeric.") if self.queryParameters.language == "": error = _( "Error. No language was specified by the querier. Please speciffy a language. Ex : lang=fr" ) elif self.queryParameters.language not in LanguageTools.getSupportedLanguages( ): error = _( "Error. Unsupported language detected in GnuQueryBroker. %s is not a supported language." ) % (self.queryParameters.language) except: pass return error