Changeset 1991 for pykota/trunk/bin/dumpykota
- Timestamp:
- 12/21/04 16:50:00 (19 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/dumpykota
r1990 r1991 24 24 # 25 25 # $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 # 26 30 # Revision 1.16 2004/12/21 14:45:31 jalet 27 31 # Prepared dumpykota to accept the new --filter command line option. Some … … 106 110 command line usage : 107 111 108 dumpykota [options] 112 dumpykota [options] [filterexpr] 109 113 110 114 options : … … 138 142 - xml : dump data as XML 139 143 140 -F - | --filter exp Uses the filter to extract only parts of the141 datas. Allowed filters are of the form :142 143 key=value144 145 Allowed keys for now are :146 147 username User's name148 groupname Users group's name149 printername Printer's name150 pgroupname Printers group's name151 152 Contrary to other PyKota management tools, wildcard153 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 not157 available for a particular data type.158 159 144 -o | --output fname All datas will be dumped to the file instead of 160 145 to the standard output. The special '-' filename 161 146 is the default value and means stdout. 162 147 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. 163 166 164 167 Examples : … … 173 176 Dumps all users datas to the users.xml file. 174 177 175 $ dumpykota --data history --filter printername=HP2100176 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. 178 181 179 182 This program is free software; you can redistribute it and/or modify … … 201 204 202 205 extractonly = {} 203 f ilterexp = 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 ValueError213 except ValueError :214 raise PyKotaToolError, _("Invalid value [%s] for --filter command line option, see help.") % filterexp215 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 }) 217 220 218 221 datatype = options["data"] … … 306 309 "output" : "-", \ 307 310 } 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="] 310 313 311 314 # Initializes the command line tool … … 321 324 options["format"] = options["f"] or options["format"] or defaults["format"] 322 325 options["output"] = options["o"] or options["output"] or defaults["output"] 323 options["filter"] = options["F"] or options["filter"]324 326 325 327 if options["help"] : … … 330 332 raise PyKotaToolError, _("The -d | --data command line option is mandatory, see help.") 331 333 else : 332 if args :333 raise PyKotaToolError, _("Too many arguments, see help.")334 334 retcode = dumper.main(args, options) 335 335 except SystemExit :