Changeset 3549

Show
Ignore:
Timestamp:
08/18/10 04:20:57 (14 years ago)
Author:
jerome
Message:

Removed support for the MaxJobSize? attribute for users group print quota
entries : I couldn't see a real use for this at the moment, and it would
complexify the code. This support might reappear later however. Added full
support for the MaxJobSize? attribute for user print quota entries,
editable with edpykota's new --maxjobsize command line switch. Changed
the internal handling of the MaxJobSize? attribute for printers :
internally 0 used to mean unlimited, it now allows one to forbid
printing onto a particular printer. The database upgrade script (only
for PostgreSQL) takes care of this.
IMPORTANT : the database schema changes. A database upgrade script is
provided for PostgreSQL only. The LDAP schema doesn't change to not
break any existing LDAP directory, so the pykotaMaxJobSize attribute is
still allowed on group print quota entries, but never used.
Seems to work as expected, for a change :-)
Fixes #15.

Location:
pykota/trunk
Files:
1 added
13 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r3545 r3549  
    557557        setenv("PYKOTALIFETIMEPAID", str(self.User.LifeTimePaid or 0.0), self.charset) 
    558558        setenv("PYKOTAUSERDESCRIPTION", self.User.Description or "", self.charset) 
     559        setenv("PYKOTAMAXJOBSIZE", ((self.UserPQuota.MaxJobSize is None) and _("Unlimited")) or str(self.UserPQuota.MaxJobSize), self.charset) 
    559560 
    560561        setenv("PYKOTAPAGECOUNTER", str(self.UserPQuota.PageCounter or 0), self.charset) 
     
    10271028                # This printer was set to refuse jobs this large. 
    10281029                self.printInfo(_("Precomputed job size (%s pages) too large for printer %s.") % (self.softwareJobSize, self.PrinterName), "warn") 
     1030                self.Action = "DENY" 
     1031                # here we don't put the precomputed job size in the message 
     1032                # because in case of error the user could complain :-) 
     1033                self.Reason = _("You are not allowed to print so many pages on printer %s at this time.") % self.PrinterName 
     1034 
     1035        if self.Action not in ("DENY", "CANCEL") : 
     1036            if (self.UserPQuota.MaxJobSize is not None) and (self.softwareJobSize > self.UserPQuota.MaxJobSize) : 
     1037                # This user print quota entry was set to refuse jobs this large. 
     1038                self.printInfo(_("Precomputed job size (%s pages) too large for user %s on printer %s.") % (self.softwareJobSize, self.UserName, self.PrinterName), "warn") 
    10291039                self.Action = "DENY" 
    10301040                # here we don't put the precomputed job size in the message 
  • pykota/trunk/bin/edpykota

    r3489 r3549  
    3636class EdPyKota(PyKotaTool) : 
    3737    """A class for edpykota.""" 
    38     def modifyPQEntry(self, pqkey, pqentry, noquota, softlimit, hardlimit, increase, reset, hardreset, suffix, used) : 
     38    def modifyPQEntry(self, pqkey, pqentry, noquota, softlimit, hardlimit, increase, reset, hardreset, suffix, used, maxjobsize) : 
    3939        """Modifies a print quota entry.""" 
    4040        if noquota or ((softlimit is not None) and (hardlimit is not None)) : 
     
    5454            if used : 
    5555                pqentry.setUsage(used) 
     56            if maxjobsize is not None : 
     57                if maxjobsize == "unlimited" : 
     58                    pqentry.setMaxJobSize(None) 
     59                else : 
     60                    pqentry.setMaxJobSize(maxjobsize) 
    5661 
    5762    def main(self, names, options) : 
     
    7782                                      or options.noquota \ 
    7883                                      or options.increase \ 
     84                                      or options.maxjobsize \ 
    7985                                      or options.skipexisting))) \ 
    8086             or (options.groups and (options.used \ 
     87                                  or options.maxjobsize \ 
    8188                                  or options.increase \ 
    8289                                  or options.reset \ 
     
    106113                        self.display("    %s\n" % (_("Hard limit : %s") % pqentry.HardLimit)) 
    107114                        self.display("    %s\n" % (_("Date limit : %s") % pqentry.DateLimit)) 
    108                         self.display("    %s (Not supported yet)\n" % (_("Maximum job size : %s") % ((pqentry.MaxJobSize and (_("%s pages") % pqentry.MaxJobSize)) or _("Unlimited")))) 
     115                        if suffix == "User" : 
     116                            self.display("    %s\n" % (_("Maximum job size : %s") % (((pqentry.MaxJobSize is not None) and (_("%s pages") % pqentry.MaxJobSize)) or _("Unlimited")))) 
    109117                        if hasattr(pqentry, "WarnCount") : 
    110118                            self.display("    %s\n" % (_("Warning banners printed : %s") % pqentry.WarnCount)) 
     
    159167                        self.printInfo(_("Undefined soft limit set to hard limit (%s).") % str(softlimit)) 
    160168 
     169            if options.maxjobsize : 
     170                if options.maxjobsize.lower() == "unlimited" : 
     171                    maxjobsize = "unlimited" 
     172                else : 
     173                    try : 
     174                        maxjobsize = int(options.maxjobsize) 
     175                        if maxjobsize < 0 : 
     176                            raise ValueError 
     177                    except ValueError : 
     178                        raise PyKotaCommandLineError, _("Invalid maximum job size value %s") % options.maxjobsize 
     179            else : 
     180                maxjobsize = None 
     181 
    161182            self.storage.beginTransaction() 
    162183            try : 
     
    183204                                               options.hardreset, 
    184205                                               suffix, 
    185                                                used) 
     206                                               used, 
     207                                               maxjobsize) 
    186208                            oldpqentry = getattr(self.storage, "add%sPQuota" % suffix)(pqentry) 
    187209                            if oldpqentry is not None : 
     
    201223                                                       options.hardreset, 
    202224                                                       suffix, 
    203                                                        used) 
     225                                                       used, 
     226                                                       maxjobsize) 
    204227                                    oldpqentry.save() 
    205228                            percent.oneMore() 
     
    220243                                                   options.hardreset, 
    221244                                                   suffix, 
    222                                                    used) 
     245                                                   used, 
     246                                                   maxjobsize) 
    223247                                pqentry.save() 
    224248                            percent.oneMore() 
     
    263287                            dest="action", 
    264288                            help=_("Display detailed informations about the specified users or groups print quota entries.")) 
     289    parser.add_option("-m", "--maxjobsize", 
     290                            dest="maxjobsize", 
     291                            help=_("Set the maximum job size in pages the specified users are allowed to print to the specified printers in a single job. Accepted values are '0' to forbid printing, 'unlimited' to allow unrestricted printing, or any positive integer value. This option is not supported for users groups.")) 
    265292    parser.add_option("-n", "--noquota", 
    266293                            dest="noquota", 
  • pykota/trunk/bin/pkprinters

    r3489 r3549  
    5050            printer.setPassThrough(True) 
    5151        if maxjobsize is not None : 
    52             printer.setMaxJobSize(maxjobsize) 
     52            if maxjobsize == "unlimited" : 
     53                printer.setMaxJobSize(None) 
     54            else : 
     55                printer.setMaxJobSize(maxjobsize) 
    5356 
    5457    def managePrintersGroups(self, pgroups, printer, remove) : 
     
    151154                                     (_("Passthrough mode : %s") % ((printer.PassThrough and _("ON")) or _("OFF")))) 
    152155                self.display("    %s\n" % \ 
    153                                      (_("Maximum job size : %s") % ((printer.MaxJobSize and (_("%s pages") % printer.MaxJobSize)) or _("Unlimited")))) 
     156                                     (_("Maximum job size : %s") % (((printer.MaxJobSize is not None) and (_("%s pages") % printer.MaxJobSize)) or _("Unlimited")))) 
    154157                self.display("    %s\n" % (_("Routed through PyKota : %s") % ((self.isPrinterCaptured(printer.Name) and _("YES")) or _("NO")))) 
    155158                if parents : 
     
    188191 
    189192            if options.maxjobsize : 
    190                 try : 
    191                     maxjobsize = int(options.maxjobsize) 
    192                     if maxjobsize < 0 : 
    193                         raise ValueError 
    194                 except ValueError : 
    195                     raise PyKotaCommandLineError, _("Invalid maximum job size value %s") % options.maxjobsize 
     193                if options.maxjobsize.lower() == "unlimited" : 
     194                    maxjobsize = "unlimited" 
     195                else : 
     196                    try : 
     197                        maxjobsize = int(options.maxjobsize) 
     198                        if maxjobsize < 0 : 
     199                            raise ValueError 
     200                    except ValueError : 
     201                        raise PyKotaCommandLineError, _("Invalid maximum job size value %s") % options.maxjobsize 
    196202            else : 
    197203                maxjobsize = None 
     
    306312    parser.add_option("-m", "--maxjobsize", 
    307313                            dest="maxjobsize", 
    308                             help=_("Set the maximum job size in pages allowed on the specified printers.")) 
     314                            help=_("Set the maximum job size in pages allowed on the specified printers. Accepted values are '0' to forbid printing, 'unlimited' to allow unrestricted printing, or any positive integer value.")) 
    309315    parser.add_option("-n", "--nopassthrough", 
    310316                            action="store_true", 
  • pykota/trunk/bin/pykotme

    r3489 r3549  
    9292                userpquota = self.storage.getUserPQuota(user, printer) 
    9393                if userpquota.Exists : 
    94                     if printer.MaxJobSize and (totalsize > printer.MaxJobSize) : 
     94                    if (printer.MaxJobSize and (totalsize > printer.MaxJobSize)) \ 
     95                            or (userpquota.MaxJobSize and (totalsize > userpquota.MaxJobSize)) : 
    9596                        self.display("%s\n" % (_("User %(username)s is not allowed to print so many pages on printer %(printername)s at this time.") % locals())) 
    9697                    else : 
  • pykota/trunk/cgi-bin/pykotme.cgi

    r3489 r3549  
    182182                                upquota = self.storage.getUserPQuota(user, printer) 
    183183                                if upquota.Exists : 
    184                                     if printer.MaxJobSize and (jobsize > printer.MaxJobSize) : 
     184                                    if (printer.MaxJobSize and (jobsize > printer.MaxJobSize)) \ 
     185                                            or (upquota.MaxJobSize and (jobsize > upquota.MaxJobSize)) : 
    185186                                        msg = _("You are not allowed to print so many pages on printer %s at this time.") % printer.Name 
    186187                                    else : 
  • pykota/trunk/initscripts/ldap/pykota.schema

    r3481 r3549  
    55# LDAP Schema for Pykota Quota System 
    66# 
    7 # (c) 2003-2009 Jerome Alet <alet@librelogiciel.com> 
     7# (c) 2003-2010 Jerome Alet <alet@librelogiciel.com> 
    88# This program is free software: you can redistribute it and/or modify 
    99# it under the terms of the GNU General Public License as published by 
     
    293293 
    294294# pykotaGroupPQuota 
     295# NB : we still allow pykotaMaxJobSize here but 
     296# only to not break existing LDAP directories. 
     297# This attribute is not supported for users groups. 
    295298objectclass ( 1.3.6.1.4.1.16868.1.2.5 NAME 'pykotaGroupPQuota' SUP top AUXILIARY 
    296299        DESC 'PyKota Group Quota on a Printer' 
  • pykota/trunk/initscripts/mysql/pykota-mysql.sql

    r3481 r3549  
    141141                         softlimit INT4, 
    142142                         hardlimit INT4, 
    143                          maxjobsize INT4, 
    144143                         datelimit DATETIME, 
    145144                         INDEX (groupid), 
  • pykota/trunk/initscripts/postgresql/pykota-postgresql.sql

    r3481 r3549  
    129129                         softlimit INT4, 
    130130                         hardlimit INT4, 
    131                          maxjobsize INT4, 
    132131                         datelimit TIMESTAMP); 
    133132CREATE INDEX grouppquota_g_id_ix ON grouppquota (groupid); 
  • pykota/trunk/initscripts/sqlite/pykota-sqlite.sql

    r3481 r3549  
    112112                         softlimit INT4, 
    113113                         hardlimit INT4, 
    114                          maxjobsize INT4, 
    115114                         datelimit TEXT); 
    116115CREATE INDEX grouppquota_g_id_ix ON grouppquota (groupid); 
  • pykota/trunk/pykota/storage.py

    r3526 r3549  
    354354        return jobprice 
    355355 
     356    def setMaxJobSize(self, maxjobsize) : 
     357        """Sets the maximal job size for this print quota entry.""" 
     358        self.MaxJobSize = maxjobsize 
     359        self.isDirty = True 
     360 
    356361    def delete(self) : 
    357362        """Deletes an user print quota entry from the database.""" 
     
    380385        self.HardLimit = None 
    381386        self.DateLimit = None 
    382         self.MaxJobSize = None 
    383387 
    384388    def __getattr__(self, name) : 
  • pykota/trunk/pykota/storages/ldapstorage.py

    r3532 r3549  
    447447            printer.PricePerJob = float(fields.get("pykotaPricePerJob", [0.0])[0]) 
    448448            printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0]) 
    449             printer.MaxJobSize = int(fields.get("pykotaMaxJobSize", [0])[0]) 
     449            printer.MaxJobSize = fields.get("pykotaMaxJobSize") 
     450            if printer.MaxJobSize is not None : 
     451                if printer.MaxJobSize[0].upper() == "NONE" : 
     452                    printer.MaxJobSize = None 
     453                else : 
     454                    printer.MaxJobSize = int(printer.MaxJobSize[0]) 
    450455            printer.PassThrough = fields.get("pykotaPassThrough", [None])[0] 
    451456            if printer.PassThrough in (1, "1", "t", "true", "TRUE", "True") : 
     
    513518            result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaGroupName=%s)(pykotaPrinterName=%s))" % \ 
    514519                                      (unicodeToDatabase(group.Name), unicodeToDatabase(printer.Name)), \ 
    515                                       ["pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaMaxJobSize"], \ 
     520                                      ["pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], \ 
    516521                                      base=base) 
    517522            if result : 
     
    536541                    else : 
    537542                        grouppquota.DateLimit = grouppquota.DateLimit[0] 
    538                 grouppquota.MaxJobSize = fields.get("pykotaMaxJobSize") 
    539                 if grouppquota.MaxJobSize is not None : 
    540                     if grouppquota.MaxJobSize[0].upper() == "NONE" : 
    541                         grouppquota.MaxJobSize = None 
    542                     else : 
    543                         grouppquota.MaxJobSize = int(grouppquota.MaxJobSize[0]) 
    544543                grouppquota.PageCounter = 0 
    545544                grouppquota.LifePageCounter = 0 
     
    712711                    printer.PricePerJob = float(fields.get("pykotaPricePerJob", [0.0])[0] or 0.0) 
    713712                    printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0) 
    714                     printer.MaxJobSize = int(fields.get("pykotaMaxJobSize", [0])[0]) 
     713                    printer.MaxJobSize = fields.get("pykotaMaxJobSize") 
     714                    if printer.MaxJobSize is not None : 
     715                        if printer.MaxJobSize[0].upper() == "NONE" : 
     716                            printer.MaxJobSize = None 
     717                        else : 
     718                            printer.MaxJobSize = int(printer.MaxJobSize[0]) 
    715719                    printer.PassThrough = fields.get("pykotaPassThrough", [None])[0] 
    716720                    if printer.PassThrough in (1, "1", "t", "true", "TRUE", "True") : 
     
    892896                   "pykotaPrinterName" : printername, 
    893897                   "pykotaPassThrough" : (printer.PassThrough and "t") or "f", 
    894                    "pykotaMaxJobSize" : str(printer.MaxJobSize or 0), 
     898                   "pykotaMaxJobSize" : str(printer.MaxJobSize), 
    895899                   "description" : unicodeToDatabase(printer.Description or ""), 
    896900                   "pykotaPricePerPage" : str(printer.PricePerPage or 0.0), 
     
    10701074                   "pykotaLifePageCounter" : str(upq.LifePageCounter or 0), 
    10711075                   "pykotaWarnCount" : str(upq.WarnCount or 0), 
    1072                    "pykotaMaxJobSize" : str(upq.MaxJobSize or 0), 
     1076                   "pykotaMaxJobSize" : str(upq.MaxJobSize), 
    10731077                 } 
    10741078        if self.info["userquotabase"].lower() == "user" : 
     
    11061110        fields = { 
    11071111                   "pykotaPassThrough" : (printer.PassThrough and "t") or "f", 
    1108                    "pykotaMaxJobSize" : str(printer.MaxJobSize or 0), 
     1112                   "pykotaMaxJobSize" : str(printer.MaxJobSize), 
    11091113                   "description" : unicodeToDatabase(printer.Description or ""), 
    11101114                   "pykotaPricePerPage" : str(printer.PricePerPage or 0.0), 
     
    12511255                   "pykotaPageCounter" : str(userpquota.PageCounter or 0), 
    12521256                   "pykotaLifePageCounter" : str(userpquota.LifePageCounter or 0), 
    1253                    "pykotaMaxJobSize" : str(userpquota.MaxJobSize or 0), 
     1257                   "pykotaMaxJobSize" : str(userpquota.MaxJobSize), 
    12541258                 } 
    12551259        self.doModify(userpquota.ident, fields) 
     
    12751279                   "pykotaHardLimit" : str(grouppquota.HardLimit), 
    12761280                   "pykotaDateLimit" : str(grouppquota.DateLimit), 
    1277                    "pykotaMaxJobSize" : str(grouppquota.MaxJobSize or 0), 
    12781281                 } 
    12791282        self.doModify(grouppquota.ident, fields) 
     
    16801683        entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames(pname)] if p.Exists] 
    16811684        if entries : 
    1682             fields = ("username", "printername", "dn", "userdn", "printerdn", "lifepagecounter", "pagecounter", "softlimit", "hardlimit", "datelimit") 
     1685            fields = ("username", "printername", "dn", "userdn", "printerdn", "lifepagecounter", "pagecounter", "softlimit", "hardlimit", "datelimit", "maxjobsize") 
    16831686            result = [] 
    16841687            uname = extractonly.get("username") 
    16851688            for entry in entries : 
    16861689                for (user, userpquota) in self.getPrinterUsersAndQuotas(entry, names=[uname or "*"]) : 
    1687                     result.append((user.Name, entry.Name, userpquota.ident, user.ident, entry.ident, userpquota.LifePageCounter, userpquota.PageCounter, userpquota.SoftLimit, userpquota.HardLimit, userpquota.DateLimit)) 
     1690                    result.append((user.Name, entry.Name, userpquota.ident, user.ident, entry.ident, userpquota.LifePageCounter, userpquota.PageCounter, userpquota.SoftLimit, userpquota.HardLimit, userpquota.DateLimit, userpquota.MaxJobSize)) 
    16881691            return [fields] + self.sortRecords(fields, result, ["+userdn"], ordering) 
    16891692 
  • pykota/trunk/pykota/storages/sql.py

    r3541 r3549  
    6262        printer.PricePerJob = record.get("priceperjob") or 0.0 
    6363        printer.PricePerPage = record.get("priceperpage") or 0.0 
    64         printer.MaxJobSize = record.get("maxjobsize") or 0 
     64        printer.MaxJobSize = record.get("maxjobsize") 
    6565        printer.PassThrough = record.get("passthrough") or 0 
    6666        if printer.PassThrough in (1, "1", "t", "true", "TRUE", "True") : 
     
    119119        userpquota.HardLimit = record.get("hardlimit") 
    120120        userpquota.DateLimit = record.get("datelimit") 
     121        userpquota.MaxJobSize = record.get("maxjobsize") 
    121122        userpquota.WarnCount = record.get("warncount") or 0 
    122123        userpquota.Exists = True 
     
    243244            thefilter = "AND %s" % thefilter 
    244245        orderby = self.createOrderBy(["+grouppquota.id"], ordering) 
    245         result = self.doRawSearch("SELECT groups.groupname,printers.printername,grouppquota.*,coalesce(sum(pagecounter), 0) AS pagecounter,coalesce(sum(lifepagecounter), 0) AS lifepagecounter FROM groups,printers,grouppquota,userpquota WHERE groups.id=grouppquota.groupid AND printers.id=grouppquota.printerid AND userpquota.printerid=grouppquota.printerid AND userpquota.userid IN (SELECT userid FROM groupsmembers WHERE groupsmembers.groupid=grouppquota.groupid) %(thefilter)s GROUP BY grouppquota.id,grouppquota.groupid,grouppquota.printerid,grouppquota.softlimit,grouppquota.hardlimit,grouppquota.datelimit,grouppquota.maxjobsize,groups.groupname,printers.printername ORDER BY %(orderby)s" % locals()) 
     246        result = self.doRawSearch("SELECT groups.groupname,printers.printername,grouppquota.*,coalesce(sum(pagecounter), 0) AS pagecounter,coalesce(sum(lifepagecounter), 0) AS lifepagecounter FROM groups,printers,grouppquota,userpquota WHERE groups.id=grouppquota.groupid AND printers.id=grouppquota.printerid AND userpquota.printerid=grouppquota.printerid AND userpquota.userid IN (SELECT userid FROM groupsmembers WHERE groupsmembers.groupid=grouppquota.groupid) %(thefilter)s GROUP BY grouppquota.id,grouppquota.groupid,grouppquota.printerid,grouppquota.softlimit,grouppquota.hardlimit,grouppquota.datelimit,groups.groupname,printers.printername ORDER BY %(orderby)s" % locals()) 
    246247        return self.prepareRawResult(result) 
    247248 
     
    560561                          % (self.doQuote(unicodeToDatabase(printer.Name)), \ 
    561562                             self.doQuote((printer.PassThrough and "t") or "f"), \ 
    562                              self.doQuote(printer.MaxJobSize or 0), \ 
     563                             self.doQuote(printer.MaxJobSize), \ 
    563564                             self.doQuote(unicodeToDatabase(printer.Description)), \ 
    564565                             self.doQuote(printer.PricePerPage or 0.0), \ 
     
    650651        if oldentry.Exists : 
    651652            return oldentry 
    652         self.doModify("INSERT INTO grouppquota (groupid, printerid, softlimit, hardlimit, datelimit, maxjobsize) VALUES (%s, %s, %s, %s, %s, %s)" \ 
     653        self.doModify("INSERT INTO grouppquota (groupid, printerid, softlimit, hardlimit, datelimit) VALUES (%s, %s, %s, %s, %s)" \ 
    653654                          % (self.doQuote(gpq.Group.ident), \ 
    654655                             self.doQuote(gpq.Printer.ident), \ 
    655656                             self.doQuote(gpq.SoftLimit), \ 
    656657                             self.doQuote(gpq.HardLimit), \ 
    657                              self.doQuote(gpq.DateLimit), \ 
    658                              self.doQuote(gpq.MaxJobSize))) 
     658                             self.doQuote(gpq.DateLimit))) 
    659659        gpq.isDirty = False 
    660660        return None # the entry created doesn't need further modification 
     
    664664        self.doModify("UPDATE printers SET passthrough=%s, maxjobsize=%s, description=%s, priceperpage=%s, priceperjob=%s WHERE id=%s" \ 
    665665                              % (self.doQuote((printer.PassThrough and "t") or "f"), \ 
    666                                  self.doQuote(printer.MaxJobSize or 0), \ 
     666                                 self.doQuote(printer.MaxJobSize), \ 
    667667                                 self.doQuote(unicodeToDatabase(printer.Description)), \ 
    668668                                 self.doQuote(printer.PricePerPage or 0.0), \ 
  • pykota/trunk/pykota/version.py

    r3547 r3549  
    2424import time 
    2525 
    26 __version__ = "1.27alpha12_unofficial" 
     26__version__ = "1.27alpha13_unofficial" 
    2727 
    2828__doc__ = "PyKota : a complete Printing Quota Solution for CUPS."