Changeset 2783 for pykota/trunk
- Timestamp:
- 03/05/06 09:36:47 (19 years ago)
- Location:
- pykota/trunk
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/edpykota
r2782 r2783 177 177 178 178 if not options["list"] : 179 self.display(_("Extracting datas...")) 179 percent = Percent(self) 180 percent.display(_("Extracting datas...")) 180 181 printers = self.storage.getMatchingPrinters(options["printer"]) 181 182 entries = getattr(self.storage, "getMatching%ss" % suffix)(",".join(names)) 183 if not options["list"] : 184 percent.setSize(len(printers) * len(entries)) 182 185 183 186 if options["list"] : … … 197 200 print 198 201 elif options["delete"] : 199 percent = Percent(self, "\n%s..." % _("Deletion"), len(printers) * len(entries))202 percent.display("\n%s..." % _("Deletion")) 200 203 getattr(self.storage, "deleteMany%sPQuotas" % suffix)(printers, entries) 201 204 percent.display("\n") … … 252 255 try : 253 256 if options["add"] : 254 percent = Percent(self, "\n%s...\n" % _("Creation"), len(printers) * len(entries))257 percent.display("\n%s...\n" % _("Creation")) 255 258 dicnames = {} 256 259 for m in entries : … … 284 287 percent.oneMore() 285 288 else : 286 percent = Percent(self, "\n%s...\n" % _("Modification"), len(entries) * len(printers))289 percent.display("\n%s...\n" % _("Modification")) 287 290 for printer in printers : 288 291 for entry in entries : … … 302 305 self.storage.commitTransaction() 303 306 304 try:307 if not options["list"] : 305 308 percent.done() 306 except NameError :307 pass308 309 309 310 if __name__ == "__main__" : -
pykota/trunk/bin/pkbcodes
r2782 r2783 97 97 raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 98 98 99 if not options["list"] : 100 percent = Percent(self) 101 99 102 if not options["add"] : 100 103 if not options["list"] : 101 self.display(_("Extracting datas..."))104 percent.display(_("Extracting datas...")) 102 105 if not names : # NB : can't happen for --delete because it's catched earlier 103 106 names = ["*"] … … 105 108 if not billingcodes : 106 109 raise PyKotaCommandLineError, _("There's no billingcode matching %s") % " ".join(names) 110 if not options["list"] : 111 percent.setSize(len(billingcodes)) 107 112 108 113 if options["list"] : … … 116 121 _("credits")) 117 122 elif options["delete"] : 118 percent = Percent(self, "\n%s..." % _("Deletion"), len(billingcodes))123 percent.display("\n%s..." % _("Deletion")) 119 124 self.storage.deleteManyBillingCodes(billingcodes) 120 125 percent.display("\n") … … 129 134 try : 130 135 if options["add"] : 131 percent = Percent(self, "%s...\n" % _("Creation"), len(names)) 136 percent.display("%s...\n" % _("Creation")) 137 percent.setSize(len(names)) 132 138 for bname in names : 133 139 billingcode = StorageBillingCode(self.storage, bname) … … 143 149 percent.oneMore() 144 150 else : 145 percent = Percent(self, "\n%s...\n" % _("Modification"), len(billingcodes))151 percent.display("\n%s...\n" % _("Modification")) 146 152 for billingcode in billingcodes : 147 153 self.modifyBillingCode(billingcode, reset, description) … … 154 160 self.storage.commitTransaction() 155 161 156 try:162 if not options["list"] : 157 163 percent.done() 158 except NameError :159 pass160 164 161 165 if __name__ == "__main__" : -
pykota/trunk/bin/pkprinters
r2782 r2783 150 150 raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 151 151 152 if not options["list"] : 153 percent = Percent(self) 154 152 155 if not options["add"] : 153 156 if not options["list"] : 154 self.display(_("Extracting datas..."))157 percent.display(_("Extracting datas...")) 155 158 if not names : # NB : can't happen for --delete because it's catched earlier 156 159 names = ["*"] … … 158 161 if not printers : 159 162 raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(names) 163 if not options["list"] : 164 percent.setSize(len(printers)) 160 165 161 166 if options["list"] : … … 171 176 print 172 177 elif options["delete"] : 173 percent = Percent(self, "\n%s..." % _("Deletion"), len(printers))178 percent.display("\n%s..." % _("Deletion")) 174 179 self.storage.deleteManyPrinters(printers) 175 180 percent.display("\n") … … 217 222 try : 218 223 if options["add"] : 219 percent = Percent(self, "%s...\n" % _("Creation"), len(names)) 224 percent.display("%s...\n" % _("Creation")) 225 percent.setSize(len(names)) 220 226 for pname in names : 221 227 if self.isValidName(pname) : … … 244 250 percent.oneMore() 245 251 else : 246 percent = Percent(self, "\n%s...\n" % _("Modification"), len(printers))252 percent.display("\n%s...\n" % _("Modification")) 247 253 for printer in printers : 248 254 self.modifyPrinter(printer, charges, perpage, perjob, \ … … 258 264 self.storage.commitTransaction() 259 265 260 try:266 if not options["list"] : 261 267 percent.done() 262 except NameError :263 pass264 268 265 269 if __name__ == "__main__" : -
pykota/trunk/bin/pkusers
r2782 r2783 193 193 suffix = (options["groups"] and "Group") or "User" 194 194 195 if not options["list"] : 196 percent = Percent(self) 197 195 198 if not options["add"] : 196 199 if not options["list"] : 197 self.display(_("Extracting datas..."))200 percent.display(_("Extracting datas...")) 198 201 if not names : # NB : can't happen for --delete because it's catched earlier 199 202 names = ["*"] … … 201 204 if not entries : 202 205 raise PyKotaCommandLineError, _("There's no %s matching %s") % (_(suffix.lower()), " ".join(names)) 206 if not options["list"] : 207 percent.setSize(len(entries)) 203 208 204 209 if options["list"] : … … 235 240 print 236 241 elif options["delete"] : 237 percent = Percent(self, "\n%s..." % _("Deletion"), len(entries))242 percent.display("\n%s..." % _("Deletion")) 238 243 getattr(self.storage, "deleteMany%ss" % suffix)(entries) 239 244 percent.display("\n") … … 287 292 if options["add"] : 288 293 rejectunknown = self.config.getRejectUnknown() 289 percent = Percent(self, "%s...\n" % _("Creation"), len(names)) 294 percent.display("%s...\n" % _("Creation")) 295 percent.setSize(len(names)) 290 296 for ename in names : 291 297 email = None … … 347 353 percent.oneMore() 348 354 else : 349 percent = Percent(self, "\n%s...\n" % _("Modification"), len(entries))355 percent.display("\n%s...\n" % _("Modification")) 350 356 for entry in entries : 351 357 if groups : … … 364 370 self.storage.commitTransaction() 365 371 366 try:372 if not options["list"] : 367 373 percent.done() 368 except NameError :369 pass370 374 371 375 if __name__ == "__main__" : -
pykota/trunk/pykota/tool.py
r2782 r2783 35 35 import tempfile 36 36 import md5 37 import time 37 38 import ConfigParser 38 39 import popen2 … … 80 81 class Percent : 81 82 """A class to display progress.""" 82 def __init__(self, app, title, size) :83 def __init__(self, app, size=None) : 83 84 """Initializes the engine.""" 84 85 self.app = app 86 self.size = None 87 if size : 88 self.setSize(size) 89 self.previous = None 90 self.before = time.time() 91 92 def setSize(self, size) : 93 """Sets the total size.""" 94 self.number = 0 85 95 self.size = size 86 self.number = 087 96 self.factor = 100.0 / float(size) 88 self.previous = None89 self.display(title)90 97 91 98 def display(self, msg) : … … 95 102 def oneMore(self) : 96 103 """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 104 if self.size : 105 self.number += 1 106 percent = "%.02f" % (float(self.number) * self.factor) 107 if percent != self.previous : # optimize for large number of items 108 self.display("\r%s%%" % percent) 109 self.previous = percent 102 110 103 111 def done(self) : 104 112 """Displays the 'done' message.""" 105 self.display("\r100.00%%\r \r%s\n" % _("Done.")) 113 after = time.time() 114 if self.size : 115 speed = int(self.size / (after - self.before)) 116 self.display("\r100.00%%\r \r%s. %s : %i %s.\n" \ 117 % (_("Done"), _("Average speed"), speed, _("entries per second"))) 118 else : 119 self.display("\r100.00%%\r \r%s.\n" % _("Done")) 106 120 107 121 class Tool : -
pykota/trunk/tests/filldb.py
r2773 r2783 7 7 import sys 8 8 import os 9 import time10 9 11 def showTiming(number, before) :12 """Displays timing information."""13 elapsed = time.time() - before14 persecond = int(float(number) / elapsed)15 sys.stdout.write("\nTime elapsed : %.2f seconds (%i entries per second)\n\n" % (elapsed, persecond))16 17 10 def createBillingCodes(number) : 18 11 """Creates a number of billing codes.""" … … 24 17 argsfile.write("%s\n" % bname) 25 18 argsfile.close() 26 before = time.time()27 19 os.system('pkbcodes --arguments arguments.list') 28 showTiming(number, before)29 20 return billingcodes 30 21 … … 37 28 argsfile.write("%s\n" % bname) 38 29 argsfile.close() 39 before = time.time()40 30 os.system('pkbcodes --arguments arguments.list') 41 showTiming(len(billingcodes), before)42 31 43 32 def createPrinters(number) : … … 50 39 argsfile.write("%s\n" % pname) 51 40 argsfile.close() 52 before = time.time()53 41 os.system('pkprinters --arguments arguments.list') 54 showTiming(number, before)55 42 return printernames 56 43 … … 63 50 argsfile.write("%s\n" % pname) 64 51 argsfile.close() 65 before = time.time()66 52 os.system('pkprinters --arguments arguments.list') 67 showTiming(len(printernames), before)68 53 69 54 def createUsers(number) : … … 76 61 argsfile.write("%s\n" % uname) 77 62 argsfile.close() 78 before = time.time()79 63 os.system('pkusers --arguments arguments.list') 80 showTiming(number, before)81 64 return usernames 82 65 … … 89 72 argsfile.write("%s\n" % uname) 90 73 argsfile.close() 91 before = time.time()92 74 os.system('pkusers --arguments arguments.list') 93 showTiming(len(usernames), before)94 75 95 76 def createUserPQuotas(usernames, printernames) : … … 103 84 argsfile.write("%s\n" % uname) 104 85 argsfile.close() 105 before = time.time()106 86 os.system('edpykota --arguments arguments.list') 107 showTiming(number, before)108 87 109 88 def deleteUserPQuotas(usernames, printernames) : … … 117 96 argsfile.write("%s\n" % uname) 118 97 argsfile.close() 119 before = time.time()120 98 os.system('edpykota --arguments arguments.list') 121 showTiming(number, before)122 99 123 100 if __name__ == "__main__" :