Changeset 2782 for pykota/trunk
- Timestamp:
- 03/04/06 15:51:12 (19 years ago)
- Location:
- pykota/trunk
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/edpykota
r2772 r2782 28 28 import os 29 29 30 from pykota.tool import P yKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_30 from pykota.tool import Percent, PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 31 31 from pykota.config import PyKotaConfigError 32 32 from pykota.storage import PyKotaStorageError, StorageUserPQuota, StorageGroupPQuota … … 197 197 print 198 198 elif options["delete"] : 199 self.display("\n%s..." % _("Deletion"))199 percent = Percent(self, "\n%s..." % _("Deletion"), len(printers) * len(entries)) 200 200 getattr(self.storage, "deleteMany%sPQuotas" % suffix)(printers, entries) 201 self.display("\n")201 percent.display("\n") 202 202 else : 203 self.display("\n")204 203 skipexisting = options["skipexisting"] 205 204 used = options["used"] … … 253 252 try : 254 253 if options["add"] : 255 self.display("%s...\n" % _("Creation"))254 percent = Percent(self, "\n%s...\n" % _("Creation"), len(printers) * len(entries)) 256 255 dicnames = {} 257 256 for m in entries : … … 262 261 263 262 factory = globals()["Storage%sPQuota" % suffix] 264 nbtotal = len(printers) * len(entries)265 i = 0266 263 for printer in printers : 267 264 pname = printer.Name … … 285 282 hardreset, suffix, used) 286 283 oldpqentry.save() 287 i += 1 288 percent = 100.0 * float(i) / float(nbtotal) 289 self.display("\r%.02f%%" % percent) 284 percent.oneMore() 290 285 else : 291 nbtotal = len(entries) * len(printers) 292 if nbtotal : 293 self.display("%s...\n" % _("Modification")) 294 i = 0 295 for printer in printers : 296 for entry in entries : 297 pqkey = "%s@%s" % (entry.Name, printer.Name) 298 pqentry = getattr(self.storage, "get%sPQuota" % suffix)(entry, printer) 299 if pqentry.Exists : 300 self.modifyPQEntry(pqkey, pqentry, noquota, \ 301 softlimit, hardlimit, \ 302 increase, reset, \ 303 hardreset, suffix, used) 304 pqentry.save() 305 i += 1 306 percent = 100.0 * float(i) / float(nbtotal) 307 self.display("\r%.02f%%" % percent) 286 percent = Percent(self, "\n%s...\n" % _("Modification"), len(entries) * len(printers)) 287 for printer in printers : 288 for entry in entries : 289 pqkey = "%s@%s" % (entry.Name, printer.Name) 290 pqentry = getattr(self.storage, "get%sPQuota" % suffix)(entry, printer) 291 if pqentry.Exists : 292 self.modifyPQEntry(pqkey, pqentry, noquota, \ 293 softlimit, hardlimit, \ 294 increase, reset, \ 295 hardreset, suffix, used) 296 pqentry.save() 297 percent.oneMore() 308 298 except : 309 299 self.storage.rollbackTransaction() … … 312 302 self.storage.commitTransaction() 313 303 314 if not options["list"] : 315 self.done() 304 try : 305 percent.done() 306 except NameError : 307 pass 316 308 317 309 if __name__ == "__main__" : -
pykota/trunk/bin/pkbcodes
r2770 r2782 29 29 import pwd 30 30 31 from pykota.tool import P yKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_31 from pykota.tool import Percent, PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 32 32 from pykota.storage import StorageBillingCode 33 33 … … 116 116 _("credits")) 117 117 elif options["delete"] : 118 self.display("\n%s..." % _("Deletion"))118 percent = Percent(self, "\n%s..." % _("Deletion"), len(billingcodes)) 119 119 self.storage.deleteManyBillingCodes(billingcodes) 120 self.display("\n")120 percent.display("\n") 121 121 else : 122 122 reset = options["reset"] … … 129 129 try : 130 130 if options["add"] : 131 self.display("%s...\n" % _("Creation")) 132 nbtotal = len(names) 133 for i in range(nbtotal) : 134 bname = names[i] 131 percent = Percent(self, "%s...\n" % _("Creation"), len(names)) 132 for bname in names : 135 133 billingcode = StorageBillingCode(self.storage, bname) 136 134 self.modifyBillingCode(billingcode, reset, description) … … 143 141 self.modifyBillingCode(oldbillingcode, reset, description) 144 142 oldbillingcode.save() 145 percent = 100.0 * float(i) / float(nbtotal) 146 self.display("\r%.02f%%" % percent) 143 percent.oneMore() 147 144 else : 148 self.display("\n%s...\n" % _("Modification")) 149 nbtotal = len(billingcodes) 150 for i in range(nbtotal) : 151 billingcode = billingcodes[i] 145 percent = Percent(self, "\n%s...\n" % _("Modification"), len(billingcodes)) 146 for billingcode in billingcodes : 152 147 self.modifyBillingCode(billingcode, reset, description) 153 148 billingcode.save() 154 percent = 100.0 * float(i) / float(nbtotal) 155 self.display("\r%.02f%%" % percent) 149 percent.oneMore() 156 150 except : 157 151 self.storage.rollbackTransaction() … … 160 154 self.storage.commitTransaction() 161 155 162 if not options["list"] : 163 self.done() 156 try : 157 percent.done() 158 except NameError : 159 pass 164 160 165 161 if __name__ == "__main__" : -
pykota/trunk/bin/pkprinters
r2770 r2782 29 29 import pwd 30 30 31 from pykota.tool import P yKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_31 from pykota.tool import Percent, PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 32 32 from pykota.storage import StoragePrinter 33 33 … … 171 171 print 172 172 elif options["delete"] : 173 self.display("\n%s..." % _("Deletion"))173 percent = Percent(self, "\n%s..." % _("Deletion"), len(printers)) 174 174 self.storage.deleteManyPrinters(printers) 175 self.display("\n")175 percent.display("\n") 176 176 else : 177 177 if options["groups"] : … … 217 217 try : 218 218 if options["add"] : 219 self.display("%s...\n" % _("Creation")) 220 nbtotal = len(names) 221 for i in range(nbtotal) : 222 pname = names[i] 219 percent = Percent(self, "%s...\n" % _("Creation"), len(names)) 220 for pname in names : 223 221 if self.isValidName(pname) : 224 222 printer = StoragePrinter(self.storage, pname) … … 244 242 else : 245 243 raise PyKotaCommandLineError, _("Invalid printer name %s") % pname 246 percent = 100.0 * float(i) / float(nbtotal) 247 self.display("\r%.02f%%" % percent) 244 percent.oneMore() 248 245 else : 249 self.display("\n%s...\n" % _("Modification")) 250 nbtotal = len(printers) 251 for i in range(nbtotal) : 252 printer = printers[i] 246 percent = Percent(self, "\n%s...\n" % _("Modification"), len(printers)) 247 for printer in printers : 253 248 self.modifyPrinter(printer, charges, perpage, perjob, \ 254 249 description, passthrough, \ … … 256 251 printer.save() 257 252 self.managePrintersGroups(printersgroups, printer, remove) 258 percent = 100.0 * float(i) / float(nbtotal) 259 self.display("\r%.02f%%" % percent) 253 percent.oneMore() 260 254 except : 261 255 self.storage.rollbackTransaction() … … 263 257 else : 264 258 self.storage.commitTransaction() 265 if not options["list"] : 266 self.done() 259 260 try : 261 percent.done() 262 except NameError : 263 pass 267 264 268 265 if __name__ == "__main__" : -
pykota/trunk/bin/pkusers
r2774 r2782 30 30 import grp 31 31 32 from pykota.tool import P yKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_32 from pykota.tool import Percent, PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 33 33 from pykota.storage import StorageUser, StorageGroup 34 34 … … 235 235 print 236 236 elif options["delete"] : 237 self.display("\n%s..." % _("Deletion"))237 percent = Percent(self, "\n%s..." % _("Deletion"), len(entries)) 238 238 getattr(self.storage, "deleteMany%ss" % suffix)(entries) 239 self.display("\n")239 percent.display("\n") 240 240 else : 241 241 limitby = options["limitby"] … … 286 286 try : 287 287 if options["add"] : 288 self.display("%s...\n" % _("Creation"))289 288 rejectunknown = self.config.getRejectUnknown() 290 nbtotal = len(names) 291 for i in range(nbtotal) : 292 ename = names[i] 289 percent = Percent(self, "%s...\n" % _("Creation"), len(names)) 290 for ename in names : 293 291 email = None 294 292 if not groups : … … 347 345 else : 348 346 raise PyKotaCommandLineError, _("Invalid name %s") % ename 349 percent = 100.0 * float(i) / float(nbtotal) 350 self.display("\r%.02f%%" % percent) 347 percent.oneMore() 351 348 else : 352 self.display("\n%s...\n" % _("Modification")) 353 nbtotal = len(entries) 354 for i in range(nbtotal) : 355 entry = entries[i] 349 percent = Percent(self, "\n%s...\n" % _("Modification"), len(entries)) 350 for entry in entries : 356 351 if groups : 357 352 self.modifyEntry(entry, groups, limitby, description) … … 362 357 self.manageUsersGroups(usersgroups, entry, remove) 363 358 entry.save() 364 percent = 100.0 * float(i) / float(nbtotal) 365 self.display("\r%.02f%%" % percent) 359 percent.oneMore() 366 360 except : 367 361 self.storage.rollbackTransaction() … … 369 363 else : 370 364 self.storage.commitTransaction() 371 372 if not options["list"] : 373 self.done() 365 366 try : 367 percent.done() 368 except NameError : 369 pass 374 370 375 371 if __name__ == "__main__" : -
pykota/trunk/pykota/tool.py
r2765 r2782 78 78 return msg 79 79 80 class Percent : 81 """A class to display progress.""" 82 def __init__(self, app, title, size) : 83 """Initializes the engine.""" 84 self.app = app 85 self.size = size 86 self.number = 0 87 self.factor = 100.0 / float(size) 88 self.previous = None 89 self.display(title) 90 91 def display(self, msg) : 92 """Displays the value.""" 93 self.app.display(msg) 94 95 def oneMore(self) : 96 """Increments internal counter.""" 97 self.number += 1 98 percent = "%.02f" % (float(self.number) * self.factor) 99 if percent != self.previous : # optimize for large number of items 100 self.display("\r%s%%" % percent) 101 self.previous = percent 102 103 def done(self) : 104 """Displays the 'done' message.""" 105 self.display("\r100.00%%\r \r%s\n" % _("Done.")) 106 80 107 class Tool : 81 108 """Base class for tools with no database access.""" … … 201 228 sys.stdout.flush() 202 229 203 def done(self) :204 """Displays the 'done' message."""205 self.display("\r100.00%%\r \r%s\n" % _("Done."))206 207 230 def logdebug(self, message) : 208 231 """Logs something to debug output if debug is enabled."""