Changeset 1990 for pykota/trunk/bin
- Timestamp:
- 12/21/04 15:45:31 (19 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/dumpykota
r1809 r1990 24 24 # 25 25 # $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 # 26 30 # Revision 1.15 2004/10/12 15:37:00 jalet 27 31 # Now outputs the name of the offending user if a mere mortal tries to use … … 134 138 - xml : dump data as XML 135 139 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 136 159 -o | --output fname All datas will be dumped to the file instead of 137 160 to the standard output. The special '-' filename … … 149 172 150 173 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. 151 178 152 179 This program is free software; you can redistribute it and/or modify … … 172 199 if not self.config.isAdmin : 173 200 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 } 174 217 175 218 datatype = options["data"] … … 197 240 raise PyKotaToolError, _("XML output is disabled because the jaxml module is not available.") 198 241 199 entries = getattr(self.storage, "extract%s" % datatype.title())( )242 entries = getattr(self.storage, "extract%s" % datatype.title())(extractonly) 200 243 if entries : 201 244 mustclose = 0 … … 263 306 "output" : "-", \ 264 307 } 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="] 267 310 268 311 # Initializes the command line tool … … 278 321 options["format"] = options["f"] or options["format"] or defaults["format"] 279 322 options["output"] = options["o"] or options["output"] or defaults["output"] 323 options["filter"] = options["F"] or options["filter"] 280 324 281 325 if options["help"] :