def generateGraphsForIndividualMachines( infos ) : """ @summary : Generate graphs for every specified machine withoout merging any of the data between the machines. """ for i in range ( len( infos.machines ) ) : rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNames( LOCAL_MACHINE, infos.machines[i] ) j=0 for txName in txNames : pid = os.fork()#create child process if pid == 0: #child process output = commands.getoutput( "python %sgenerateGnuGraphics.py -m '%s' -f tx -c '%s' -d '%s' -s %s --copy --outputLanguage %s" \ %( STATSPATHS.STATSBIN, infos.machines[i], txName, infos.date, infos.timespan, infos.outputLanguage ) ) print output sys.exit() else: j = j + 1 if j %10 == 0: while True:#wait on all non terminated child process' try: #will raise exception when no child process remain. pid, status = os.wait( ) except: break while True:#wait on all non terminated child process' try: #will raise exception when no child process remain. pid, status = os.wait( ) except: break j=0 for rxName in rxNames: pid = os.fork()#create child process if pid == 0 :#child process output = commands.getoutput( "python %sgenerateGnuGraphics.py -m '%s' -f rx -c '%s' -d '%s' -s %s --copy --outputLanguage %s"\ %( STATSPATHS.STATSBIN, infos.machines[i] , rxName, infos.date,infos.timespan, infos.outputLanguage ) ) print output sys.exit() else: j = j + 1 if j %10 == 0: while True:#wait on all non terminated child process' try: #will raise exception when no child process remain. pid, status = os.wait( ) except: break while True:#wait on all non terminated child process' try: #will raise exception when no child process remain. pid, status = os.wait( ) except: break
def generateGraphsForIndividualMachines(infos): """ @summary : Generate graphs for every specified machine withoout merging any of the data between the machines. """ for i in range(len(infos.machines)): rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNames( LOCAL_MACHINE, infos.machines[i]) j = 0 for txName in txNames: pid = os.fork() #create child process if pid == 0: #child process output = commands.getoutput( "python %sgenerateGnuGraphics.py -m '%s' -f tx -c '%s' -d '%s' -s %s --copy --outputLanguage %s" \ %( STATSPATHS.STATSBIN, infos.machines[i], txName, infos.date, infos.timespan, infos.outputLanguage ) ) print output sys.exit() else: j = j + 1 if j % 10 == 0: while True: #wait on all non terminated child process' try: #will raise exception when no child process remain. pid, status = os.wait() except: break while True: #wait on all non terminated child process' try: #will raise exception when no child process remain. pid, status = os.wait() except: break j = 0 for rxName in rxNames: pid = os.fork() #create child process if pid == 0: #child process output = commands.getoutput( "python %sgenerateGnuGraphics.py -m '%s' -f rx -c '%s' -d '%s' -s %s --copy --outputLanguage %s"\ %( STATSPATHS.STATSBIN, infos.machines[i] , rxName, infos.date,infos.timespan, infos.outputLanguage ) ) print output sys.exit() else: j = j + 1 if j % 10 == 0: while True: #wait on all non terminated child process' try: #will raise exception when no child process remain. pid, status = os.wait() except: break while True: #wait on all non terminated child process' try: #will raise exception when no child process remain. pid, status = os.wait() except: break
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 generateGraphsForPairedMachines(infos): """ @summary : Create graphs for all client by merging the data from all the listed machines. """ rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNames( LOCAL_MACHINE, infos.machines[0]) #print infos.machines #print txNames infos.combinedName = str(infos.machines).replace(' ', '').replace( '[', '').replace(']', '') j = 0 for txName in txNames: pid = os.fork() #create child process if pid == 0: #child process output = commands.getoutput( "python %sgenerateGnuGraphics.py -m %s -f tx -c %s -d '%s' -s %s --copy --outputLanguage %s" % (STATSPATHS.STATSBIN, infos.combinedName, txName, infos.date, infos.timespan, infos.outputLanguage)) print output sys.exit() #terminate child process else: #print "wait" j = j + 1 if j % 10 == 0: while True: #wait on all non terminated child process' try: #will raise exception when no child process remain. pid, status = os.wait() except: break while True: #wait on all non terminated child process' try: #will raise exception when no child process remain. pid, status = os.wait() except: break j = 0 for rxName in rxNames: pid = os.fork() #create child process if pid == 0: #child process output = commands.getoutput( "python %sgenerateGnuGraphics.py -m %s -f rx -c %s -d '%s' -s %s --copy --outputLanguage %s"\ %( STATSPATHS.STATSBIN, infos.combinedName, rxName, infos.date, infos.timespan, infos.outputLanguage ) ) print output sys.exit() else: j = j + 1 if j % 10 == 0: while True: #wait on all non terminated child process' try: #will raise exception when no child process remain. pid, status = os.wait() except: break while True: #wait on all non terminated child process' try: #will raise exception when no child process remain. #print "goes to wait" pid, status = os.wait() except: break
def getOptionsFromParser( parser, paths, logger = None ): """ @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 hlE variable. @Warning : If errors are encountered in parameters used, it will immediatly terminate the application. """ directories = [] startTimes = [] ( options, args ) = parser.parse_args() interval = options.interval collectUpToNow = options.collectUpToNow currentDate = options.currentDate.replace( '"','' ).replace( "'",'' ) currentDate = StatsDateLib.getIsoWithRoundedHours( currentDate ) fileType = options.fileType.replace( "'",'' ) machine = options.machine.replace( " ","" ) clients = options.clients.replace(' ','' ).split( ',' ) types = options.types.replace( ' ', '' ).split( ',' ) pathToLogFiles = GeneralStatsLibraryMethods.getPathToLogFiles( LOCAL_MACHINE, machine ) #print "*****pathToLogFiles %s" %pathToLogFiles try: # Makes sure date is of valid format. # Makes sure only one space is kept between date and hour. t = time.strptime( currentDate, '%Y-%m-%d %H:%M:%S' ) split = currentDate.split() currentDate = "%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( interval ) < 1 : raise except: print _("Error. The interval 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 fileType == "tx": validTypes = [ _("errors"), _("latency"), _("bytecount") ] else: validTypes = [ _("errors"), _("bytecount") ] if types[0] == _("All"): types = validTypes try : for t in types : if t not in validTypes: raise 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() def translateType(typeToTranslate): translations = { _("errors"):"errors", _("latency"):"latency", _("bytecount"):"bytecount" } return translations[typeToTranslate] types = map( translateType, types ) if clients[0] == _("All") : rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNames( LOCAL_MACHINE, machine ) if fileType == "tx": clients = txNames else: clients = rxNames #print "clients found :%s" %clients # Verify that each client needs to be updated. # If not we add a warning to the logger and removwe the client from the list # since it's not needed, but other clients might be. usefullClients = [] for client in clients : startTime = getLastUpdate( machine = machine, client = client, fileType= fileType, currentDate = currentDate , paths = paths, collectUpToNow = collectUpToNow ) if currentDate > startTime: #print " client : %s currentDate : %s startTime : %s" %( client, currentDate, startTime ) directories.append( pathToLogFiles ) startTimes.append( startTime ) usefullClients.append( client ) else: #print "This client was not updated since it's last update was more recent than specified date : %s" %client if logger != None : try: logger.warning( _("This client was not updated since it's last update was more recent than specified date : %s") %client) except : pass infos = _UpdaterInfos( currentDate = currentDate, clients = usefullClients, startTimes = startTimes, directories = directories ,\ types = types, collectUpToNow = collectUpToNow, fileType = fileType, machine = machine ) if collectUpToNow == False: infos.endTime = StatsDateLib.getIsoWithRoundedHours( infos.currentDate ) return infos
def getMaximumGaps( self ): """ @summary : Reads columbos maxSettings.conf file @returns: The maximum gaps dictionnary containing the maximium gap allowed between two transfers for a specific client. ex : { clientX: 60 } """ allNames = [] rxNames = [] txNames = [] maximumGaps = {} try: machineConfig = MachineConfigParameters() machineConfig.getParametersFromMachineConfigurationFile() generalParameters = StatsConfigParameters() generalParameters.getAllParameters() self.__updateMaxSettingsFile( generalParameters ) for tag in generalParameters.sourceMachinesTags: try: #print tag #print "in getMaximumGaps %s" %generalParameters.detailedParameters.sourceMachinesForTag machines = generalParameters.detailedParameters.sourceMachinesForTag[tag] machine = machines[0] except: raise Exception( "Invalid tag found in main configuration file." ) newRxNames, newTxNames = GeneralStatsLibraryMethods.getRxTxNames( LOCAL_MACHINE, machine ) rxNames.extend(newRxNames) txNames.extend(newTxNames) allNames.extend( rxNames ) allNames.extend( txNames ) circuitsRegex, default_circuit, timersRegex, default_timer, pxGraphsRegex, default_pxGraph = readMaxFile.readQueueMax( self.maxSettingsFile, "PX" ) for key in timersRegex.keys(): #fill all explicitly set maximum gaps. values = timersRegex[key] newKey = key.replace( "^", "" ).replace( "$","").replace(".","") maximumGaps[newKey] = values for name in allNames:#add all clients/sources for wich no value was set if name not in maximumGaps.keys(): #no value was set nameFoundWithWildcard = False for key in timersRegex.keys(): # in case a wildcard character was used cleanKey = key.replace( "^", "" ).replace( "$","").replace(".","") if fnmatch.fnmatch( name, cleanKey ): maximumGaps[name] = timersRegex[key] nameFoundWithWildcard = True if nameFoundWithWildcard == False : maximumGaps[name] = default_timer except:#in case of corrupt or absent file maximumGaps = {} return maximumGaps
def generateGraphsForPairedMachines( infos ) : """ @summary : Create graphs for all client by merging the data from all the listed machines. """ rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNames( LOCAL_MACHINE, infos.machines[0] ) #print infos.machines #print txNames infos.combinedName = str(infos.machines).replace( ' ','' ).replace( '[','' ).replace( ']', '' ) j=0 for txName in txNames : pid = os.fork()#create child process if pid == 0 :#child process output = commands.getoutput( "python %sgenerateGnuGraphics.py -m %s -f tx -c %s -d '%s' -s %s --copy --outputLanguage %s" %( STATSPATHS.STATSBIN, infos.combinedName, txName, infos.date, infos.timespan, infos.outputLanguage ) ) print output sys.exit() #terminate child process else: #print "wait" j = j + 1 if j %10 == 0: while True:#wait on all non terminated child process' try: #will raise exception when no child process remain. pid, status = os.wait( ) except: break while True:#wait on all non terminated child process' try: #will raise exception when no child process remain. pid, status = os.wait( ) except: break j=0 for rxName in rxNames: pid = os.fork()#create child process if pid == 0:#child process output = commands.getoutput( "python %sgenerateGnuGraphics.py -m %s -f rx -c %s -d '%s' -s %s --copy --outputLanguage %s"\ %( STATSPATHS.STATSBIN, infos.combinedName, rxName, infos.date, infos.timespan, infos.outputLanguage ) ) print output sys.exit() else: j = j + 1 if j %10 == 0: while True:#wait on all non terminated child process' try: #will raise exception when no child process remain. pid, status = os.wait( ) except: break while True:#wait on all non terminated child process' try: #will raise exception when no child process remain. #print "goes to wait" pid, status = os.wait( ) except: break
def main(): """ @summary : Generates the web page based on the received machines and file type parameters. """ try: newForm = {} form = cgi.FieldStorage() for key in form.keys(): value = form.getvalue(key, "") if isinstance(value, list): # Multiple username fields specified newvalue = ",".join(value) else: newvalue = value newForm[key.replace("?","")]= newvalue form = newForm try: language = form["lang"] except: language = "" error = "Error.Unknwown language detected in popSourlientUpAdder" try: fileType = form['fileType'] if fileType !='tx' and fileType != 'rx': error= "Error. File type needs to be either rx or tx." except: fileType = "" try: machines = form['machines'] machine = machines.split( ',' )[0] machines = machines.replace( ',', '' ) except: error = "Error. Machine names need to be specified." machine = "" if machines != "": rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNames( LOCAL_MACHINE, machine ) groups = getGroups( fileType, machine ) #print "/../../html/popUps/%s%sPopUpSourlientAdder_%s.html" %( fileType, machines, language ) #----------------------------- fileHandle = open("/web/pxStats/out","w") # fileHandle.write(sys.path[0] + "/../../html/popUps/%s%sPopUpSourlientAdder_%s.html" %( fileType, machines, language )) #---------------------------------------------------- fileHandle.close() path = StatsPaths() path.setPaths( language ) if fileType == "tx": generateWebPage(txNames, groups, fileType, path.STATSWEBPAGESHTML + "/popUps/%s%sPopUpSourlientAdder_%s.html" %( fileType, machines, language ), language ) elif fileType == "rx": generateWebPage(rxNames, groups, fileType, path.STATSWEBPAGESHTML + "/popUps/%s%sPopUpSourlientAdder_%s.html" %( fileType, machines, language ), language ) returnReply('') except Exception, instance: fileHandle = open("/web/pxStats/out","w") fileHandle.write( "bug in main method" ) fileHandle.write( str( instance ) ) fileHandle.close() sys.exit()
def main(): """ @summary : Generates the web page based on the received machines and file type parameters. """ try: newForm = {} form = cgi.FieldStorage() for key in form.keys(): value = form.getvalue(key, "") if isinstance(value, list): # Multiple username fields specified newvalue = ",".join(value) else: newvalue = value newForm[key.replace("?", "")] = newvalue form = newForm try: language = form["lang"] except: language = "" error = "Error.Unknwown language detected in popSourlientUpAdder" try: fileType = form['fileType'] if fileType != 'tx' and fileType != 'rx': error = "Error. File type needs to be either rx or tx." except: fileType = "" try: machines = form['machines'] machine = machines.split(',')[0] machines = machines.replace(',', '') except: error = "Error. Machine names need to be specified." machine = "" if machines != "": rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNames( LOCAL_MACHINE, machine) groups = getGroups(fileType, machine) #print "/../../html/popUps/%s%sPopUpSourlientAdder_%s.html" %( fileType, machines, language ) #----------------------------- fileHandle = open("/web/pxStats/out","w") # fileHandle.write(sys.path[0] + "/../../html/popUps/%s%sPopUpSourlientAdder_%s.html" %( fileType, machines, language )) #---------------------------------------------------- fileHandle.close() path = StatsPaths() path.setPaths(language) if fileType == "tx": generateWebPage( txNames, groups, fileType, path.STATSWEBPAGESHTML + "/popUps/%s%sPopUpSourlientAdder_%s.html" % (fileType, machines, language), language) elif fileType == "rx": generateWebPage( rxNames, groups, fileType, path.STATSWEBPAGESHTML + "/popUps/%s%sPopUpSourlientAdder_%s.html" % (fileType, machines, language), language) returnReply('') except Exception, instance: fileHandle = open("/web/pxStats/out", "w") fileHandle.write("bug in main method") fileHandle.write(str(instance)) fileHandle.close() sys.exit()
def getOptionsFromParser( parser, logger = None ): """ 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() end = options.end.replace( '"','' ).replace( "'",'') clients = options.clients.replace( ' ','' ).split( ',' ) machines = options.machines.replace( ' ','' ).split( ',' ) fileTypes = options.fileTypes.replace( ' ','' ).split( ',' ) products = options.products.replace( ' ','' ).split( ',' ) group = options.group.replace( ' ','' ) try: # Makes sure date is of valid format. # Makes sure only one space is kept between date and hour. t = time.strptime( end, '%Y-%m-%d %H:%M:%S' )#will raise exception if format is wrong. split = end.split() currentTime = "%s %s" %( split[0], split[1] ) except: print _( "Error. The endind date format must be YYYY-MM-DD HH:MM:SS" ) print _( "Use -h for help." ) print _( "Program terminated." ) sys.exit() #round ending hour to match pickleUpdater. end = StatsDateLib.getIsoWithRoundedHours( end ) for machine in machines: if machine != LOCAL_MACHINE: GeneralStatsLibraryMethods.updateConfigurationFiles( machine, "pds" ) if products[0] != _("ALL") and group == "" : print _( "Error. Products can only be specified when using special groups." ) print _( "Use -h for help." ) print _( "Program terminated." ) sys.exit() #init fileTypes array here if only one fileType is specified for all clients/sources if len(fileTypes) == 1 and len(clients) !=1: for i in range(1,len(clients) ): fileTypes.append(fileTypes[0]) if clients[0] == _( "ALL" ) and fileTypes[0] != "": print _( "Error. Filetypes cannot be specified when all clients are to be updated." ) print _( "Use -h for help." ) print _( "Program terminated." ) sys.exit() elif clients[0] != _( "ALL" ) and len(clients) != len( fileTypes ) : print _( "Error. Specified filetypes must be either 1 for all the group or of the exact same lenght as the number of clients/sources." ) print _( "Use -h for help." ) print _( "Program terminated." ) sys.exit() elif clients[0] == _( 'ALL' ) : rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNames( LOCAL_MACHINE, machines[0] ) clients = [] clients.extend( txNames ) clients.extend( rxNames ) fileTypes = [] for txName in txNames: fileTypes.append( _( "tx" ) ) for rxName in rxNames: fileTypes.append( _( "rx" ) ) clients = GeneralStatsLibraryMethods.filterClientsNamesUsingWilcardFilters( end, 1000, clients, machines, fileTypes= fileTypes ) infos = _Infos( endTime = end, machines = machines, clients = clients, fileTypes = fileTypes, products = products, group = group ) return infos
def getOptionsFromParser(parser, logger=None): """ 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() end = options.end.replace('"', '').replace("'", '') clients = options.clients.replace(' ', '').split(',') machines = options.machines.replace(' ', '').split(',') fileTypes = options.fileTypes.replace(' ', '').split(',') products = options.products.replace(' ', '').split(',') group = options.group.replace(' ', '') try: # Makes sure date is of valid format. # Makes sure only one space is kept between date and hour. t = time.strptime( end, '%Y-%m-%d %H:%M:%S') #will raise exception if format is wrong. split = end.split() currentTime = "%s %s" % (split[0], split[1]) except: print _("Error. The endind date format must be YYYY-MM-DD HH:MM:SS") print _("Use -h for help.") print _("Program terminated.") sys.exit() #round ending hour to match pickleUpdater. end = StatsDateLib.getIsoWithRoundedHours(end) for machine in machines: if machine != LOCAL_MACHINE: GeneralStatsLibraryMethods.updateConfigurationFiles(machine, "pds") if products[0] != _("ALL") and group == "": print _( "Error. Products can only be specified when using special groups.") print _("Use -h for help.") print _("Program terminated.") sys.exit() #init fileTypes array here if only one fileType is specified for all clients/sources if len(fileTypes) == 1 and len(clients) != 1: for i in range(1, len(clients)): fileTypes.append(fileTypes[0]) if clients[0] == _("ALL") and fileTypes[0] != "": print _( "Error. Filetypes cannot be specified when all clients are to be updated." ) print _("Use -h for help.") print _("Program terminated.") sys.exit() elif clients[0] != _("ALL") and len(clients) != len(fileTypes): print _( "Error. Specified filetypes must be either 1 for all the group or of the exact same lenght as the number of clients/sources." ) print _("Use -h for help.") print _("Program terminated.") sys.exit() elif clients[0] == _('ALL'): rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNames( LOCAL_MACHINE, machines[0]) clients = [] clients.extend(txNames) clients.extend(rxNames) fileTypes = [] for txName in txNames: fileTypes.append(_("tx")) for rxName in rxNames: fileTypes.append(_("rx")) clients = GeneralStatsLibraryMethods.filterClientsNamesUsingWilcardFilters( end, 1000, clients, machines, fileTypes=fileTypes) infos = _Infos(endTime=end, machines=machines, clients=clients, fileTypes=fileTypes, products=products, group=group) return infos