Changeset 3429 for pykota

Show
Ignore:
Timestamp:
10/05/08 11:21:53 (16 years ago)
Author:
jerome
Message:

Changed the way informations are output, especially to replace 'print'
statements which won't exist anymore in Python 3.

Location:
pykota/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkinvoice

    r3413 r3429  
    264264        if outfname != "-" : 
    265265            nbusers = len(peruser) 
    266             print _("Invoiced %(nbusers)i users for %(nbjobs)i jobs, %(nbpages)i pages and %(nbcredits).3f credits") \ 
    267                      % locals() 
     266            self.display("%s\n" % (_("Invoiced %(nbusers)i users for %(nbjobs)i jobs, %(nbpages)i pages and %(nbcredits).3f credits") \ 
     267                     % locals())) 
    268268 
    269269if __name__ == "__main__" : 
  • pykota/trunk/bin/pkrefund

    r3413 r3429  
    257257                        percent.oneMore() 
    258258                else : 
    259                     print _("Date : %s") % str(job.JobDate)[:19] 
    260                     print _("Printer : %s") % job.PrinterName 
    261                     print _("User : %s") % job.UserName 
    262                     print _("JobId : %s") % job.JobId 
    263                     print _("Title : %s") % job.JobTitle 
     259                    self.display("%s\n" % (_("Date : %s") % str(job.JobDate)[:19])) 
     260                    self.display("%s\n" % (_("Printer : %s") % job.PrinterName)) 
     261                    self.display("%s\n" % (_("User : %s") % job.UserName)) 
     262                    self.display("%s\n" % (_("JobId : %s") % job.JobId)) 
     263                    self.display("%s\n" % (_("Title : %s") % job.JobTitle)) 
    264264                    if job.JobBillingCode : 
    265                         print _("Billing code : %s") % job.JobBillingCode 
    266                     print _("Pages : %i") % job.JobSize 
    267                     print _("Credits : %.3f") % job.JobPrice 
     265                        self.display("%s\n" % (_("Billing code : %s") % job.JobBillingCode)) 
     266                    self.display("%s\n" % (_("Pages : %i") % job.JobSize)) 
     267                    self.display("%s\n" % (_("Credits : %.3f") % job.JobPrice)) 
    268268 
    269269                    while True : 
     
    292292        if outfname != "-" : 
    293293            nbusers = len(peruser) 
    294             print _("Refunded %(nbusers)i users for %(nbjobs)i jobs, %(nbpages)i pages and %(nbcredits).3f credits") \ 
    295                      % locals() 
     294            self.display("%s\n" % (_("Refunded %(nbusers)i users for %(nbjobs)i jobs, %(nbpages)i pages and %(nbcredits).3f credits") \ 
     295                     % locals())) 
    296296 
    297297if __name__ == "__main__" : 
  • pykota/trunk/bin/pkturnkey

    r3424 r3429  
    331331            return 
    332332        sys.stderr.flush() # ensure outputs don't mix 
    333         print 
    334         print "--- CUT ---" 
    335         print "# Here are some lines that we suggest you add at the end" 
    336         print "# of the pykota.conf file. These lines gives possible" 
    337         print "# values for the way print jobs' size will be computed." 
    338         print "# NB : it is possible that a manual configuration gives" 
    339         print "# better results for you. As always, your mileage may vary." 
    340         print "#" 
     333        self.display("\n--- CUT ---\n") 
     334        self.display("# Here are some lines that we suggest you add at the end\n") 
     335        self.display("# of the pykota.conf file. These lines gives possible\n") 
     336        self.display("# values for the way print jobs' size will be computed.\n") 
     337        self.display("# NB : it is possible that a manual configuration gives\n") 
     338        self.display("# better results for you. As always, your mileage may vary.\n") 
     339        self.display("#\n") 
    341340        for (name, uri) in printers : 
    342             print "[%s]" % name 
     341            self.display("[%s]\n" % name) 
    343342            accounter = "software()" 
    344343            try : 
     
    380379                        accounter = "hardware(pjl:%s)" % port 
    381380 
    382             print "preaccounter : software()" 
    383             print "accounter : %s" % accounter 
    384             print 
    385         print "--- CUT ---" 
     381            self.display("preaccounter : software()\n") 
     382            self.display("accounter : %s\n" % accounter) 
     383            self.display("\n") 
     384        self.display("--- CUT ---\n") 
    386385 
    387386    def main(self, names, options) : 
  • pykota/trunk/bin/repykota

    r3413 r3429  
    8181 
    8282        self.reportingtool = reporter.openReporter(self, "text", printers, ugnames, options.groups) 
    83         print self.reportingtool.generateReport() 
     83        self.display(self.reportingtool.generateReport()) 
    8484 
    8585if __name__ == "__main__" : 
  • pykota/trunk/pykota/tool.py

    r3413 r3429  
    4747    def __init__(self, app, size=None) : 
    4848        """Initializes the engine.""" 
     49        self.isatty = sys.stdout.isatty() 
    4950        self.app = app 
    5051        self.size = None 
     
    6364    def display(self, msg) : 
    6465        """Displays the value.""" 
    65         self.app.display(msg) 
     66        if self.isatty : 
     67            self.app.display(msg) 
     68            sys.stdout.flush() 
    6669 
    6770    def oneMore(self) : 
     
    151154 
    152155    def display(self, message) : 
    153         """Display a message but only if stdout is a tty.""" 
    154         if sys.stdout.isatty() : 
    155             sys.stdout.write(message.encode(self.charset, \ 
     156        """Display a message after ensuring the correct charset is used.""" 
     157        sys.stdout.write(message.encode(self.charset, 
    156158                                            "replace")) 
    157             sys.stdout.flush() 
    158159 
    159160    def logdebug(self, message) :