Changeset 3470
- Timestamp:
- 12/16/08 22:54:18 (16 years ago)
- Location:
- pykota/trunk
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pkrefund
r3434 r3470 29 29 import time 30 30 import cStringIO 31 32 from mx import DateTime 31 33 32 34 try : … … 236 238 end=end, 237 239 limit=0) 240 try : 241 loginname = os.getlogin() 242 except OSError : 243 loginname = pwd.getpwuid(os.getuid()).pw_name 238 244 239 245 peruser = {} … … 246 252 for job in jobs : 247 253 if job.JobSize and (job.JobAction not in ("DENY", "CANCEL", "REFUND")) : 254 if options.info : 255 reason = "%s : %s" % (options.info % { "nbpages" : job.JobSize, 256 "nbcredits" : job.JobPrice, 257 "effectiveuser" : self.effectiveUserName, 258 "loginname" : loginname, 259 "date" : str(DateTime.now())[:19], 260 }, 261 options.reason) 262 else : 263 reason = options.reason 264 248 265 if options.force : 249 266 nbpages += job.JobSize 250 267 nbcredits += job.JobPrice 251 counters = peruser.setdefault(job.UserName, { "nbjobs" : 0, "nbpages" : 0, "nbcredits" : 0.0 }) 268 counters = peruser.setdefault(job.UserName, 269 { "nbjobs" : 0, 270 "nbpages" : 0, 271 "nbcredits" : 0.0, 272 }) 252 273 counters["nbpages"] += job.JobSize 253 274 counters["nbcredits"] += job.JobPrice 254 job.refund( options.reason)275 job.refund(reason) 255 276 counters["nbjobs"] += 1 256 277 nbjobs += 1 … … 273 294 nbpages += job.JobSize 274 295 nbcredits += job.JobPrice 275 counters = peruser.setdefault(job.UserName, { "nbjobs" : 0, "nbpages" : 0, "nbcredits" : 0.0 }) 296 counters = peruser.setdefault(job.UserName, 297 { "nbjobs" : 0, 298 "nbpages" : 0, 299 "nbcredits" : 0.0, 300 }) 276 301 counters["nbpages"] += job.JobSize 277 302 counters["nbcredits"] += job.JobPrice 278 job.refund( options.reason)303 job.refund(reason) 279 304 counters["nbjobs"] += 1 280 305 nbjobs += 1 … … 282 307 elif answer == _("N") : 283 308 break 284 print309 sys.stdout.write("\n") 285 310 if outfname != "-" : 286 311 percent.done() … … 289 314 outfname, 290 315 options.number, 291 options.reason, 316 options.reason, # We don't want the full reason here. 292 317 options.unit or _("Credits")) 293 318 if outfname != "-" : … … 302 327 dest="force", 303 328 action="store_true", 304 help=_("Doesn't ask for confirmation before refunding.")) 329 help=_("Doesn't ask for confirmation before refunding. Only needed if you specify a filename for the PDF receipts. If you send such receipts to stdout, --force is assumed to be set.")) 330 parser.add_option("-i", "--info", 331 dest="info", 332 type="string", 333 default=_("Refunded %(nbpages)i pages and %(nbcredits).3f credits by %(effectiveuser)s (%(loginname)s) on %(date)s"), 334 help=_("The informations to be prepended to the refunding reason, which can include some of Python's string interpolations to access to certain internal values. If you don't want such information, set this explicitely to an empty string. The default is '''%default'''")) 305 335 parser.add_option("-l", "--logo", 306 336 dest="logo", 307 337 default=u"/usr/share/pykota/logos/pykota.jpeg", 308 338 help=_("The image to use as a logo. The logo will be drawn at the center top of the page. The default logo is %default.")) 309 parser.add_option("-p", "--pagesize",310 type="string",311 action="callback",312 callback=checkandset_pagesize,313 dest="pagesize",314 default=u"A4",315 help=_("Set the size of the page. Most well known page sizes are recognized, like 'A4' or 'Letter' to name a few. The default page size is %default."))316 339 parser.add_option("-n", "--number", 317 340 dest="number", … … 325 348 type="string", 326 349 default=u"-", 327 help=_("The name of the file to which the PDF receipts will be written. If not set or set to '%default', the PDF document will be sent to the standard output.")) 350 help=_("The name of the file to which the PDF receipts will be written. If not set or set to '%default', the PDF document will be sent to the standard output, and --force will be assumed to be set.")) 351 parser.add_option("-p", "--pagesize", 352 type="string", 353 action="callback", 354 callback=checkandset_pagesize, 355 dest="pagesize", 356 default=u"A4", 357 help=_("Set the size of the page. Most well known page sizes are recognized, like 'A4' or 'Letter' to name a few. The default page size is %default.")) 328 358 parser.add_option("-r", "--reason", 329 359 dest="reason", -
pykota/trunk/pykota/storage.py
r3445 r3470 475 475 def refund(self, reason) : 476 476 """Refund a particular print job.""" 477 if (not self.JobSize) or (self.JobAction in ("DENY", "CANCEL", "REFUND")) :478 return479 try :480 loginname = os.getlogin()481 except OSError :482 import pwd483 loginname = pwd.getpwuid(os.getuid()).pw_name484 basereason = _("Refunded %i pages and %.3f credits by %s (%s) on %s") \485 % (self.JobSize,486 self.JobPrice,487 self.parent.tool.effectiveUserName,488 loginname,489 str(DateTime.now())[:19])490 if reason :491 reason = "%s : %s" % (basereason, reason)492 else :493 reason = basereason494 477 self.parent.tool.logdebug("Refunding job %s..." % self.ident) 495 478 self.parent.beginTransaction()