Changeset 2054 for pykota/trunk/bin

Show
Ignore:
Timestamp:
02/13/05 23:02:29 (19 years ago)
Author:
jalet
Message:

Big database structure changes. Upgrade script is now included as well as
the new LDAP schema.
Introduction of the -o | --overcharge command line option to edpykota.
The output of repykota is more complete, but doesn't fit in 80 columns anymore.
Introduction of the new 'maxdenybanners' directive.

Location:
pykota/trunk/bin
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r2028 r2054  
    2424# 
    2525# $Log$ 
     26# Revision 1.85  2005/02/13 22:02:28  jalet 
     27# Big database structure changes. Upgrade script is now included as well as 
     28# the new LDAP schema. 
     29# Introduction of the -o | --overcharge command line option to edpykota. 
     30# The output of repykota is more complete, but doesn't fit in 80 columns anymore. 
     31# Introduction of the new 'maxdenybanners' directive. 
     32# 
    2633# Revision 1.84  2005/01/17 08:44:23  jalet 
    2734# Modified copyright years 
     
    501508            accountbanner = self.config.getAccountBanner(printer.Name) 
    502509            if accountbanner in ["ENDING", "NONE"] : 
    503                 banner = self.startingBanner(printer.Name) 
    504                 if banner : 
    505                     self.logdebug("Printing starting banner before accounting begins.") 
    506                     self.handleData(banner) 
     510                if (action == 'DENY') and (userpquota.WarnCount < self.config.getMaxDenyBanners()) : 
     511                    self.printInfo(_("Banner won't be printed : maximum number of deny banners reached."), "warn") 
     512                else : 
     513                    if action == 'DENY' : 
     514                        userpquota.warn() # increments the warning counter 
     515                        self.exportUserInfo(userpquota) 
     516                    banner = self.startingBanner(printer.Name) 
     517                    if banner : 
     518                        self.logdebug("Printing starting banner before accounting begins.") 
     519                        self.handleData(banner) 
    507520  
    508521            self.printMoreInfo(user, printer, _("Job accounting begins.")) 
     
    511524            # handle starting banner pages during accounting 
    512525            if accountbanner in ["STARTING", "BOTH"] : 
    513                 banner = self.startingBanner(printer.Name) 
    514                 if banner : 
    515                     self.logdebug("Printing starting banner during accounting.") 
    516                     self.handleData(banner) 
    517                     if self.accounter.isSoftware : 
    518                         bannersize += 1 # TODO : fix this by passing the banner's content through PDLAnalyzer 
     526                if (action == 'DENY') and (userpquota.WarnCount < self.config.getMaxDenyBanners()) : 
     527                    self.printInfo(_("Banner won't be printed : maximum number of deny banners reached."), "warn") 
     528                else : 
     529                    if action == 'DENY' : 
     530                        userpquota.warn() # increments the warning counter 
     531                        self.exportUserInfo(userpquota) 
     532                    banner = self.startingBanner(printer.Name) 
     533                    if banner : 
     534                        self.logdebug("Printing starting banner during accounting.") 
     535                        self.handleData(banner) 
     536                        if self.accounter.isSoftware : 
     537                            bannersize += 1 # TODO : fix this by passing the banner's content through PDLAnalyzer 
    519538        else :     
    520539            action = "ALLOW" 
     
    536555            # handle ending banner pages during accounting 
    537556            if accountbanner in ["ENDING", "BOTH"] : 
    538                 banner = self.endingBanner(printer.Name) 
    539                 if banner : 
    540                     self.logdebug("Printing ending banner during accounting.") 
    541                     self.handleData(banner) 
    542                     if self.accounter.isSoftware : 
    543                         bannersize += 1 # TODO : fix this by passing the banner's content through PDLAnalyzer 
     557                if (action == 'DENY') and (userpquota.WarnCount < self.config.getMaxDenyBanners()) : 
     558                    self.printInfo(_("Banner won't be printed : maximum number of deny banners reached."), "warn") 
     559                else : 
     560                    if action == 'DENY' : 
     561                        userpquota.warn() # increments the warning counter 
     562                        self.exportUserInfo(userpquota) 
     563                    banner = self.endingBanner(printer.Name) 
     564                    if banner : 
     565                        self.logdebug("Printing ending banner during accounting.") 
     566                        self.handleData(banner) 
     567                        if self.accounter.isSoftware : 
     568                            bannersize += 1 # TODO : fix this by passing the banner's content through PDLAnalyzer 
    544569  
    545570            # stops accounting.  
     
    575600            # handle ending banner pages after accounting ends 
    576601            if accountbanner in ["STARTING", "NONE"] : 
    577                 banner = self.endingBanner(printer.Name) 
    578                 if banner : 
    579                     self.logdebug("Printing ending banner after accounting ends.") 
    580                     self.handleData(banner) 
    581              
     602                if (action == 'DENY') and (userpquota.WarnCount < self.config.getMaxDenyBanners()) : 
     603                    self.printInfo(_("Banner won't be printed : maximum number of deny banners reached."), "warn") 
     604                else : 
     605                    if action == 'DENY' : 
     606                        userpquota.warn() # increments the warning counter 
     607                        self.exportUserInfo(userpquota) 
     608                    banner = self.endingBanner(printer.Name) 
     609                    if banner : 
     610                        self.logdebug("Printing ending banner after accounting ends.") 
     611                        self.handleData(banner) 
     612                         
    582613            # Launches the post hook 
    583614            self.posthook(userpquota) 
     
    823854            try : 
    824855                status = subprocess.wait() 
    825             except OSError : # already dead     
     856            except OSError : # already dead : TODO : detect when abnormal 
    826857                status = 0 
    827858        if os.WIFEXITED(status) : 
  • pykota/trunk/bin/edpykota

    r2036 r2054  
    2424# 
    2525# $Log$ 
     26# Revision 1.87  2005/02/13 22:02:28  jalet 
     27# Big database structure changes. Upgrade script is now included as well as 
     28# the new LDAP schema. 
     29# Introduction of the -o | --overcharge command line option to edpykota. 
     30# The output of repykota is more complete, but doesn't fit in 80 columns anymore. 
     31# Introduction of the new 'maxdenybanners' directive. 
     32# 
    2633# Revision 1.86  2005/01/21 14:40:01  jalet 
    2734# edpykota's --delete command line tool doesn't use "*" as its default argument 
     
    337344                       If both are to be set, separate them with a comma. 
    338345                       Floating point values are allowed. 
     346                        
     347  -o | --overcharge f  Sets the overcharging factor applied to the user  
     348                       when computing the cost of a print job. Positive or  
     349                       negative floating point values are allowed, 
     350                       this allows you to do some really creative 
     351                       things like giving money to an user whenever 
     352                       he prints. The number of pages in a print job 
     353                       is not modified by this coefficient, only the 
     354                       cost of the job for a particular user. 
     355                       Only users have a coefficient. 
    339356   
    340357  -i | --ingroups g1[,g2...]  Puts the users into each of the groups 
     
    480497  When printing either on hplj1 or hplj2, print quota will also be  
    481498  checked and accounted for on virtual printers Laser and HP. 
     499   
     500  $ edpykota --overcharge 2.5 poorstudent 
     501   
     502  This will overcharge the poorstudent user by a factor of 2.5. 
     503   
     504  $ edpykota --overcharge -1 jerome 
     505   
     506  User jerome will actually earn money whenever he prints. 
     507   
     508  $ edpykota --overcharge 0 boss 
     509   
     510  User boss can print at will, it won't cost him anything because the 
     511  cost of each print job will be multiplied by zero before charging 
     512  his account. 
    482513 
    483514This program is free software; you can redistribute it and/or modify 
     
    532563                (softlimit, hardlimit) = (hardlimit, softlimit) 
    533564             
     565        overcharge = options["overcharge"] 
     566        if overcharge : 
     567            try : 
     568                overcharge = float(overcharge.strip()) 
     569            except (ValueError, AttributeError) :     
     570                raise PyKotaToolError, _("Invalid overcharge value %s") % options["overcharge"] 
     571                 
    534572        balance = options["balance"] 
    535573        if balance : 
     
    710748                            entrypquota.setUsage(used) 
    711749                             
     750                        if overcharge is not None :     
     751                            if changed[entry.Name].get("overcharge") is None : 
     752                                entry.setOverChargeFactor(overcharge) 
     753                                changed[entry.Name]["overcharge"] = overcharge 
     754                                 
    712755                        if balance : 
    713756                            if changed[entry.Name].get("balance") is None : 
     
    742785                     "printer" : "*", \ 
    743786                   } 
    744         short_options = "vhdc:l:b:i:naugrp:P:S:H:G:RU:" 
    745         long_options = ["help", "version", "charge=", "delete", "limitby=", "balance=", "ingroups=", "noquota", "add", "users", "groups", "reset", "hardreset", "prototype=", "printer=", "softlimit=", "hardlimit=", "pgroups=", "used="] 
     787        short_options = "vhdo:c:l:b:i:naugrp:P:S:H:G:RU:" 
     788        long_options = ["help", "version", "overcharge=", "charge=", "delete", "limitby=", "balance=", "ingroups=", "noquota", "add", "users", "groups", "reset", "hardreset", "prototype=", "printer=", "softlimit=", "hardlimit=", "pgroups=", "used="] 
    746789         
    747790        # Initializes the command line tool 
     
    771814        options["hardreset"] = options["R"] or options["hardreset"]  
    772815        options["used"] = options["U"] or options["used"] 
     816        options["overcharge"] = options["o"] or options["overcharge"] 
    773817         
    774818        if options["help"] : 
     
    784828        elif options["noquota"] and (options["prototype"] or options["hardlimit"] or options["softlimit"]) : 
    785829            raise PyKotaToolError, _("incompatible options, see help.") 
    786         elif options["groups"] and (options["balance"] or options["ingroups"] or options["used"]) : 
     830        elif options["groups"] and (options["balance"] or options["ingroups"] or options["used"] or options["overcharge"]) : 
    787831            raise PyKotaToolError, _("incompatible options, see help.") 
    788832        else :