Changeset 1048

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

Extracted reporting code.

Location:
pykota/trunk
Files:
4 added
4 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() 
  • pykota/trunk/cgi-bin/printquota.cgi

    r952 r1048  
    2323# 
    2424# $Log$ 
     25# Revision 1.7  2003/06/30 12:46:15  jalet 
     26# Extracted reporting code. 
     27# 
    2528# Revision 1.6  2003/04/23 22:13:56  jalet 
    2629# Preliminary support for LPRng added BUT STILL UNTESTED. 
     
    4851import os 
    4952import cgi 
     53 
     54from pykota import version 
     55from pykota.tool import PyKotaTool, PyKotaToolError 
     56from pykota.config import PyKotaConfigError 
     57from pykota.storage import PyKotaStorageError 
    5058 
    5159header = """Content-type: text/html 
  • pykota/trunk/pykota/tool.py

    r1041 r1048  
    2121# 
    2222# $Log$ 
     23# Revision 1.42  2003/06/30 12:46:15  jalet 
     24# Extracted reporting code. 
     25# 
    2326# Revision 1.41  2003/06/25 14:10:01  jalet 
    2427# Hey, it may work (edpykota --reset excepted) ! 
     
    498501                self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 
    499502        return action         
    500      
  • pykota/trunk/setup.py

    r1018 r1048  
    2323# 
    2424# $Log$ 
     25# Revision 1.17  2003/06/30 12:46:15  jalet 
     26# Extracted reporting code. 
     27# 
    2528# Revision 1.16  2003/06/06 20:49:15  jalet 
    2629# Very latest schema. UNTESTED. 
     
    228231      author_email = "alet@librelogiciel.com", 
    229232      url = "http://www.librelogiciel.com/software/", 
    230       packages = [ "pykota", "pykota.storages", "pykota.requesters", "pykota.loggers", "pykota.accounters" ], 
     233      packages = [ "pykota", "pykota.storages", "pykota.requesters", "pykota.loggers", "pykota.accounters", "pykota.reporters" ], 
    231234      scripts = [ "bin/pykota", "bin/edpykota", "bin/repykota", "bin/warnpykota" ], 
    232235      data_files = data_files)