Changeset 3470

Show
Ignore:
Timestamp:
12/16/08 22:54:18 (15 years ago)
Author:
jerome
Message:

Now pkrefund features a -i|--info command line option allowing the
refunding informations prefix to be changed from the default.
This change fixes #30.

Location:
pykota/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkrefund

    r3434 r3470  
    2929import time 
    3030import cStringIO 
     31 
     32from mx import DateTime 
    3133 
    3234try : 
     
    236238                                            end=end, 
    237239                                            limit=0) 
     240        try : 
     241            loginname = os.getlogin() 
     242        except OSError : 
     243            loginname = pwd.getpwuid(os.getuid()).pw_name 
    238244 
    239245        peruser = {} 
     
    246252        for job in jobs : 
    247253            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 
    248265                if options.force : 
    249266                    nbpages += job.JobSize 
    250267                    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                                                  }) 
    252273                    counters["nbpages"] += job.JobSize 
    253274                    counters["nbcredits"] += job.JobPrice 
    254                     job.refund(options.reason) 
     275                    job.refund(reason) 
    255276                    counters["nbjobs"] += 1 
    256277                    nbjobs += 1 
     
    273294                            nbpages += job.JobSize 
    274295                            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                                                          }) 
    276301                            counters["nbpages"] += job.JobSize 
    277302                            counters["nbcredits"] += job.JobPrice 
    278                             job.refund(options.reason) 
     303                            job.refund(reason) 
    279304                            counters["nbjobs"] += 1 
    280305                            nbjobs += 1 
     
    282307                        elif answer == _("N") : 
    283308                            break 
    284                     print 
     309                    sys.stdout.write("\n") 
    285310        if outfname != "-" : 
    286311            percent.done() 
     
    289314                         outfname, 
    290315                         options.number, 
    291                          options.reason, 
     316                         options.reason, # We don't want the full reason here. 
    292317                         options.unit or _("Credits")) 
    293318        if outfname != "-" : 
     
    302327                            dest="force", 
    303328                            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'''")) 
    305335    parser.add_option("-l", "--logo", 
    306336                            dest="logo", 
    307337                            default=u"/usr/share/pykota/logos/pykota.jpeg", 
    308338                            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.")) 
    316339    parser.add_option("-n", "--number", 
    317340                            dest="number", 
     
    325348                            type="string", 
    326349                            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.")) 
    328358    parser.add_option("-r", "--reason", 
    329359                            dest="reason", 
  • pykota/trunk/pykota/storage.py

    r3445 r3470  
    475475    def refund(self, reason) : 
    476476        """Refund a particular print job.""" 
    477         if (not self.JobSize) or (self.JobAction in ("DENY", "CANCEL", "REFUND")) : 
    478             return 
    479         try : 
    480             loginname = os.getlogin() 
    481         except OSError : 
    482             import pwd 
    483             loginname = pwd.getpwuid(os.getuid()).pw_name 
    484         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 = basereason 
    494477        self.parent.tool.logdebug("Refunding job %s..." % self.ident) 
    495478        self.parent.beginTransaction()