Show
Ignore:
Timestamp:
12/21/04 16:50:00 (19 years ago)
Author:
jalet
Message:

The dumpykota command now supports extended filtering capabilities with
the PostgreSQL backend. LDAP doesn't yet support such possibilities.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/dumpykota

    r1990 r1991  
    2424# 
    2525# $Log$ 
     26# Revision 1.17  2004/12/21 15:50:00  jalet 
     27# The dumpykota command now supports extended filtering capabilities with 
     28# the PostgreSQL backend. LDAP doesn't yet support such possibilities. 
     29# 
    2630# Revision 1.16  2004/12/21 14:45:31  jalet 
    2731# Prepared dumpykota to accept the new --filter command line option. Some 
     
    106110command line usage : 
    107111 
    108   dumpykota [options]  
     112  dumpykota [options] [filterexpr] 
    109113 
    110114options : 
     
    138142                         - xml : dump data as XML 
    139143                          
    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                           
    159144  -o | --output fname  All datas will be dumped to the file instead of 
    160145                       to the standard output. The special '-' filename 
    161146                       is the default value and means stdout. 
    162147                       WARNING : existing files are truncated ! 
     148                        
     149  Use the filter expressions to extract only parts of the  
     150  datas. Allowed filters are of the form : 
     151                 
     152         key=value 
     153                          
     154  Allowed keys for now are :   
     155                        
     156         username       User's name 
     157         groupname      Users group's name 
     158         printername    Printer's name 
     159         pgroupname     Printers group's name 
     160          
     161  Contrary to other PyKota management tools, wildcard characters are not  
     162  expanded, so you can't use them. 
     163   
     164  NB : not all keys are allowed for each data type, so the result may be  
     165  empty if you use a key not available for a particular data type. 
    163166   
    164167Examples : 
     
    173176  Dumps all users datas to the users.xml file. 
    174177   
    175   $ dumpykota --data history --filter printername=HP2100 
    176    
    177   Dumps the job history for printer HP2100 only. 
     178  $ dumpykota --data history printername=HP2100 username=jerome 
     179   
     180  Dumps the job history for user jerome on printer HP2100 only. 
    178181   
    179182This program is free software; you can redistribute it and/or modify 
     
    201204             
    202205        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 } 
     206        for filterexp in arguments : 
     207            if filterexp.strip() : 
     208                try : 
     209                    (filterkey, filtervalue) = [part.strip() for part in filterexp.split("=")] 
     210                    if filterkey not in [ "username", 
     211                                          "groupname", 
     212                                          "printername", 
     213                                          "pgroupname", 
     214                                        ] : 
     215                        raise ValueError                 
     216                except ValueError :     
     217                    raise PyKotaToolError, _("Invalid value [%s] for --filter command line option, see help.") % filterexp 
     218                else :     
     219                    extractonly.update({ filterkey : filtervalue }) 
    217220             
    218221        datatype = options["data"] 
     
    306309                     "output" : "-", \ 
    307310                   } 
    308         short_options = "vhd:f:o:F:" 
    309         long_options = ["help", "version", "data=", "format=", "output=", "filter="] 
     311        short_options = "vhd:f:o:" 
     312        long_options = ["help", "version", "data=", "format=", "output="] 
    310313         
    311314        # Initializes the command line tool 
     
    321324        options["format"] = options["f"] or options["format"] or defaults["format"] 
    322325        options["output"] = options["o"] or options["output"] or defaults["output"] 
    323         options["filter"] = options["F"] or options["filter"] 
    324326         
    325327        if options["help"] : 
     
    330332            raise PyKotaToolError, _("The -d | --data command line option is mandatory, see help.") 
    331333        else : 
    332             if args : 
    333                 raise PyKotaToolError, _("Too many arguments, see help.") 
    334334            retcode = dumper.main(args, options) 
    335335    except SystemExit :