Changeset 1990 for pykota/trunk/bin

Show
Ignore:
Timestamp:
12/21/04 15:45:31 (19 years ago)
Author:
jalet
Message:

Prepared dumpykota to accept the new --filter command line option. Some
additionnal work needs to be done in the backends though.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/dumpykota

    r1809 r1990  
    2424# 
    2525# $Log$ 
     26# Revision 1.16  2004/12/21 14:45:31  jalet 
     27# Prepared dumpykota to accept the new --filter command line option. Some 
     28# additionnal work needs to be done in the backends though. 
     29# 
    2630# Revision 1.15  2004/10/12 15:37:00  jalet 
    2731# Now outputs the name of the offending user if a mere mortal tries to use 
     
    134138                         - xml : dump data as XML 
    135139                          
     140  -F - | --filter exp  Uses the filter to extract only parts of the                           
     141                       datas. Allowed filters are of the form : 
     142                        
     143                         key=value 
     144                          
     145                       Allowed keys for now are :   
     146                        
     147                         username       User's name 
     148                         groupname      Users group's name 
     149                         printername    Printer's name 
     150                         pgroupname     Printers group's name 
     151                          
     152                       Contrary to other PyKota management tools, wildcard 
     153                       characters are not expanded, so you can't use them. 
     154                          
     155                       NB : not all keys are allowed for each data type, 
     156                       so the result may be empty if you use a key not 
     157                       available for a particular data type. 
     158                          
    136159  -o | --output fname  All datas will be dumped to the file instead of 
    137160                       to the standard output. The special '-' filename 
     
    149172   
    150173  Dumps all users datas to the users.xml file. 
     174   
     175  $ dumpykota --data history --filter printername=HP2100 
     176   
     177  Dumps the job history for printer HP2100 only. 
    151178   
    152179This program is free software; you can redistribute it and/or modify 
     
    172199        if not self.config.isAdmin : 
    173200            raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
     201             
     202        extractonly = {} 
     203        filterexp = options["filter"]     
     204        if filterexp : 
     205            try : 
     206                (filterkey, filtervalue) = [part.strip() for part in filterexp.split("=")] 
     207                if filterkey not in [ "username", 
     208                                      "groupname", 
     209                                      "printername", 
     210                                      "pgroupname", 
     211                                    ] : 
     212                    raise ValueError                 
     213            except ValueError :     
     214                raise PyKotaToolError, _("Invalid value [%s] for --filter command line option, see help.") % filterexp 
     215            else :     
     216                extractonly = { filterkey : filtervalue } 
    174217             
    175218        datatype = options["data"] 
     
    197240            raise PyKotaToolError, _("XML output is disabled because the jaxml module is not available.") 
    198241             
    199         entries = getattr(self.storage, "extract%s" % datatype.title())()     
     242        entries = getattr(self.storage, "extract%s" % datatype.title())(extractonly)     
    200243        if entries : 
    201244            mustclose = 0     
     
    263306                     "output" : "-", \ 
    264307                   } 
    265         short_options = "vhd:f:o:" 
    266         long_options = ["help", "version", "data=", "format=", "output="] 
     308        short_options = "vhd:f:o:F:" 
     309        long_options = ["help", "version", "data=", "format=", "output=", "filter="] 
    267310         
    268311        # Initializes the command line tool 
     
    278321        options["format"] = options["f"] or options["format"] or defaults["format"] 
    279322        options["output"] = options["o"] or options["output"] or defaults["output"] 
     323        options["filter"] = options["F"] or options["filter"] 
    280324         
    281325        if options["help"] :