Changeset 952

Show
Ignore:
Timestamp:
04/24/03 00:13:57 (21 years ago)
Author:
jalet
Message:

Preliminary support for LPRng added BUT STILL UNTESTED.

Location:
pykota/trunk
Files:
44 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/edpykota

    r937 r952  
    33# PyKota Print Quota Editor  
    44# 
    5 # PyKota - Print Quotas for CUPS 
     5# PyKota - Print Quotas for CUPS and LPRng 
    66# 
    77# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2323# 
    2424# $Log$ 
     25# Revision 1.43  2003/04/23 22:13:56  jalet 
     26# Preliminary support for LPRng added BUT STILL UNTESTED. 
     27# 
    2528# Revision 1.42  2003/04/17 13:38:47  jalet 
    2629# Docstring corrected for better manual page 
     
    252255  user jerome is put into the groups "coders" and "it" which must 
    253256  already exist in the Quota Storage. 
    254   WARNING : the CUPS PPD file for this printer must still be modified 
    255             manually, as well as pykota's configuration file for a 
    256             new printer to be managed successfully. 
     257  WARNING : the CUPS PPD file for this printer or the /etc/printcap 
     258            file (depending on your printing backend)  must still be  
     259            modified manually, as well as pykota's configuration file 
     260            for a new printer to be managed successfully. 
    257261             
    258262  $ edpykota -g -S 500 -H 550 financial support             
     
    474478                                if groupid is not None : 
    475479                                    self.storage.addUserToGroup(ident, groupid) 
     480                                else : 
     481                                    self.logger.log_message(_("Group %s not found in the PyKota Storage.") % groupname) 
    476482                            self.warnUserPQuota(name, printer)     
    477483                      
  • pykota/trunk/bin/pykota

    r915 r952  
    33# PyKota accounting filter 
    44# 
    5 # PyKota - Print Quotas for CUPS 
     5# PyKota - Print Quotas for CUPS and LPRng 
    66# 
    77# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2323# 
    2424# $Log$ 
     25# Revision 1.24  2003/04/23 22:13:56  jalet 
     26# Preliminary support for LPRng added BUT STILL UNTESTED. 
     27# 
    2528# Revision 1.23  2003/04/15 11:30:57  jalet 
    2629# More work done on money print charging. 
     
    115118class PyKotaFilter(PyKotaTool) :     
    116119    """Class for the PyKota filter.""" 
    117     def __init__(self, username) : 
     120    def __init__(self) : 
    118121        PyKotaTool.__init__(self) 
    119         self.username = username 
     122        (self.printingsystem, self.printerhostname, self.printername, self.username, self.jobid, self.inputfile) = self.extractInfoFromCupsOrLprng() 
    120123        self.requester = openRequester(self.config, self.printername) 
    121         self.printerhostname = self.getPrinterHostname() 
    122      
    123     def getPrinterHostname(self) : 
    124         """Returns the printer hostname.""" 
    125         device_uri = os.environ.get("DEVICE_URI", "") 
    126         # TODO : check this for more complex urls than ipp://myprinter.dot.com:631/printers/lp 
    127         try : 
    128             (backend, destination) = device_uri.split(":", 1)  
    129         except ValueError :     
    130             raise PyKotaToolError, "Invalid DEVICE_URI : %s\n" % device_uri 
    131         while destination.startswith("/") : 
    132             destination = destination[1:] 
    133         return destination.split("/")[0].split(":")[0] 
    134          
     124     
    135125    def filterInput(self, inputfile) : 
    136126        """Transparent filter.""" 
     
    148138            infile.close() 
    149139             
     140    def acceptJob(self) :         
     141        """Returns the exit code needed by the printing backend to accept the job and print it.""" 
     142        if self.printingsystem == "CUPS" : 
     143            return 0 
     144        elif self.printingsystem == "LPRNG" :     
     145            return 0 
     146        else :     
     147            # UNKNOWN 
     148            return -1 
     149             
     150    def removeJob(self) :             
     151        """Returns the exit code needed by the printing backend to refuse the job and remove it.""" 
     152        if self.printingsystem == "CUPS" : 
     153            return 1 
     154        elif self.printingsystem == "LPRNG" :     
     155            return 3 
     156        else :     
     157            # UNKNOWN 
     158            return -1 
     159             
    150160def main() :     
    151161    """Do it, and do it right !""" 
     162         
     163    # Initializes the current tool 
     164    kotafilter = PyKotaFilter()     
     165     
    152166    # 
    153     # This is a CUPS filter, so we should act and die like a CUPS filter when needed 
    154     narg = len(sys.argv) 
    155     if narg not in (6, 7) :     
    156         sys.stderr.write("ERROR: %s job-id user title copies options [file]\n" % sys.argv[0]) 
    157         return 1 
    158     elif narg == 7 :     
    159         # input file 
    160         inputfile = sys.argv[6] 
    161     else :     
    162         # stdin 
    163         inputfile = None 
    164          
    165     #     
    166     # According to CUPS documentation, the job id is the second command line argument 
    167     jobid = sys.argv[1].strip() 
    168      
    169     #     
    170     # According to CUPS documentation, the username is the third command line argument 
    171     username = sys.argv[2].strip()     
    172      
    173     # Initializes the current tool 
    174     kotafilter = PyKotaFilter(username)     
     167    # If this is a CUPS filter, we should act and die like a CUPS filter when needed 
     168    if kotafilter.printingsystem == "CUPS" : 
     169        if len(sys.argv) not in (6, 7) :     
     170            sys.stderr.write("ERROR: %s job-id user title copies options [file]\n" % sys.argv[0]) 
     171            return kotafilter.removeJob() 
    175172     
    176173    # Get the page counter directly from the printer itself 
    177174    try : 
    178         counterbeforejob = kotafilter.requester.getPrinterPageCounter(kotafilter.printerhostname) # TODO use printername instead, make them match from CUPS' config files 
     175        counterbeforejob = kotafilter.requester.getPrinterPageCounter(kotafilter.printerhostname) 
    179176    except PyKotaRequesterError, msg : 
    180177        # can't get actual page counter, assume printer is off, but warns in log 
     
    192189        kotafilter.logger.log_message(_("Printer %s not registered in the PyKota system") % kotafilter.printername, "warn") 
    193190    else :     
    194         userid = kotafilter.storage.getUserId(username) 
     191        userid = kotafilter.storage.getUserId(kotafilter.username) 
    195192        if userid is None : 
    196193            # The user is unknown from the Quota Storage perspective 
    197             # we let the job pass through, but log a warning message 
    198             kotafilter.logger.log_message(_("User %s not registered in the PyKota system") % username, "warn") 
     194            # Depending on the default policy for this printer, we 
     195            # either let the job pass through or reject it, but we 
     196            # log a message in any case. 
     197            policy = kotafilter.config.getPrinterPolicy(kotafilter.printername) 
     198            if policy in [None, "ALLOW"] : 
     199                action = "POLICY_ALLOW" 
     200            else :     
     201                action = "POLICY_DENY" 
     202            kotafilter.logger.log_message(_("User %s not registered in the PyKota system, applying default policy (%s) for printer %s") % (kotafilter.username, action, kotafilter.printername), "warn") 
     203            if action == "POLICY_DENY" : 
     204                return kotafilter.removeJob() 
    199205        else : 
    200206            # get last job information for this printer 
     
    203209                # The printer hasn't been used yet, from PyKota's point of view 
    204210                lasthistoryid = None 
    205                 lastjobid = jobid 
     211                lastjobid = kotafilter.jobid 
    206212                lastuserid = userid 
    207                 lastusername = username 
     213                lastusername = kotafilter.username 
    208214                lastpagecounter = counterbeforejob 
    209215            else :     
     
    251257             
    252258            # warns the last user if he is over quota 
    253             kotafilter.warnUserPQuota(lastusername) 
     259            kotafilter.warnUserPQuota(lastusername, kotafilter.printername) 
    254260                 
    255261            # Is the current user allowed to print at all ? 
    256             action = kotafilter.warnUserPQuota(username) 
     262            action = kotafilter.warnUserPQuota(kotafilter.username, kotafilter.printername) 
    257263             
    258264            # adds the current job to history     
    259             kotafilter.storage.addJobToHistory(jobid, kotafilter.storage.getUserId(username), printerid, counterbeforejob, action) 
     265            kotafilter.storage.addJobToHistory(kotafilter.jobid, kotafilter.storage.getUserId(kotafilter.username), printerid, counterbeforejob, action) 
    260266             
    261267            # if not allowed to print then die, else proceed. 
    262268            if action == "DENY" : 
    263269                # No, just die cleanly 
    264                 return 1 
     270                return kotafilter.removeJob() 
    265271         
    266272    # pass the job untouched to the underlying layer 
    267     kotafilter.filterInput(inputfile)       
    268      
    269     return 0 
     273    kotafilter.filterInput(kotafilter.inputfile)       
     274     
     275    return kotafilter.acceptJob() 
    270276 
    271277if __name__ == "__main__" :     
    272     sys.exit(main() or 0) 
     278    sys.exit(main()) 
  • pykota/trunk/bin/README

    r873 r952  
    11# $Id$ 
    22 
    3 PyKota - Print Quota for CUPS 
     3PyKota - Print Quota for CUPS and LPRng 
    44 
    55(c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/bin/repykota

    r950 r952  
    33# PyKota Print Quota Reports generator 
    44# 
    5 # PyKota - Print Quotas for CUPS 
     5# PyKota - Print Quotas for CUPS and LPRng 
    66# 
    77# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2323# 
    2424# $Log$ 
     25# Revision 1.32  2003/04/23 22:13:56  jalet 
     26# Preliminary support for LPRng added BUT STILL UNTESTED. 
     27# 
    2528# Revision 1.31  2003/04/23 09:58:17  jalet 
    2629# Prices per page/job are now displayed 
  • pykota/trunk/bin/warnpykota

    r934 r952  
    33# PyKota Print Quota Warning sender 
    44# 
    5 # PyKota - Print Quotas for CUPS 
     5# PyKota - Print Quotas for CUPS and LPRng 
    66# 
    77# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2323# 
    2424# $Log$ 
     25# Revision 1.18  2003/04/23 22:13:56  jalet 
     26# Preliminary support for LPRng added BUT STILL UNTESTED. 
     27# 
    2528# Revision 1.17  2003/04/17 13:32:17  jalet 
    2629# bad documentation string 
  • pykota/trunk/cgi-bin/printquota.cgi

    r941 r952  
    33# PyKota Print Quota Reports generator 
    44# 
    5 # PyKota - Print Quotas for CUPS 
     5# PyKota - Print Quotas for CUPS and LPRng 
    66# 
    77# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2323# 
    2424# $Log$ 
     25# Revision 1.6  2003/04/23 22:13:56  jalet 
     26# Preliminary support for LPRng added BUT STILL UNTESTED. 
     27# 
    2528# Revision 1.5  2003/04/17 21:30:09  jalet 
    2629# Now includes the logo 
  • pykota/trunk/cgi-bin/README

    r873 r952  
    11# $Id$ 
    22 
    3 PyKota - Print Quota for CUPS 
     3PyKota - Print Quota for CUPS and LPRng 
    44 
    55(c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/conf/pykota.conf.sample

    r919 r952  
    44# usually /etc/cups under the name pykota.conf 
    55# 
    6 # PyKota - Print Quotas for CUPS 
     6# PyKota - Print Quotas for CUPS and LPRng 
    77# 
    88# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    3030storagebackend: postgresql 
    3131 
    32 # Quota Storage Server hostname (and port) 
     32# Quota Storage Server hostname (and optional port) 
    3333# e.g. db.mydomain.com:5432 
    3434storageserver: localhost 
     
    100100# 
    101101# Another example, for AppleTalk printers which works fine : 
    102 # (You need the pap CUPS backend installed, and copy the  
    103 # pagecount.ps file from untested/netatalk into /etc) 
     102# (You may need the pap CUPS backend installed, and copy the  
     103# pagecount.ps file from untested/netatalk into /etc or any  
     104# appropriate location) 
    104105#     requester: external(/usr/bin/pap -p "%(printer)s:LaserWriter" /etc/pagecount.ps  2>/dev/null | grep -v status | grep -v Connect) 
    105106# 
  • pykota/trunk/conf/README

    r873 r952  
    11# $Id$ 
    22 
    3 PyKota - Print Quota for CUPS 
     3PyKota - Print Quota for CUPS and LPRng 
    44 
    55(c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/debian/README

    r873 r952  
    11# $Id$ 
    22 
    3 PyKota - Print Quota for CUPS 
     3PyKota - Print Quota for CUPS and LPRng 
    44 
    55(c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/initscripts/pykota-postgresql.sql

    r915 r952  
    11-- 
    2 -- PyKota - Print Quotas for CUPS 
     2-- PyKota - Print Quotas for CUPS and LPRng 
    33-- 
    44-- (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2020-- 
    2121-- $Log$ 
     22-- Revision 1.14  2003/04/23 22:13:56  jalet 
     23-- Preliminary support for LPRng added BUT STILL UNTESTED. 
     24-- 
    2225-- Revision 1.13  2003/04/15 11:30:57  jalet 
    2326-- More work done on money print charging. 
  • pykota/trunk/initscripts/README

    r951 r952  
    11# $Id$ 
    22 
    3 PyKota - Print Quota for CUPS 
     3PyKota - Print Quota for CUPS and LPRng 
    44 
    55(c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/initscripts/README.postgresql

    r951 r952  
    11# $Id$ 
    22 
    3 PyKota - Print Quota for CUPS 
     3PyKota - Print Quota for CUPS and LPRng 
    44 
    55(c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/initscripts/upgrade-from-before-1.03.py

    r951 r952  
    33# PyKota Print Quota Warning sender 
    44# 
    5 # PyKota - Print Quotas for CUPS 
     5# PyKota - Print Quotas for CUPS and LPRng 
    66# 
    77# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/initscripts/VERYOLDpykota-upgrade-postgresql.sql

    r942 r952  
    11-- 
    2 -- PyKota - Print Quotas for CUPS 
     2-- PyKota - Print Quotas for CUPS and LPRng 
    33-- 
    44-- (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2020-- 
    2121-- $Log$ 
     22-- Revision 1.2  2003/04/23 22:13:56  jalet 
     23-- Preliminary support for LPRng added BUT STILL UNTESTED. 
     24-- 
    2225-- Revision 1.1  2003/04/17 21:33:16  jalet 
    2326-- Version 1.03 is out. 
  • pykota/trunk/LICENSE

    r873 r952  
    11# $Id$ 
    22 
    3 PyKota - Print Quota for CUPS 
     3PyKota - Print Quota for CUPS and LPRng 
    44 
    55(c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/logos/README

    r932 r952  
    11# $Id$ 
    22 
    3 PyKota - Print Quota for CUPS 
     3PyKota - Print Quota for CUPS and LPRng 
    44 
    55(c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/man/README

    r873 r952  
    11# $Id$ 
    22 
    3 PyKota - Print Quota for CUPS 
     3PyKota - Print Quota for CUPS and LPRng 
    44 
    55(c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/NEWS

    r950 r952  
    2222PyKota NEWS : 
    2323 
     24    - 1.04pre2 : 
     25     
     26        - Preliminary support for LPRng added (still untested) 
     27         
    2428    - 1.04pre1 : 
    2529     
  • pykota/trunk/po/en/pykota.po

    r950 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222# $Log$ 
     23# Revision 1.21  2003/04/23 22:13:56  jalet 
     24# Preliminary support for LPRng added BUT STILL UNTESTED. 
     25# 
    2326# Revision 1.20  2003/04/23 09:58:17  jalet 
    2427# Prices per page/job are now displayed 
     
    274277msgstr "" 
    275278 
    276 msgid "User %s not registered in the PyKota system" 
     279msgid "User %s not registered in the PyKota system, applying default policy (%s) for printer %s" 
    277280msgstr "" 
    278281 
     
    319322msgid "Price per page: %.3f" 
    320323msgstr "" 
     324 
     325msgid "Group %s not found in the PyKota Storage." 
     326msgstr "" 
  • pykota/trunk/po/fr/pykota.po

    r950 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222# $Log$ 
     23# Revision 1.20  2003/04/23 22:13:57  jalet 
     24# Preliminary support for LPRng added BUT STILL UNTESTED. 
     25# 
    2326# Revision 1.19  2003/04/23 09:58:17  jalet 
    2427# Prices per page/job are now displayed 
     
    283286msgstr "Fichier de configuration %s non trouv� 
    284287 
    285 msgid "User %s not registered in the PyKota system" 
    286 msgstr "Utilisateur %s non enregistr�ans le syst� PyKota" 
     288msgid "User %s not registered in the PyKota system, applying default policy (%s) for printer %s" 
     289msgstr "Utilisateur %s non enregistr�ans le syst� PyKota, action par d�ut (%s) appliqu�sur l'imprimante %s" 
    287290 
    288291msgid "Invalid charge amount value %s" 
     
    332335msgid "Price per page: %.3f" 
    333336msgstr "Prix par page: %.3f" 
     337 
     338msgid "Group %s not found in the PyKota Storage." 
     339msgstr "Groupe %s non trouv�ans le Quota Storage." 
  • pykota/trunk/po/pykota.pot

    r950 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222# $Log$ 
     23# Revision 1.21  2003/04/23 22:13:56  jalet 
     24# Preliminary support for LPRng added BUT STILL UNTESTED. 
     25# 
    2326# Revision 1.20  2003/04/23 09:58:17  jalet 
    2427# Prices per page/job are now displayed 
     
    274277msgstr "" 
    275278 
    276 msgid "User %s not registered in the PyKota system" 
     279msgid "User %s not registered in the PyKota system, applying default policy (%s) for printer %s" 
    277280msgstr "" 
    278281 
     
    319322msgid "Price per page: %.3f" 
    320323msgstr "" 
     324 
     325msgid "Group %s not found in the PyKota Storage." 
     326msgstr "" 
  • pykota/trunk/po/README

    r873 r952  
    11# $Id$ 
    22 
    3 PyKota - Print Quota for CUPS 
     3PyKota - Print Quota for CUPS and LPRng 
    44 
    55(c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/pykota/config.py

    r873 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222# $Log$ 
     23# Revision 1.22  2003/04/23 22:13:57  jalet 
     24# Preliminary support for LPRng added BUT STILL UNTESTED. 
     25# 
    2326# Revision 1.21  2003/03/29 13:45:27  jalet 
    2427# GPL paragraphs were incorrectly (from memory) copied into the sources. 
  • pykota/trunk/pykota/__init__.py

    r873 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/pykota/logger.py

    r873 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222# $Log$ 
     23# Revision 1.6  2003/04/23 22:13:57  jalet 
     24# Preliminary support for LPRng added BUT STILL UNTESTED. 
     25# 
    2326# Revision 1.5  2003/03/29 13:45:27  jalet 
    2427# GPL paragraphs were incorrectly (from memory) copied into the sources. 
  • pykota/trunk/pykota/loggers/__init__.py

    r873 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/pykota/loggers/stderr.py

    r873 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222# $Log$ 
     23# Revision 1.3  2003/04/23 22:13:57  jalet 
     24# Preliminary support for LPRng added BUT STILL UNTESTED. 
     25# 
    2326# Revision 1.2  2003/03/29 13:45:27  jalet 
    2427# GPL paragraphs were incorrectly (from memory) copied into the sources. 
  • pykota/trunk/pykota/loggers/system.py

    r873 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222# $Log$ 
     23# Revision 1.6  2003/04/23 22:13:57  jalet 
     24# Preliminary support for LPRng added BUT STILL UNTESTED. 
     25# 
    2326# Revision 1.5  2003/03/29 13:45:27  jalet 
    2427# GPL paragraphs were incorrectly (from memory) copied into the sources. 
  • pykota/trunk/pykota/requester.py

    r873 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222# $Log$ 
     23# Revision 1.7  2003/04/23 22:13:57  jalet 
     24# Preliminary support for LPRng added BUT STILL UNTESTED. 
     25# 
    2326# Revision 1.6  2003/03/29 13:45:27  jalet 
    2427# GPL paragraphs were incorrectly (from memory) copied into the sources. 
  • pykota/trunk/pykota/requesters/external.py

    r873 r952  
    1 #! /usr/bin/env python 
    2  
    3 # PyKota - Print Quotas for CUPS 
     1# PyKota 
     2# 
     3# PyKota - Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222# $Log$ 
     23# Revision 1.7  2003/04/23 22:13:57  jalet 
     24# Preliminary support for LPRng added BUT STILL UNTESTED. 
     25# 
    2326# Revision 1.6  2003/03/29 13:45:27  jalet 
    2427# GPL paragraphs were incorrectly (from memory) copied into the sources. 
  • pykota/trunk/pykota/requesters/__init__.py

    r873 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/pykota/requesters/snmp.py

    r873 r952  
    1 #! /usr/bin/env python 
    2  
    3 # PyKota - Print Quotas for CUPS 
     1# PyKota 
     2# 
     3# PyKota - Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222# $Log$ 
     23# Revision 1.8  2003/04/23 22:13:57  jalet 
     24# Preliminary support for LPRng added BUT STILL UNTESTED. 
     25# 
    2326# Revision 1.7  2003/03/29 13:45:27  jalet 
    2427# GPL paragraphs were incorrectly (from memory) copied into the sources. 
  • pykota/trunk/pykota/storage.py

    r900 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222# $Log$ 
     23# Revision 1.12  2003/04/23 22:13:57  jalet 
     24# Preliminary support for LPRng added BUT STILL UNTESTED. 
     25# 
    2326# Revision 1.11  2003/04/10 21:47:20  jalet 
    2427# Job history added. Upgrade script neutralized for now ! 
  • pykota/trunk/pykota/storages/__init__.py

    r873 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/pykota/storages/postgresql.py

    r915 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222# $Log$ 
     23# Revision 1.8  2003/04/23 22:13:57  jalet 
     24# Preliminary support for LPRng added BUT STILL UNTESTED. 
     25# 
    2326# Revision 1.7  2003/04/15 11:30:57  jalet 
    2427# More work done on money print charging. 
  • pykota/trunk/pykota/storages/sql.py

    r929 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222# $Log$ 
     23# Revision 1.29  2003/04/23 22:13:57  jalet 
     24# Preliminary support for LPRng added BUT STILL UNTESTED. 
     25# 
    2326# Revision 1.28  2003/04/17 09:26:21  jalet 
    2427# repykota now reports account balances too. 
  • pykota/trunk/pykota/tool.py

    r929 r952  
    11#! /usr/bin/env python 
    22 
    3 # PyKota - Print Quotas for CUPS 
     3# PyKota - Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222# $Log$ 
     23# Revision 1.35  2003/04/23 22:13:57  jalet 
     24# Preliminary support for LPRng added BUT STILL UNTESTED. 
     25# 
    2326# Revision 1.34  2003/04/17 09:26:21  jalet 
    2427# repykota now reports account balances too. 
     
    183186        self.logger = logger.openLogger(self.config) 
    184187        self.storage = storage.openConnection(self.config, asadmin=asadmin) 
    185         self.printername = os.environ.get("PRINTER", None) 
    186188        self.smtpserver = self.config.getSMTPServer() 
     189         
     190    def extractInfoFromCupsOrLprng(self) :     
     191        """Returns a tuple (printingsystem, printerhostname, printername, username, jobid, filename) depending on the printing system in use (as seen by the print filter). 
     192         
     193           Returns (None, None, None, None, None, None) if no printing system is recognized. 
     194        """ 
     195        # Try to detect CUPS 
     196        if os.environ.has_key("CUPS_SERVERROOT") and os.path.isdir(os.environ.get("CUPS_SERVERROOT", "")) : 
     197            if len(sys.argv) == 7 : 
     198                inputfile = sys.argv[6] 
     199            else :     
     200                inputfile = None 
     201                 
     202            device_uri = os.environ.get("DEVICE_URI", "") 
     203            # TODO : check this for more complex urls than ipp://myprinter.dot.com:631/printers/lp 
     204            try : 
     205                (backend, destination) = device_uri.split(":", 1)  
     206            except ValueError :     
     207                raise PyKotaToolError, "Invalid DEVICE_URI : %s\n" % device_uri 
     208            while destination.startswith("/") : 
     209                destination = destination[1:] 
     210            printerhostname = destination.split("/")[0].split(":")[0] 
     211            return ("CUPS", printerhostname, os.environ.get("PRINTER"), sys.argv[2].strip(), sys.argv[1].strip(), inputfile) 
     212        else :     
     213            # Try to detect LPRng 
     214            jseen = Jseen = Pseen = nseen = rseen = None 
     215            for arg in sys.argv : 
     216                if arg.startswith("-j") : 
     217                    jseen = arg[2:].strip() 
     218                elif arg.startswith("-J") :     
     219                    Jseen = arg[2:].strip() 
     220                    if Jseen == "(STDIN)" : 
     221                        Jseen = None 
     222                elif arg.startswith("-n") :      
     223                    nseen = arg[2:].strip() 
     224                elif arg.startswith("-P") :     
     225                    Pseen = arg[2:].strip() 
     226                elif arg.startswith("-r") :     
     227                    rseen = arg[2:].strip() 
     228            if jseen and Jseen and Pseen and nseen and rseen :         
     229                return ("LPRNG", rseen, Pseen, nseen, jseen, Jseen) 
     230        return (None, None, None, None, None, None)   # Unknown printing system           
    187231         
    188232    def display_version_and_quit(self) : 
     
    296340        """Checks the group quota on a printer and deny or accept the job.""" 
    297341        printerid = self.storage.getPrinterId(printername) 
     342        policy = self.config.getPrinterPolicy(printername) 
    298343        groupid = self.storage.getGroupId(groupname) 
    299344        limitby = self.storage.getGroupLimitBy(groupid) 
     
    301346            balance = self.storage.getGroupBalance(groupid) 
    302347            if balance is None : 
    303                 policy = self.config.getPrinterPolicy(printername) 
    304348                if policy in [None, "ALLOW"] : 
    305349                    action = "POLICY_ALLOW" 
     
    318362            if quota is None : 
    319363                # Unknown group or printer or combination 
    320                 policy = self.config.getPrinterPolicy(printername) 
    321364                if policy in [None, "ALLOW"] : 
    322365                    action = "POLICY_ALLOW" 
     
    373416        # then we check the user's own quota 
    374417        printerid = self.storage.getPrinterId(printername) 
     418        policy = self.config.getPrinterPolicy(printername) 
    375419        limitby = self.storage.getUserLimitBy(userid) 
    376420        if limitby == "balance" :  
    377421            balance = self.storage.getUserBalance(userid) 
    378422            if balance is None : 
    379                 policy = self.config.getPrinterPolicy(printername) 
    380423                if policy in [None, "ALLOW"] : 
    381424                    action = "POLICY_ALLOW" 
     
    394437            if quota is None : 
    395438                # Unknown user or printer or combination 
    396                 policy = self.config.getPrinterPolicy(printername) 
    397439                if policy in [None, "ALLOW"] : 
    398440                    action = "POLICY_ALLOW" 
     
    438480        return action 
    439481     
    440     def warnGroupPQuota(self, groupname, printername=None) : 
     482    def warnGroupPQuota(self, groupname, printername) : 
    441483        """Checks a group quota and send messages if quota is exceeded on current printer.""" 
    442         pname = printername or self.printername 
    443         admin = self.config.getAdmin(pname) 
    444         adminmail = self.config.getAdminMail(pname) 
    445         mailto = self.config.getMailTo(pname) 
    446         action = self.checkGroupPQuota(groupname, pname) 
     484        admin = self.config.getAdmin(printername) 
     485        adminmail = self.config.getAdminMail(printername) 
     486        mailto = self.config.getMailTo(printername) 
     487        action = self.checkGroupPQuota(groupname, printername) 
    447488        groupmembers = self.storage.getGroupMembersNames(groupname) 
    448489        if action.startswith("POLICY_") : 
    449490            action = action[7:] 
    450491        if action == "DENY" : 
    451             adminmessage = _("Print Quota exceeded for group %s on printer %s") % (groupname, pname) 
     492            adminmessage = _("Print Quota exceeded for group %s on printer %s") % (groupname, printername) 
    452493            self.logger.log_message(adminmessage) 
    453494            if mailto in [ "BOTH", "ADMIN" ] : 
     
    455496            for username in groupmembers : 
    456497                if mailto in [ "BOTH", "USER" ] : 
    457                     self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You are not allowed to print anymore because\nyour group Print Quota is exceeded on printer %s.") % pname) 
     498                    self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You are not allowed to print anymore because\nyour group Print Quota is exceeded on printer %s.") % printername) 
    458499        elif action == "WARN" :     
    459             adminmessage = _("Print Quota soft limit exceeded for group %s on printer %s") % (groupname, pname) 
     500            adminmessage = _("Print Quota soft limit exceeded for group %s on printer %s") % (groupname, printername) 
    460501            self.logger.log_message(adminmessage) 
    461502            if mailto in [ "BOTH", "ADMIN" ] : 
     
    463504            for username in groupmembers : 
    464505                if mailto in [ "BOTH", "USER" ] : 
    465                     self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You will soon be forbidden to print anymore because\nyour group Print Quota is almost reached on printer %s.") % pname) 
     506                    self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You will soon be forbidden to print anymore because\nyour group Print Quota is almost reached on printer %s.") % printername) 
    466507        return action         
    467508         
    468     def warnUserPQuota(self, username, printername=None) : 
     509    def warnUserPQuota(self, username, printername) : 
    469510        """Checks a user quota and send him a message if quota is exceeded on current printer.""" 
    470         pname = printername or self.printername 
    471         admin = self.config.getAdmin(pname) 
    472         adminmail = self.config.getAdminMail(pname) 
    473         mailto = self.config.getMailTo(pname) 
    474         action = self.checkUserPQuota(username, pname) 
     511        admin = self.config.getAdmin(printername) 
     512        adminmail = self.config.getAdminMail(printername) 
     513        mailto = self.config.getMailTo(printername) 
     514        action = self.checkUserPQuota(username, printername) 
    475515        if action.startswith("POLICY_") : 
    476516            action = action[7:] 
    477517        if action == "DENY" : 
    478             adminmessage = _("Print Quota exceeded for user %s on printer %s") % (username, pname) 
     518            adminmessage = _("Print Quota exceeded for user %s on printer %s") % (username, printername) 
    479519            self.logger.log_message(adminmessage) 
    480520            if mailto in [ "BOTH", "USER" ] : 
    481                 self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s.") % pname) 
     521                self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s.") % printername) 
    482522            if mailto in [ "BOTH", "ADMIN" ] : 
    483523                self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 
    484524        elif action == "WARN" :     
    485             adminmessage = _("Print Quota soft limit exceeded for user %s on printer %s") % (username, pname) 
     525            adminmessage = _("Print Quota soft limit exceeded for user %s on printer %s") % (username, printername) 
    486526            self.logger.log_message(adminmessage) 
    487527            if mailto in [ "BOTH", "USER" ] : 
    488                 self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You will soon be forbidden to print anymore because\nyour Print Quota is almost reached on printer %s.") % pname) 
     528                self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You will soon be forbidden to print anymore because\nyour Print Quota is almost reached on printer %s.") % printername) 
    489529            if mailto in [ "BOTH", "ADMIN" ] : 
    490530                self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 
  • pykota/trunk/pykota/version.py

    r950 r952  
    11# PyKota 
    22# 
    3 # PyKota : Print Quotas for CUPS 
     3# PyKota : Print Quotas for CUPS and LPRng 
    44# 
    55# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2121# 
    2222 
    23 __version__ = "1.04pre1-unofficial" 
     23__version__ = "1.04pre2-unofficial" 
    2424 
    25 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS.""" 
     25__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng.""" 
    2626 
    2727__author__ = """Jerome Alet - alet@librelogiciel.com""" 
  • pykota/trunk/README

    r942 r952  
    11# $Id$ 
    22 
    3 PyKota - Print Quota for CUPS 
     3PyKota - Print Quota for CUPS and LPRng 
    44 
    55(c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2525 
    2626PyKota is a complete Print Quota system for the Common Unix Printing 
    27 System (aka CUPS), which works by directly querying the printers 
    28 for the number of pages they have printed. 
     27System (aka CUPS) or LPR Next Generation (LPRng), which works by directly  
     28querying the printers for the number of pages they have printed. 
    2929 
    3030Actual working features : 
    3131 
     32        - Supports both CUPS and LPRng backends. 
     33         
    3234        - Per printer user and group quotas. 
    3335         
     
    3537          user himself and to the print quota administrator. 
    3638         
    37         - CUPS filter for quota accounting : pykota 
     39        - Filter for quota accounting : pykota 
    3840         
    3941        - Command line print quota editor : edpykota 
     
    101103  of a new job and before the end of the previous job. This depends on  
    102104  the printer speed and time between jobs, but so far I've not seen  
    103   any problem with moderately used printers. This also depends on CUPS  
    104   internal behavior : if CUPS doesn't begin to send a job to a printer  
    105   before the previous one is completely printed, then there's no  
    106   problem.  
     105  any problem with moderately used printers. This also depends on the 
     106  printing system's internal behavior : if it doesn't begin to send a  
     107  job to a printer before the previous one is completely printed, then  
     108  there's no problem.  
    107109   
    108110  Other querying methods which won't suffer from this possible  
     
    140142  You need to have the following tools installed on the CUPS Server : 
    141143   
    142     - CUPS 
     144    - CUPS or LPRng 
    143145    - Python v2.1 or above 
    144146    - eGenix' mxDateTime Python extension 
     
    155157    - PostgreSQL 
    156158     
    157   PygreSQL and the PostgreSQL client libraries's versions on the CUPS  
     159  PygreSQL and the PostgreSQL client libraries's versions on the Print 
    158160  Server must match the PostgreSQL version used on the Quota Storage  
    159161  Server. 
     
    163165  alternatives. 
    164166   
    165   Of course the CUPS Server and the Quota Storage Server can be the  
     167  Of course the Print Server and the Quota Storage Server can be the  
    166168  very same machine if you've got a tiny network, or you can have  
    167   multiple CUPS Servers all storing their quotas on the same Quota  
     169  multiple Print Servers all storing their quotas on the same Quota  
    168170  Storage Server if you've got a bigger network.  
    169171   
     
    196198you if needed and you agreed to this action. 
    197199 
    198 Modify the PPD files for each printer on which you want to manage 
    199 print quotas, for example /etc/cups/ppd/lp.ppd : 
    200  
    201 --- Add the line below exactly as-is somewhere near the top --- 
    202 *cupsFilter:  "application/vnd.cups-postscript 0 /usr/bin/pykota" 
    203 --- Add the line above exactly as-is somewhere near the top  --- 
    204  
    205 Modify the path to the pykota executable if needed, unfortunately  
    206 you have to supply the correct absolute path here due to CUPS  
    207 internals, or put the pykota executable into /usr/lib/cups/filter  
    208 instead of into /usr/bin.  
    209  
    210 Do this for each ppd file present in this directory if you want 
    211 to enable quota on every printer. 
    212            
    213 WARNING : In the case you've got a non-postscript printer, chances 
    214           are that the *cupsFilter is already filled-in and points 
    215           to cupsomatic or such a print filter. In this case please 
    216           check if you can switch your printer to PostScript mode 
    217           or if there's a way to make it accept PostScript jobs. 
    218           If yes then ensure that your workstations uses a PostScript 
    219           printer driver, and replace the *cupsFilter line with the 
    220           one pointing to the pykota filter. This should work, but 
    221           is currently untested. 
    222           If your printer really needs the original *cupsFilter line 
    223           then you may not be able to use PyKota easily for now. 
    224  
     200  - CUPS Print Backend : 
     201   
     202    Modify the PPD files for each printer on which you want to manage 
     203    print quotas, for example /etc/cups/ppd/lp.ppd : 
     204     
     205    --- Add the line below exactly as-is somewhere near the top --- 
     206    *cupsFilter:  "application/vnd.cups-postscript 0 /usr/bin/pykota" 
     207    --- Add the line above exactly as-is somewhere near the top  --- 
     208     
     209    Modify the path to the pykota executable if needed, unfortunately  
     210    you have to supply the correct absolute path here due to CUPS  
     211    internals, or put the pykota executable into /usr/lib/cups/filter  
     212    instead of into /usr/bin.  
     213     
     214    Do this for each ppd file present in this directory if you want 
     215    to enable quota on every printer. 
     216               
     217    WARNING : In the case you've got a non-postscript printer, chances 
     218              are that the *cupsFilter is already filled-in and points 
     219              to cupsomatic or such a print filter. In this case please 
     220              check if you can switch your printer to PostScript mode 
     221              or if there's a way to make it accept PostScript jobs. 
     222              If yes then ensure that your workstations uses a PostScript 
     223              printer driver, and replace the *cupsFilter line with the 
     224              one pointing to the pykota filter. This should work, but 
     225              is currently untested. 
     226              If your printer really needs the original *cupsFilter line 
     227              then you may not be able to use PyKota easily for now. 
     228 
     229  - LPRng Print Backend : 
     230   
     231    Modify the /etc/printcap file to add two lines identical to these ones : 
     232     
     233    :achk=true 
     234    :as=|/usr/bin/pykota 
     235     
     236    For each printer on which you want to use print accounting. 
     237   
    225238Add printers and users to the quota system and set their quota values :  
    226239 
     
    261274           should make you reasonably safe. 
    262275            
     276           also please ensure that only the printing daemon user 
     277           can launch the pykota command. Again this is not enforced 
     278           in the program. 
     279            
    263280============================================================ 
    264281 
  • pykota/trunk/setup.py

    r940 r952  
    33# PyKota 
    44# 
    5 # PyKota : Print Quotas for CUPS 
     5# PyKota : Print Quotas for CUPS and LPRng 
    66# 
    77# (c) 2003 Jerome Alet <alet@librelogiciel.com> 
     
    2323# 
    2424# $Log$ 
     25# Revision 1.12  2003/04/23 22:13:56  jalet 
     26# Preliminary support for LPRng added BUT STILL UNTESTED. 
     27# 
    2528# Revision 1.11  2003/04/17 13:49:29  jalet 
    2629# Typo 
  • pykota/trunk/TODO

    r927 r952  
    11# $Id$ 
    22 
    3 PyKota - Print Quota for CUPS 
     3PyKota - Print Quota for CUPS and LPRng 
    44 
    55(c) 2003 Jerome Alet <alet@librelogiciel.com> 
  • pykota/trunk/untested/README

    r873 r952  
    11# $Id$ 
    22 
    3 PyKota - Print Quota for CUPS 
     3PyKota - Print Quota for CUPS and LPRng 
    44 
    55(c) 2003 Jerome Alet <alet@librelogiciel.com>