Changeset 1717
- Timestamp:
- 09/15/04 00:29:13 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 7 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 -
pykota/trunk/MANIFEST.in
r1668 r1717 1 include README FAQ COPYING LICENSE TODO NEWS CREDITS SECURITY MANIFEST.in clean.sh bin/ lprngpykota bin/cupspykota bin/edpykota bin/warnpykota bin/repykota bin/pykotme bin/pykosd bin/pkprinters bin/pkhint bin/pkpgcounter bin/snmpprinterstatus bin/waitprinter.sh bin/papwaitprinter.sh bin/mailandpopup.sh bin/README1 include README FAQ COPYING LICENSE TODO NEWS CREDITS SECURITY MANIFEST.in clean.sh bin/dumpykota bin/lprngpykota bin/cupspykota bin/edpykota bin/warnpykota bin/repykota bin/pykotme bin/pykosd bin/pkprinters bin/pkhint bin/pkpgcounter bin/snmpprinterstatus bin/waitprinter.sh bin/papwaitprinter.sh bin/mailandpopup.sh bin/README 2 2 recursive-include po README *.sh *.po *.mo *.pot 3 3 recursive-include man README *.sh *.1 -
pykota/trunk/NEWS
r1713 r1717 22 22 PyKota NEWS : 23 23 24 - 1.20alpha11 : 25 26 - Generic data dumper 'dumpykota' introduced. 27 Works only with PostgreSQL backend for now. 28 24 29 - 1.20alpha10 : 25 30 -
pykota/trunk/pykota/storages/pgstorage.py
r1520 r1717 22 22 # 23 23 # $Log$ 24 # Revision 1.37 2004/09/14 22:29:12 jalet 25 # First version of dumpykota. Works fine but only with PostgreSQL backend 26 # for now. 27 # 24 28 # Revision 1.36 2004/06/03 23:14:11 jalet 25 29 # Now stores the job's size in bytes in the database. … … 196 200 self.tool.logdebug("Transaction aborted.") 197 201 198 def do Search(self, query) :199 """Does a search query."""202 def doRawSearch(self, query) : 203 """Does a raw search query.""" 200 204 query = query.strip() 201 205 if not query.endswith(';') : … … 207 211 raise PyKotaStorageError, msg 208 212 else : 209 if (result is not None) and (result.ntuples() > 0) : 210 return result.dictresult() 213 return result 211 214 215 def doSearch(self, query) : 216 """Does a search query.""" 217 result = self.doRawSearch(query) 218 if (result is not None) and (result.ntuples() > 0) : 219 return result.dictresult() 220 212 221 def doModify(self, query) : 213 222 """Does a (possibly multiple) modify query.""" -
pykota/trunk/pykota/storages/sql.py
r1711 r1717 22 22 # 23 23 # $Log$ 24 # Revision 1.45 2004/09/14 22:29:13 jalet 25 # First version of dumpykota. Works fine but only with PostgreSQL backend 26 # for now. 27 # 24 28 # Revision 1.44 2004/09/10 21:32:54 jalet 25 29 # Small fixes for incomplete entry intialization … … 65 69 66 70 class SQLStorage : 71 def prepareRawResult(self, result) : 72 """Prepares a raw result by including the headers.""" 73 if result.ntuples() > 0 : 74 entries = [result.listfields()] 75 entries.extend(result.getresult()) 76 return entries 77 78 def extractPrinters(self) : 79 """Extracts all printer records.""" 80 result = self.doRawSearch("SELECT * FROM printers") 81 return self.prepareRawResult(result) 82 83 def extractUsers(self) : 84 """Extracts all user records.""" 85 result = self.doRawSearch("SELECT * FROM users") 86 return self.prepareRawResult(result) 87 88 def extractGroups(self) : 89 """Extracts all group records.""" 90 result = self.doRawSearch("SELECT * FROM groups") 91 return self.prepareRawResult(result) 92 93 def extractPayments(self) : 94 """Extracts all payment records.""" 95 result = self.doRawSearch("SELECT username,payments.* FROM users,payments WHERE users.id=payments.userid") 96 return self.prepareRawResult(result) 97 98 def extractUpquotas(self) : 99 """Extracts all userpquota records.""" 100 result = self.doRawSearch("SELECT users.username,printers.printername,userpquota.* FROM users,printers,userpquota WHERE users.id=userpquota.userid AND printers.id=userpquota.printerid") 101 return self.prepareRawResult(result) 102 103 def extractGpquotas(self) : 104 """Extracts all grouppquota records.""" 105 result = self.doRawSearch("SELECT groups.groupname,printers.printername,grouppquota.* FROM groups,printers,grouppquota WHERE groups.id=grouppquota.groupid AND printers.id=grouppquota.printerid") 106 return self.prepareRawResult(result) 107 108 def extractHistory(self) : 109 """Extracts all jobhistory records.""" 110 result = self.doRawSearch("SELECT users.username,printers.printername,jobhistory.* FROM users,printers,jobhistory WHERE users.id=jobhistory.userid AND printers.id=jobhistory.printerid") 111 return self.prepareRawResult(result) 112 67 113 def getAllUsersNames(self) : 68 114 """Extracts all user names.""" -
pykota/trunk/pykota/version.py
r1713 r1717 22 22 # 23 23 24 __version__ = "1.20alpha1 0_unofficial"24 __version__ = "1.20alpha11_unofficial" 25 25 26 26 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng.""" -
pykota/trunk/setup.py
r1658 r1717 24 24 # 25 25 # $Log$ 26 # Revision 1.50 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.49 2004/07/28 13:00:02 jalet 27 31 # Now takes care of .sxi and .sxc files if any … … 473 477 url = "http://www.librelogiciel.com/software/", 474 478 packages = [ "pykota", "pykota.storages", "pykota.loggers", "pykota.accounters", "pykota.reporters" ], 475 scripts = [ "bin/ pkpgcounter", "bin/snmpprinterstatus", "bin/pykosd", "bin/edpykota", "bin/repykota", "bin/warnpykota", "bin/pykotme", "bin/pkprinters", "bin/pkhint" ],479 scripts = [ "bin/dumpykota", "bin/pkpgcounter", "bin/snmpprinterstatus", "bin/pykosd", "bin/edpykota", "bin/repykota", "bin/warnpykota", "bin/pykotme", "bin/pkprinters", "bin/pkhint" ], 476 480 data_files = data_files) 477 481