Changeset 3549 for pykota/trunk/bin

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/bin
Files:
4 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 :