示例#1
0
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 
示例#2
0
    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)
示例#3
0
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
示例#4
0
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     
示例#5
0
    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 )
示例#6
0
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