Changeset 1717 for pykota/trunk/bin
- Timestamp:
- 09/15/04 00:29:13 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/dumpykota
r1583 r1717 24 24 # 25 25 # $Log$ 26 # Revision 1.2 2004/09/14 22:29:12 jalet 27 # First version of dumpykota. Works fine but only with PostgreSQL backend 28 # for now. 29 # 26 30 # Revision 1.1 2004/07/01 19:22:37 jalet 27 31 # First draft of dumpykota … … 52 56 -h | --help Prints this message then exits. 53 57 54 -d | --data type Dumps 'type' datas. When not specified, the 55 default is to dump the jobs history data. 56 Allowed types are : 58 -d | --data type Dumps 'type' datas. Allowed types are : 57 59 58 60 - history : dumps the jobs history. … … 62 64 - uquotas : dump user quotas. 63 65 - gquotas : dump user groups quotas. 66 - payments : dumps user payments. 67 68 NB : the -d | --data command line option 69 is MANDATORY. 64 70 65 71 -f | --format fmt Dumps datas in the 'fmt' format. When not specified, … … 72 78 - tsv : separate datas with tabs 73 79 74 -p | --printer p Only dumps datas concerning printer 'p'.75 Actually 'p' can use wildcards characters to select76 only some printers. The default value is *, meaning77 all printers.78 You can specify several names or wildcards,79 by separating them with commas.80 81 -u | --user u Only dumps datas concerning user 'u'.82 Actually 'u' can use wildcards characters to select83 only some users. The default value is *, meaning84 all users.85 You can specify several names or wildcards,86 by separating them with commas.87 88 -g | --group g Only dumps datas concerning group 'g'.89 Actually 'g' can use wildcards characters to select90 only some groups. The default value is *, meaning91 all groups.92 You can specify several names or wildcards,93 by separating them with commas.94 95 If launched by a non-root user, additionnal arguments representing96 users or groups names are ignored, and only the current user/group97 is reported.98 99 80 This program is free software; you can redistribute it and/or modify 100 81 it under the terms of the GNU General Public License as published by … … 115 96 class DumPyKota(PyKotaTool) : 116 97 """A class for dumpykota.""" 117 def main(self, ugnames, options) :98 def main(self, arguments, options) : 118 99 """Print Quota Data Dumper.""" 119 uid = os.geteuid() 120 if not uid : 121 # root user 122 if not ugnames : 123 # no username, means all usernames 124 ugnames = [ "*" ] 125 else : 126 # not the root user 127 # reports only the current user 128 username = pwd.getpwuid(uid)[0] 129 if options["data"] == "groups" : 130 user = self.storage.getUser(username) 131 if user.Exists : 132 ugnames = [ g.Name for g in self.storage.getUserGroups(user) ] 133 else : 134 ugnames = [ ] 135 else : 136 ugnames = [ username ] 100 datatype = options["data"] 101 if datatype not in [ "history", 102 "users", 103 "groups", 104 "printers", 105 "upquotas", 106 "gpquotas", 107 "payments", 108 ] : 109 raise PyKotaToolError, _("Invalid modifier [%s] for --data command line option, see help.") % datatype 110 111 format = options["format"] 112 if format not in [ "csv", 113 "ssv", 114 "tsv", 115 ] : 116 raise PyKotaToolError, _("Invalid modifier [%s] for --format command line option, see help.") % datatype 117 118 entries = getattr(self.storage, "extract%s" % datatype.title())() 119 getattr(self, "dump%s" % format.title())(entries) 120 return 0 137 121 138 printers = self.storage.getMatchingPrinters(options["printer"]) 139 if not printers : 140 raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] 141 142 # TODO : insert code here ! 143 raise PyKotaToolError, "Not implemented" 144 122 def dumpWithSeparator(self, separator, entries) : 123 """Dumps datas with a separator.""" 124 for entry in entries : 125 line = separator.join([ '"%s"' % field for field in entry ]) 126 print line 127 128 def dumpCsv(self, entries) : 129 """Dumps datas with a comma as the separator.""" 130 self.dumpWithSeparator(",", entries) 131 132 def dumpSsv(self, entries) : 133 """Dumps datas with a comma as the separator.""" 134 self.dumpWithSeparator(";", entries) 135 136 def dumpTsv(self, entries) : 137 """Dumps datas with a comma as the separator.""" 138 self.dumpWithSeparator("\t", entries) 139 145 140 if __name__ == "__main__" : 146 141 try : 147 142 defaults = { \ 148 " printer" : "*", \143 "format" : "csv", \ 149 144 } 150 short_options = "vhd:f: p:u:g:"151 long_options = ["help", "version", "data=", "format=" , "printer=", "user=", "group="]145 short_options = "vhd:f:" 146 long_options = ["help", "version", "data=", "format="] 152 147 153 148 # Initializes the command line tool … … 160 155 options["help"] = options["h"] or options["help"] 161 156 options["version"] = options["v"] or options["version"] 162 options["users"] = options["u"] or options["users"] 163 options["groups"] = options["g"] or options["groups"] 164 options["printer"] = options["P"] or options["printer"] or defaults["printer"] 157 options["data"] = options["d"] or options["data"] 158 options["format"] = options["f"] or options["format"] or defaults["format"] 165 159 166 160 if options["help"] : … … 168 162 elif options["version"] : 169 163 dumper.display_version_and_quit() 170 elif options[" users"] and options["groups"]:171 raise PyKotaToolError, _(" incompatible options, see help.")164 elif options["data"] is None : 165 raise PyKotaToolError, _("The -d | --data command line option is mandatory, see help.") 172 166 else : 167 if args : 168 raise PyKotaToolError, _("Too many arguments, see help.") 173 169 retcode = dumper.main(args, options) 174 170 except SystemExit : … … 176 172 except : 177 173 try : 178 dumper.crashed(" repykota failed")174 dumper.crashed("dumpykota failed") 179 175 except : 180 176 pass