Changeset 1048 for pykota/trunk/bin

Show
Ignore:
Timestamp:
06/30/03 14:46:15 (21 years ago)
Author:
jalet
Message:

Extracted reporting code.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/repykota

    r1041 r1048  
    2323# 
    2424# $Log$ 
     25# Revision 1.40  2003/06/30 12:46:15  jalet 
     26# Extracted reporting code. 
     27# 
    2528# Revision 1.39  2003/06/25 14:10:01  jalet 
    2629# Hey, it may work (edpykota --reset excepted) ! 
     
    160163from pykota.config import PyKotaConfigError 
    161164from pykota.storage import PyKotaStorageError 
     165from pykota.reporter import PyKotaReporterError 
     166from pykota import reporter 
    162167 
    163168__doc__ = """repykota v%s (C) 2003 C@LL - Conseil Internet & Logiciels Libres 
     
    241246        if not printers : 
    242247            raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] 
    243         for printer in printers : 
    244             print _("*** Report for %s quota on printer %s") % ((options["groups"] and "group") or "user", printer.Name) 
    245             print _("Pages grace time: %i days") % self.config.getGraceDelay(printer.Name) 
    246             if printer.PricePerJob is not None : 
    247                 print _("Price per job: %.3f") % printer.PricePerJob 
    248             if printer.PricePerPage is not None :     
    249                 print _("Price per page: %.3f") % printer.PricePerPage 
    250             total = 0 
    251             totalmoney = 0.0 
    252             if options["groups"] : 
    253                 print _("Group           used    soft    hard    balance grace         total       paid")  
    254                 print "------------------------------------------------------------------------------" 
    255                 for (group, grouppquota) in self.storage.getPrinterGroupsAndQuotas(printer, ugnames) : 
    256                     (pages, money) = self.printQuota(group, grouppquota) 
    257                     total += pages 
    258                     totalmoney += money 
    259             else : 
    260                 # default is user quota report 
    261                 print _("User            used    soft    hard    balance grace         total       paid")  
    262                 print "------------------------------------------------------------------------------" 
    263                 for (user, userpquota) in self.storage.getPrinterUsersAndQuotas(printer, ugnames) : 
    264                     (pages, money) = self.printQuota(user, userpquota) 
    265                     total += pages 
    266                     totalmoney += money 
    267             if total or totalmoney :         
    268                 print (" " * 50) + (_("Total : %9i") % total) + ("%11s" % ("%7.2f" % totalmoney)[:11]) 
    269             try : 
    270                 msg = "%9i" % printer.LastJob.PrinterPageCounter 
    271             except TypeError :      
    272                 msg = _("unknown") 
    273             print (" " * 51) + (_("Real : %s") % msg) 
    274             print         
    275         if options["groups"] :     
    276             print _("Totals may be inaccurate if some users are members of several groups.") 
    277                          
    278     def printQuota(self, entry, quota) : 
    279         """Prints the quota information.""" 
    280         lifepagecounter = int(quota.LifePageCounter or 0) 
    281         pagecounter = int(quota.PageCounter or 0) 
    282         balance = float(entry.AccountBalance or 0.0) 
    283         lifetimepaid = float(entry.LifeTimePaid or 0.0) 
    284          
    285         if quota.DateLimit is not None : 
    286             now = DateTime.now() 
    287             datelimit = DateTime.ISO.ParseDateTime(quota.DateLimit) 
    288             if now >= datelimit : 
    289                 datelimit = "DENY" 
    290         elif (quota.HardLimit is not None) and (pagecounter >= quota.HardLimit) :     
    291             datelimit = "DENY" 
    292         elif (quota.HardLimit is None) and (quota.SoftLimit is not None) and (pagecounter >= quota.SoftLimit) : 
    293             datelimit = "DENY" 
    294         else :     
    295             datelimit = "" 
    296248             
    297         if entry.LimitBy.lower() == "balance" :     
    298             reached = (((balance <= 0) and "+") or "-") + "B" 
    299         else : 
    300             reached = (((quota.SoftLimit is not None) and (pagecounter >= quota.SoftLimit) and "+") or "-") + "Q" 
    301              
    302         strbalance = ("%5.2f" % balance)[:10] 
    303         strlifetimepaid = ("%6.2f" % lifetimepaid)[:10] 
    304         print "%-9.9s %s %7i %7s %7s %10s %-10.10s %8i %10s" % (entry.Name, reached, pagecounter, str(quota.SoftLimit), str(quota.HardLimit), strbalance, str(datelimit)[:10], lifepagecounter, strlifetimepaid) 
    305         return (lifepagecounter, lifetimepaid) 
     249        self.reportingtool = reporter.openReporter(self, "text", printers, ugnames, (options["groups"] and 1) or 0)     
     250        print self.reportingtool.generateReport() 
    306251                     
    307252if __name__ == "__main__" :  
     
    314259         
    315260        # Initializes the command line tool 
    316         reporter = RePyKota(doc=__doc__) 
     261        reportTool = RePyKota(doc=__doc__) 
    317262         
    318263        # parse and checks the command line 
    319         (options, args) = reporter.parseCommandline(sys.argv[1:], short_options, long_options, allownothing=1) 
     264        (options, args) = reportTool.parseCommandline(sys.argv[1:], short_options, long_options, allownothing=1) 
    320265         
    321266        # sets long options 
     
    327272         
    328273        if options["help"] : 
    329             reporter.display_usage_and_quit() 
     274            reportTool.display_usage_and_quit() 
    330275        elif options["version"] : 
    331             reporter.display_version_and_quit() 
     276            reportTool.display_version_and_quit() 
    332277        elif options["users"] and options["groups"] :     
    333278            raise PyKotaToolError, _("incompatible options, see help.") 
    334279        else : 
    335             sys.exit(reporter.main(args, options)) 
    336     except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError), msg :             
     280            sys.exit(reportTool.main(args, options)) 
     281    except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError, PyKotaReporterError), msg :             
    337282        sys.stderr.write("%s\n" % msg) 
    338283        sys.stderr.flush()