Changeset 1258

Show
Ignore:
Timestamp:
01/08/04 17:24:49 (21 years ago)
Author:
jalet
Message:

edpykota now supports adding printers to printer groups.

Location:
pykota/trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/edpykota

    r1257 r1258  
    2424# 
    2525# $Log$ 
     26# Revision 1.65  2004/01/08 16:24:49  jalet 
     27# edpykota now supports adding printers to printer groups. 
     28# 
    2629# Revision 1.64  2004/01/08 14:10:32  jalet 
    2730# Copyright year changed. 
     
    276279                       by separating them with commas. 
    277280   
    278   -g | --groups        Edit groups print quotas instead of users. 
     281  -G | --pgroups pg1[,pg2...] Adds the printer(s) to the printer groups 
     282                       pg1, pg2, etc... which must already exist. 
     283                       A printer group is just like a normal printer, 
     284                       only that it is usually unknown from the printing 
     285                       system. Create printer groups exactly the same 
     286                       way that you create printers, then add other  
     287                       printers to them with this option. 
     288                       Accounting is done on a printer and on all 
     289                       the printer groups it belongs to, quota checking 
     290                       is done on a printer and on all the printer groups 
     291                       it belongs to. 
     292   
     293  -g | --groups        Edit users groups print quotas instead of users. 
    279294                           
    280295  -p | --prototype u|g Uses user u or group g as a prototype to set 
     
    366381  This will set the page price for printer lp to 0.1. Job price 
    367382  will not be changed. 
     383   
     384  $ edpykota --printer hplj1,hplj2 --pgroups Laser,HP 
     385   
     386  This will put printers hplj1 and hplj2 in printers groups Laser and HP. 
     387  When printing either on hplj1 or hplj2, print quota will also be  
     388  checked and accounted for on virtual printers Laser and HP. 
    368389 
    369390This program is free software; you can redistribute it and/or modify 
     
    464485                names = [ "*" ] # all users 
    465486                 
     487        printersgroups = []         
     488        if options["pgroups"] :         
     489            printersgroups = self.storage.getMatchingPrinters(options["pgroups"]) 
     490             
    466491        changed = {} # tracks changes made at the user/group level 
    467492        for printer in printers : 
     493            for pgroup in printersgroups : 
     494                pgroup.addPrinterToGroup(printer)     
     495                 
    468496            if options["charge"] : 
    469497                (perpage, perjob) = charges 
     
    576604                     "printer" : "*", \ 
    577605                   } 
    578         short_options = "vhdc:l:b:i:naugrp:P:S:H:" 
    579         long_options = ["help", "version", "charge=", "delete", "limitby=", "balance=", "ingroups=", "noquota", "add", "users", "groups", "reset", "prototype=", "printer=", "softlimit=", "hardlimit="] 
     606        short_options = "vhdc:l:b:i:naugrp:P:S:H:G:" 
     607        long_options = ["help", "version", "charge=", "delete", "limitby=", "balance=", "ingroups=", "noquota", "add", "users", "groups", "reset", "prototype=", "printer=", "softlimit=", "hardlimit=", "pgroups="] 
    580608         
    581609        # Initializes the command line tool 
     
    602630        options["ingroups"] = options["i"] or options["ingroups"] 
    603631        options["charge"] = options["c"] or options["charge"] 
     632        options["pgroups"] = options["G"] or options["pgroups"] 
    604633         
    605634        if options["help"] : 
  • pykota/trunk/NEWS

    r1257 r1258  
    2222PyKota NEWS : 
    2323 
     24    - 1.16alpha22 : 
     25     
     26        - edpykota now allows adding printers to printer groups 
     27         
    2428    - 1.16alpha21 : 
    2529     
  • pykota/trunk/pykota/storage.py

    r1257 r1258  
    2222# 
    2323# $Log$ 
     24# Revision 1.34  2004/01/08 16:24:49  jalet 
     25# edpykota now supports adding printers to printer groups. 
     26# 
    2427# Revision 1.33  2004/01/08 14:10:32  jalet 
    2528# Copyright year changed. 
     
    239242        self.parent.writeJobNew(self, user, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options) 
    240243        # TODO : update LastJob object ? Probably not needed. 
     244         
     245    def addPrinterToGroup(self, printer) :     
     246        """Adds a printer to a printer group.""" 
     247        if printer not in self.parent.getParentPrinters(self) : 
     248            self.parent.writePrinterToGroup(self, printer) 
    241249         
    242250    def setPrices(self, priceperpage = None, priceperjob = None) :     
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1257 r1258  
    2222# 
    2323# $Log$ 
     24# Revision 1.45  2004/01/08 16:24:49  jalet 
     25# edpykota now supports adding printers to printer groups. 
     26# 
    2427# Revision 1.44  2004/01/08 14:10:33  jalet 
    2528# Copyright year changed. 
     
    361364        """Extracts printer information given its name.""" 
    362365        printer = StoragePrinter(self, printername) 
    363         result = self.doSearch("(&(objectClass=pykotaPrinter)(|(pykotaPrinterName=%s)(%s=%s)))" % (printername, self.info["printerrdn"], printername), ["pykotaPricePerPage", "pykotaPricePerJob"], base=self.info["printerbase"]) 
     366        result = self.doSearch("(&(objectClass=pykotaPrinter)(|(pykotaPrinterName=%s)(%s=%s)))" % (printername, self.info["printerrdn"], printername), ["pykotaPricePerPage", "pykotaPricePerJob", "uniqueMember"], base=self.info["printerbase"]) 
    364367        if result : 
    365368            fields = result[0][1] 
     
    368371            printer.PricePerPage = float(fields.get("pykotaPricePerPage")[0] or 0.0) 
    369372            printer.LastJob = self.getPrinterLastJob(printer) 
     373            printer.uniqueMember = fields.get("uniqueMember", []) 
    370374            printer.Exists = 1 
    371375        return printer     
     
    521525        printers = [] 
    522526        # see comment at the same place in pgstorage.py 
    523         result = self.doSearch("(&(objectClass=pykotaPrinter)(|%s))" % "".join(["(pykotaPrinterName=%s)" % pname for pname in printerpattern.split(",")]), ["pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerJob"], base=self.info["printerbase"]) 
     527        result = self.doSearch("(&(objectClass=pykotaPrinter)(|%s))" % "".join(["(pykotaPrinterName=%s)" % pname for pname in printerpattern.split(",")]), ["pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerJob", "uniqueMember"], base=self.info["printerbase"]) 
    524528        if result : 
    525529            for (printerid, fields) in result : 
     
    529533                printer.PricePerJob = float(fields.get("pykotaPricePerJob")[0] or 0.0) 
    530534                printer.PricePerPage = float(fields.get("pykotaPricePerPage")[0] or 0.0) 
     535                printer.uniqueMember = fields.get("uniqueMember", []) 
    531536                printer.LastJob = self.getPrinterLastJob(printer) 
    532537                printer.Exists = 1 
     
    814819        self.doModify(grouppquota.ident, fields) 
    815820             
     821    def writePrinterToGroup(self, pgroup, printer) : 
     822        """Puts a printer into a printer group.""" 
     823        if (printer.ident not in pgroup.uniqueMember) and (printer.ident != pgroup.ident) : 
     824            fields = { 
     825                       "uniqueMember" : pgroup.uniqueMember + [printer.ident] 
     826                     }   
     827            self.doModify(pgroup.ident, fields)          
     828         
    816829    def deleteUser(self, user) :     
    817830        """Completely deletes an user from the Quota Storage.""" 
  • pykota/trunk/pykota/storages/pgstorage.py

    r1257 r1258  
    2222# 
    2323# $Log$ 
     24# Revision 1.29  2004/01/08 16:24:49  jalet 
     25# edpykota now supports adding printers to printer groups. 
     26# 
    2427# Revision 1.28  2004/01/08 14:10:33  jalet 
    2528# Copyright year changed. 
     
    505508        self.doModify("UPDATE grouppquota SET softlimit=%s, hardlimit=%s, datelimit=NULL WHERE id=%s" % (self.doQuote(softlimit), self.doQuote(hardlimit), self.doQuote(grouppquota.ident))) 
    506509 
     510    def writePrinterToGroup(self, pgroup, printer) : 
     511        """Puts a printer into a printer group.""" 
     512        self.doModify("INSERT INTO printergroupsmembers (groupid, printerid) VALUES (%s, %s);" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident))) 
     513         
    507514    def deleteUser(self, user) :     
    508515        """Completely deletes an user from the Quota Storage.""" 
  • pykota/trunk/pykota/version.py

    r1257 r1258  
    2222# 
    2323 
    24 __version__ = "1.16alpha21_unofficial" 
     24__version__ = "1.16alpha22_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""