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 __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 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 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 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 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 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 __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 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 __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 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 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 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
def __init__( self, timespan, stats = None, clientNames = None, groupName = "", type='lines', \ interval=1, imageName="gnuplotOutput", title = "Stats", currentTime = "",now = False, \ statsTypes = None, productTypes = None, logger = None, logging = True, fileType = "tx", \ machines = "", entryType = "minute", maxLatency = 15, workingLanguage = None, outputLanguage = None ): """ @summary : GnuPlotter constructor. """ #TODO Verify if all theses fileds are really necessary. machines = "%s" %machines machines = machines.replace( "[","").replace( "]","" ).replace( "'", "" ) self.now = now # False means we round to the top of the hour, True we don't self.stats = stats or [] # ClientStatsPickler instance. self.clientNames = clientNames or [] # Clients for wich we are producing the graphics. self.groupName = groupName # Group name used when combining data of numerous client/sources. self.timespan = timespan # Helpfull to build titles self.currentTime = currentTime # Time of call self.type = 'impulses' # Must be in: ['linespoint', 'lines', 'boxes', 'impulses']. self.fileType = fileType # Type of file for wich the data was collected self.imageName = imageName # Name of the image file. self.nbFiles = [] # Number of files found in the data collected per server. self.nbErrors = [] # Number of errors found per server self.graph = Gnuplot.Gnuplot() # The gnuplot graphic object itself. self.timeOfMax = [[]] # Time where the maximum value occured. self.machines = machines # List of machine where we collected info. self.entryType = entryType # Entry type : minute, hour, week, month self.clientName = "" # Name of the client we are dealing with self.maxLatency = maxLatency # Maximum latency self.maximums = [[]] # List of all maximum values 1 for each graphic. self.minimums = [[]] # Minimum value of all pairs. self.means = [[]] # Mean of all the pairs. self.maxFileNames= [[]] # Name of file where value is the highest . self.filesWhereMaxOccured = [[]] # List of files for wich said maximums occured. self.statsTypes = statsTypes or [] # List of data types to plot per client. self.totalNumberOfBytes = [] # Total of bytes for each client self.nbFilesOverMaxLatency = [] # Numbers of files for wich the latency was too long. self.ratioOverLatency = [] # % of files for wich the latency was too long. self.const = len( self.stats ) -1 # Usefull constant self.productTypes = productTypes # Type of product for wich the graph is being generated. self.initialiseArrays() self.loggerName = 'gnuPlotter' self.logger = logger self.logging = logging self.workingLanguage = workingLanguage # Language with whom we are currently working, in which the string parameters were specified. self.outputLanguage = outputLanguage # Language in which the graphics will be produced. if self.logging == True: if self.logger == None: # Enable logging self.logger = Logger( StatsPaths.STATSLOGGING + 'stats_' + self.loggerName + '.log',\ 'INFO', 'TX' + self.loggerName, bytes = True ) self.logger = self.logger.getLogger() if self.workingLanguage == None: self.workingLanguage = LanguageTools.getMainApplicationLanguage() if self.outputLanguage == None: self.outputLanguage = LanguageTools.getMainApplicationLanguage() if self.workingLanguage not in LanguageTools.getSupportedLanguages(): if self.logging == True: _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.workingLanguage ) self.logger.error( _("Error. %s is not a supported working language.") %( self.workingLanguage ) ) sys.exit() if self.outputLanguage not in LanguageTools.getSupportedLanguages(): if self.logging == True: _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.workingLanguage ) self.logger.error( _("Error. %s is not a supported output language.") %( self.outputLanguage ) ) sys.exit() _ = self.getTranslatorForModule(CURRENT_MODULE_ABS_PATH, self.workingLanguage) self.productTypes = productTypes or [ _( "All" ) ] _ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.outputLanguage ) if self.fileType == 'tx': self.sourlient = _("Client") else: self.sourlient = _("Source") self.xtics = self.getXTics( ) # Seperators on the x axis.
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 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
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
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