def getParametersFromForm(self, form): """ @summary: Initialises the queryParameters based on the form received as parameter. @note : Absent parameters will be set to default values( [] or '' ) and will NOT raise exceptions. Use the searchForParameterErrors function to search for errors """ global _ #print form image = None #No image was produced yet #Every param is received in an array, use [0] to get first item, nothing for array. try: querier = form["querier"].replace("'", "").replace('"', '') except: querier = '' try: plotter = form["plotter"].replace("'", "").replace('"', '') except: plotter = '' try: fileTypes = form["fileType"].replace("'", "").replace('"', '') except: fileTypes = '' try: sourLients = form["sourLients"].split(',') except: sourLients = [] try: groupName = form["groupName"].replace("'", "").replace('"', '') except: groupName = '' try: machines = form["machines"].split(',') except: machines = [] if groupName != '' and (sourLients == [] or sourLients == ['']): configParameters = StatsConfigParameters() configParameters.getAllParameters() if groupName in configParameters.groupParameters.groups: if configParameters.groupParameters.groupFileTypes[ groupName] == fileTypes and configParameters.groupParameters.groupsMachines[ groupName] == machines: sourLients = configParameters.groupParameters.groupsMembers[ groupName] try: combine = form["combineSourlients"].replace(",", "").replace('"', '') if combine == 'false' or combine == 'False': combine = False elif combine == 'true' or combine == 'True': combine = True else: raise except: combine = False try: endTime = form["endTime"].replace("'", "").replace('"', '') hour = endTime.split(" ")[1] splitDate = endTime.split(" ")[0].split('-') endTime = "%s" % (splitDate[2] + '-' + splitDate[1] + '-' + splitDate[0] + " " + hour) if _("current") in str(form["fixedSpan"]).lower(): start, endTime = StatsDateLib.getStartEndFromCurrentDay( endTime) elif _("previous") in str(form["fixedSpan"]).lower(): start, endTime = StatsDateLib.getStartEndFromPreviousDay( endTime) except: endTime = '' try: products = form["products"].split(',') if products == [""]: raise except: products = ["*"] try: statsTypes = form["statsTypes"].split(',') except: statsTypes = [] #statsTypes = translateStatsTypes( statsTypes ) try: span = form["span"].replace("'", "").replace('"', '') if str(span).replace(' ', '') == '': raise span = int(span) except: span = 24 try: language = form["lang"].replace("'", "").replace('"', '') except: language = "" sourLients = GeneralStatsLibraryMethods.filterClientsNamesUsingWilcardFilters( endTime, span, sourLients, machines, [fileTypes]) self.queryParameters = GnuQueryBroker._QueryParameters( fileTypes, sourLients, groupName, machines, combine, endTime, products, statsTypes, span, language) self.replyParameters = GnuQueryBroker._ReplyParameters( querier, plotter, image, fileTypes, sourLients, groupName, machines, combine, endTime, products, statsTypes, span, '', language)
def getParametersFromForm( self, form ): """ @summary: Initialises the queryParameters based on the form received as parameter. @note : Absent parameters will be set to default values( [] or '' ) and will NOT raise exceptions. Use the searchForParameterErrors function to search for errors """ global _ #print form image = None #No image was produced yet #Every param is received in an array, use [0] to get first item, nothing for array. try: querier = form["querier"].replace("'", "").replace('"','') except: querier = '' try: plotter = form["plotter"].replace("'", "").replace('"','') except: plotter = '' try: fileTypes = form["fileType"].replace("'", "").replace('"','') except: fileTypes = '' try: sourLients = form["sourLients"].split(',') except: sourLients = [] try: groupName = form["groupName"].replace("'", "").replace('"','') except: groupName = '' try: machines = form["machines"].split(',') except: machines = [] if groupName != '' and ( sourLients == [] or sourLients == [''] ) : configParameters = StatsConfigParameters( ) configParameters.getAllParameters() if groupName in configParameters.groupParameters.groups: if configParameters.groupParameters.groupFileTypes[groupName] == fileTypes and configParameters.groupParameters.groupsMachines[groupName] == machines: sourLients = configParameters.groupParameters.groupsMembers[groupName] try: combine = form["combineSourlients"].replace(",", "").replace('"','') if combine == 'false' or combine == 'False': combine = False elif combine == 'true' or combine == 'True': combine = True else: raise except: combine = False try: endTime = form["endTime"].replace("'", "").replace('"','') hour = endTime.split(" ")[1] splitDate = endTime.split(" ")[0].split( '-' ) endTime = "%s" %( splitDate[2] + '-' + splitDate[1] + '-' + splitDate[0] + " " + hour ) if _("current") in str(form["fixedSpan"]).lower(): start, endTime = StatsDateLib.getStartEndFromCurrentDay(endTime) elif _("previous") in str(form["fixedSpan"]).lower(): start, endTime = StatsDateLib.getStartEndFromPreviousDay( endTime ) except: endTime = '' try: products = form["products"].split(',') if products == [""]: raise except: products = ["*"] try: statsTypes = form["statsTypes"].split(',') except: statsTypes = [] #statsTypes = translateStatsTypes( statsTypes ) try: span = form["span"].replace("'", "").replace('"','') if str(span).replace( ' ', '' ) == '': raise span = int(span) except: span = 24 try: language = form["lang"].replace("'", "").replace('"','') except: language = "" sourLients = GeneralStatsLibraryMethods.filterClientsNamesUsingWilcardFilters( endTime, span, sourLients, machines, [fileTypes]) self.queryParameters = GnuQueryBroker._QueryParameters( fileTypes, sourLients, groupName, machines, combine, endTime, products, statsTypes, span, language ) self.replyParameters = GnuQueryBroker._ReplyParameters( querier, plotter, image, fileTypes, sourLients, groupName, machines, combine, endTime, products, statsTypes, span, '', language )
def getOptionsFromParser( parser ): """ @summary: Parses and validates the options found in the parser. @return: If information was found to be valid, return options """ infos = None date = [] ( options, args )= parser.parse_args() machines = options.machines.replace( ' ','').split(',') date = options.date.replace('"','').replace("'",'') fileType = options.fileType.replace("'",'') daily = options.daily weekly = options.weekly monthly = options.monthly yearly = options.yearly fixedCurrent = options.fixedCurrent fixedPrevious = options.fixedPrevious turnOffLogging = options.turnOffLogging includeGroups = options.includeGroups machinesAreClusters = options.machinesAreClusters outputLanguage = options.outputLanguage 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() 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 == 0: print _( "Error. Please use either the -d -m -w or -y options. " ) 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() #TODO :fixStartEnd method??? if fixedPrevious : if daily : span = "daily" graphicType = "daily" start, end = StatsDateLib.getStartEndFromPreviousDay( date ) elif weekly: span = "weekly" graphicType = "weekly" start, end = StatsDateLib.getStartEndFromPreviousWeek( date ) elif monthly: span = "monthly" graphicType = "monthly" start, end = StatsDateLib.getStartEndFromPreviousMonth( date ) elif yearly: span = "yearly" graphicType = "yearly" start, end = StatsDateLib.getStartEndFromPreviousYear( date ) timeSpan = int( StatsDateLib.getSecondsSinceEpoch( end ) - StatsDateLib.getSecondsSinceEpoch( start ) ) / 3600 elif fixedCurrent: if daily : span = "daily" graphicType = "daily" start, end = StatsDateLib.getStartEndFromCurrentDay( date ) elif weekly: span = "weekly" graphicType = "weekly" start, end = StatsDateLib.getStartEndFromCurrentWeek( date ) elif monthly: span = "monthly" graphicType = "monthly" start, end = StatsDateLib.getStartEndFromCurrentMonth( date ) elif yearly: span = "yearly" graphicType = "yearly" start, end = StatsDateLib.getStartEndFromCurrentYear( date ) timeSpan = int( StatsDateLib.getSecondsSinceEpoch( end ) - StatsDateLib.getSecondsSinceEpoch( start ) ) / 3600 else: #TODO fix span method??? if daily : timeSpan = 24 graphicType = "daily" span = "daily" elif weekly: timeSpan = 24 * 7 graphicType = "weekly" span = "weekly" elif monthly: timeSpan = 24 * 30 graphicType = "monthly" span = "monthly" elif yearly: timeSpan = 24 * 365 graphicType = "yearly" span = "yearly" start = StatsDateLib.getIsoFromEpoch( StatsDateLib.getSecondsSinceEpoch( date ) - timeSpan*60*60 ) end = date 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 includeGroups == True: configParameters = StatsConfigParameters() configParameters.getAllParameters() groups = configParameters.groupParameters.groups machinesToSearch = machines[:]#Forces a copy and nota reference. for machine in machines: if machinesAreClusters == True : machineConfig = MachineConfigParameters() machineConfig.getParametersFromMachineConfigurationFile() machinesAssociatedWith = machineConfig.getMachinesAssociatedWith( machine ) machinesToTest = str(machinesAssociatedWith).replace('[','').replace(']', '').replace(',','').replace( "'",'' ).replace('"','' ).\ replace(" ",'').replace('[','').replace(']', '').replace(',','').replace( "'",'' ).replace('"','' ).replace(" ",'') for group in groups: groupsMachine = str( configParameters.groupParameters.groupsMachines[group] ).replace('[','').replace(']', '').\ replace(',','').replace( "'",'' ).replace('"','' ).replace(" ",'') #print "machinesToTest %s groupsMachine %s" %(machinesToTest,groupsMachine ) if machinesToTest in groupsMachine : if groupsMachine not in machinesToSearch: machinesToSearch.append(groupsMachine) #print machines infos = _CsvInfos( start = start , end = end , span = span, timeSpan = timeSpan, fileType = fileType, machinesForLabels = machines,\ machinesToSearch = machinesToSearch, machinesAreClusters = machinesAreClusters, dataSource = "databases", outputLanguage = outputLanguage ) return infos
def getOptionsFromParser(parser): """ @summary: Parses and validates the options found in the parser. @return: If information was found to be valid, return options """ infos = None date = [] (options, args) = parser.parse_args() machines = options.machines.replace(' ', '').split(',') date = options.date.replace('"', '').replace("'", '') fileType = options.fileType.replace("'", '') daily = options.daily weekly = options.weekly monthly = options.monthly yearly = options.yearly fixedCurrent = options.fixedCurrent fixedPrevious = options.fixedPrevious turnOffLogging = options.turnOffLogging includeGroups = options.includeGroups machinesAreClusters = options.machinesAreClusters outputLanguage = options.outputLanguage 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() 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 == 0: print _("Error. Please use either the -d -m -w or -y options. ") 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() #TODO :fixStartEnd method??? if fixedPrevious: if daily: span = "daily" graphicType = "daily" start, end = StatsDateLib.getStartEndFromPreviousDay(date) elif weekly: span = "weekly" graphicType = "weekly" start, end = StatsDateLib.getStartEndFromPreviousWeek(date) elif monthly: span = "monthly" graphicType = "monthly" start, end = StatsDateLib.getStartEndFromPreviousMonth(date) elif yearly: span = "yearly" graphicType = "yearly" start, end = StatsDateLib.getStartEndFromPreviousYear(date) timeSpan = int( StatsDateLib.getSecondsSinceEpoch(end) - StatsDateLib.getSecondsSinceEpoch(start)) / 3600 elif fixedCurrent: if daily: span = "daily" graphicType = "daily" start, end = StatsDateLib.getStartEndFromCurrentDay(date) elif weekly: span = "weekly" graphicType = "weekly" start, end = StatsDateLib.getStartEndFromCurrentWeek(date) elif monthly: span = "monthly" graphicType = "monthly" start, end = StatsDateLib.getStartEndFromCurrentMonth(date) elif yearly: span = "yearly" graphicType = "yearly" start, end = StatsDateLib.getStartEndFromCurrentYear(date) timeSpan = int( StatsDateLib.getSecondsSinceEpoch(end) - StatsDateLib.getSecondsSinceEpoch(start)) / 3600 else: #TODO fix span method??? if daily: timeSpan = 24 graphicType = "daily" span = "daily" elif weekly: timeSpan = 24 * 7 graphicType = "weekly" span = "weekly" elif monthly: timeSpan = 24 * 30 graphicType = "monthly" span = "monthly" elif yearly: timeSpan = 24 * 365 graphicType = "yearly" span = "yearly" start = StatsDateLib.getIsoFromEpoch( StatsDateLib.getSecondsSinceEpoch(date) - timeSpan * 60 * 60) end = date 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 includeGroups == True: configParameters = StatsConfigParameters() configParameters.getAllParameters() groups = configParameters.groupParameters.groups machinesToSearch = machines[:] #Forces a copy and nota reference. for machine in machines: if machinesAreClusters == True: machineConfig = MachineConfigParameters() machineConfig.getParametersFromMachineConfigurationFile() machinesAssociatedWith = machineConfig.getMachinesAssociatedWith( machine) machinesToTest = str(machinesAssociatedWith).replace('[','').replace(']', '').replace(',','').replace( "'",'' ).replace('"','' ).\ replace(" ",'').replace('[','').replace(']', '').replace(',','').replace( "'",'' ).replace('"','' ).replace(" ",'') for group in groups: groupsMachine = str( configParameters.groupParameters.groupsMachines[group] ).replace('[','').replace(']', '').\ replace(',','').replace( "'",'' ).replace('"','' ).replace(" ",'') #print "machinesToTest %s groupsMachine %s" %(machinesToTest,groupsMachine ) if machinesToTest in groupsMachine: if groupsMachine not in machinesToSearch: machinesToSearch.append(groupsMachine) #print machines infos = _CsvInfos( start = start , end = end , span = span, timeSpan = timeSpan, fileType = fileType, machinesForLabels = machines,\ machinesToSearch = machinesToSearch, machinesAreClusters = machinesAreClusters, dataSource = "databases", outputLanguage = outputLanguage ) return infos