Index: /pykota/trunk/debian/README
===================================================================
--- /pykota/trunk/debian/README (revision 873)
+++ /pykota/trunk/debian/README (revision 952)
@@ -1,5 +1,5 @@
 # $Id$
 
-PyKota - Print Quota for CUPS
+PyKota - Print Quota for CUPS and LPRng
 
 (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/LICENSE
===================================================================
--- /pykota/trunk/LICENSE (revision 873)
+++ /pykota/trunk/LICENSE (revision 952)
@@ -1,5 +1,5 @@
 # $Id$
 
-PyKota - Print Quota for CUPS
+PyKota - Print Quota for CUPS and LPRng
 
 (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/logos/README
===================================================================
--- /pykota/trunk/logos/README (revision 932)
+++ /pykota/trunk/logos/README (revision 952)
@@ -1,5 +1,5 @@
 # $Id$
 
-PyKota - Print Quota for CUPS
+PyKota - Print Quota for CUPS and LPRng
 
 (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/conf/pykota.conf.sample
===================================================================
--- /pykota/trunk/conf/pykota.conf.sample (revision 919)
+++ /pykota/trunk/conf/pykota.conf.sample (revision 952)
@@ -4,5 +4,5 @@
 # usually /etc/cups under the name pykota.conf
 #
-# PyKota - Print Quotas for CUPS
+# PyKota - Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -30,5 +30,5 @@
 storagebackend: postgresql
 
-# Quota Storage Server hostname (and port)
+# Quota Storage Server hostname (and optional port)
 # e.g. db.mydomain.com:5432
 storageserver: localhost
@@ -100,6 +100,7 @@
 #
 # Another example, for AppleTalk printers which works fine :
-# (You need the pap CUPS backend installed, and copy the 
-# pagecount.ps file from untested/netatalk into /etc)
+# (You may need the pap CUPS backend installed, and copy the 
+# pagecount.ps file from untested/netatalk into /etc or any 
+# appropriate location)
 #     requester: external(/usr/bin/pap -p "%(printer)s:LaserWriter" /etc/pagecount.ps  2>/dev/null | grep -v status | grep -v Connect)
 #
Index: /pykota/trunk/conf/README
===================================================================
--- /pykota/trunk/conf/README (revision 873)
+++ /pykota/trunk/conf/README (revision 952)
@@ -1,5 +1,5 @@
 # $Id$
 
-PyKota - Print Quota for CUPS
+PyKota - Print Quota for CUPS and LPRng
 
 (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/setup.py
===================================================================
--- /pykota/trunk/setup.py (revision 940)
+++ /pykota/trunk/setup.py (revision 952)
@@ -3,5 +3,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.12  2003/04/23 22:13:56  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.11  2003/04/17 13:49:29  jalet
 # Typo
Index: /pykota/trunk/untested/README
===================================================================
--- /pykota/trunk/untested/README (revision 873)
+++ /pykota/trunk/untested/README (revision 952)
@@ -1,5 +1,5 @@
 # $Id$
 
-PyKota - Print Quota for CUPS
+PyKota - Print Quota for CUPS and LPRng
 
 (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/README
===================================================================
--- /pykota/trunk/README (revision 942)
+++ /pykota/trunk/README (revision 952)
@@ -1,5 +1,5 @@
 # $Id$
 
-PyKota - Print Quota for CUPS
+PyKota - Print Quota for CUPS and LPRng
 
 (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -25,9 +25,11 @@
 
 PyKota is a complete Print Quota system for the Common Unix Printing
-System (aka CUPS), which works by directly querying the printers
-for the number of pages they have printed.
+System (aka CUPS) or LPR Next Generation (LPRng), which works by directly 
+querying the printers for the number of pages they have printed.
 
 Actual working features :
 
+        - Supports both CUPS and LPRng backends.
+        
         - Per printer user and group quotas.
         
@@ -35,5 +37,5 @@
           user himself and to the print quota administrator.
         
-        - CUPS filter for quota accounting : pykota
+        - Filter for quota accounting : pykota
         
         - Command line print quota editor : edpykota
@@ -101,8 +103,8 @@
   of a new job and before the end of the previous job. This depends on 
   the printer speed and time between jobs, but so far I've not seen 
-  any problem with moderately used printers. This also depends on CUPS 
-  internal behavior : if CUPS doesn't begin to send a job to a printer 
-  before the previous one is completely printed, then there's no 
-  problem. 
+  any problem with moderately used printers. This also depends on the
+  printing system's internal behavior : if it doesn't begin to send a 
+  job to a printer before the previous one is completely printed, then 
+  there's no problem. 
   
   Other querying methods which won't suffer from this possible 
@@ -140,5 +142,5 @@
   You need to have the following tools installed on the CUPS Server :
   
-    - CUPS
+    - CUPS or LPRng
     - Python v2.1 or above
     - eGenix' mxDateTime Python extension
@@ -155,5 +157,5 @@
     - PostgreSQL
     
-  PygreSQL and the PostgreSQL client libraries's versions on the CUPS 
+  PygreSQL and the PostgreSQL client libraries's versions on the Print
   Server must match the PostgreSQL version used on the Quota Storage 
   Server.
@@ -163,7 +165,7 @@
   alternatives.
   
-  Of course the CUPS Server and the Quota Storage Server can be the 
+  Of course the Print Server and the Quota Storage Server can be the 
   very same machine if you've got a tiny network, or you can have 
-  multiple CUPS Servers all storing their quotas on the same Quota 
+  multiple Print Servers all storing their quotas on the same Quota 
   Storage Server if you've got a bigger network. 
   
@@ -196,31 +198,42 @@
 you if needed and you agreed to this action.
 
-Modify the PPD files for each printer on which you want to manage
-print quotas, for example /etc/cups/ppd/lp.ppd :
-
---- Add the line below exactly as-is somewhere near the top ---
-*cupsFilter:  "application/vnd.cups-postscript 0 /usr/bin/pykota"
---- Add the line above exactly as-is somewhere near the top  ---
-
-Modify the path to the pykota executable if needed, unfortunately 
-you have to supply the correct absolute path here due to CUPS 
-internals, or put the pykota executable into /usr/lib/cups/filter 
-instead of into /usr/bin. 
-
-Do this for each ppd file present in this directory if you want
-to enable quota on every printer.
-          
-WARNING : In the case you've got a non-postscript printer, chances
-          are that the *cupsFilter is already filled-in and points
-          to cupsomatic or such a print filter. In this case please
-          check if you can switch your printer to PostScript mode
-          or if there's a way to make it accept PostScript jobs.
-          If yes then ensure that your workstations uses a PostScript
-          printer driver, and replace the *cupsFilter line with the
-          one pointing to the pykota filter. This should work, but
-          is currently untested.
-          If your printer really needs the original *cupsFilter line
-          then you may not be able to use PyKota easily for now.
-
+  - CUPS Print Backend :
+  
+    Modify the PPD files for each printer on which you want to manage
+    print quotas, for example /etc/cups/ppd/lp.ppd :
+    
+    --- Add the line below exactly as-is somewhere near the top ---
+    *cupsFilter:  "application/vnd.cups-postscript 0 /usr/bin/pykota"
+    --- Add the line above exactly as-is somewhere near the top  ---
+    
+    Modify the path to the pykota executable if needed, unfortunately 
+    you have to supply the correct absolute path here due to CUPS 
+    internals, or put the pykota executable into /usr/lib/cups/filter 
+    instead of into /usr/bin. 
+    
+    Do this for each ppd file present in this directory if you want
+    to enable quota on every printer.
+              
+    WARNING : In the case you've got a non-postscript printer, chances
+              are that the *cupsFilter is already filled-in and points
+              to cupsomatic or such a print filter. In this case please
+              check if you can switch your printer to PostScript mode
+              or if there's a way to make it accept PostScript jobs.
+              If yes then ensure that your workstations uses a PostScript
+              printer driver, and replace the *cupsFilter line with the
+              one pointing to the pykota filter. This should work, but
+              is currently untested.
+              If your printer really needs the original *cupsFilter line
+              then you may not be able to use PyKota easily for now.
+
+  - LPRng Print Backend :
+  
+    Modify the /etc/printcap file to add two lines identical to these ones :
+    
+    :achk=true
+    :as=|/usr/bin/pykota
+    
+    For each printer on which you want to use print accounting.
+  
 Add printers and users to the quota system and set their quota values : 
 
@@ -261,4 +274,8 @@
            should make you reasonably safe.
            
+           also please ensure that only the printing daemon user
+           can launch the pykota command. Again this is not enforced
+           in the program.
+           
 ============================================================
 
Index: /pykota/trunk/TODO
===================================================================
--- /pykota/trunk/TODO (revision 927)
+++ /pykota/trunk/TODO (revision 952)
@@ -1,5 +1,5 @@
 # $Id$
 
-PyKota - Print Quota for CUPS
+PyKota - Print Quota for CUPS and LPRng
 
 (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/pykota/loggers/__init__.py
===================================================================
--- /pykota/trunk/pykota/loggers/__init__.py (revision 873)
+++ /pykota/trunk/pykota/loggers/__init__.py (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/pykota/loggers/stderr.py
===================================================================
--- /pykota/trunk/pykota/loggers/stderr.py (revision 873)
+++ /pykota/trunk/pykota/loggers/stderr.py (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.3  2003/04/23 22:13:57  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.2  2003/03/29 13:45:27  jalet
 # GPL paragraphs were incorrectly (from memory) copied into the sources.
Index: /pykota/trunk/pykota/loggers/system.py
===================================================================
--- /pykota/trunk/pykota/loggers/system.py (revision 873)
+++ /pykota/trunk/pykota/loggers/system.py (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.6  2003/04/23 22:13:57  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.5  2003/03/29 13:45:27  jalet
 # GPL paragraphs were incorrectly (from memory) copied into the sources.
Index: /pykota/trunk/pykota/requesters/snmp.py
===================================================================
--- /pykota/trunk/pykota/requesters/snmp.py (revision 873)
+++ /pykota/trunk/pykota/requesters/snmp.py (revision 952)
@@ -1,5 +1,5 @@
-#! /usr/bin/env python
-
-# PyKota - Print Quotas for CUPS
+# PyKota
+#
+# PyKota - Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.8  2003/04/23 22:13:57  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.7  2003/03/29 13:45:27  jalet
 # GPL paragraphs were incorrectly (from memory) copied into the sources.
Index: /pykota/trunk/pykota/requesters/__init__.py
===================================================================
--- /pykota/trunk/pykota/requesters/__init__.py (revision 873)
+++ /pykota/trunk/pykota/requesters/__init__.py (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/pykota/requesters/external.py
===================================================================
--- /pykota/trunk/pykota/requesters/external.py (revision 873)
+++ /pykota/trunk/pykota/requesters/external.py (revision 952)
@@ -1,5 +1,5 @@
-#! /usr/bin/env python
-
-# PyKota - Print Quotas for CUPS
+# PyKota
+#
+# PyKota - Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.7  2003/04/23 22:13:57  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.6  2003/03/29 13:45:27  jalet
 # GPL paragraphs were incorrectly (from memory) copied into the sources.
Index: /pykota/trunk/pykota/tool.py
===================================================================
--- /pykota/trunk/pykota/tool.py (revision 929)
+++ /pykota/trunk/pykota/tool.py (revision 952)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
 
-# PyKota - Print Quotas for CUPS
+# PyKota - Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.35  2003/04/23 22:13:57  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.34  2003/04/17 09:26:21  jalet
 # repykota now reports account balances too.
@@ -183,6 +186,47 @@
         self.logger = logger.openLogger(self.config)
         self.storage = storage.openConnection(self.config, asadmin=asadmin)
-        self.printername = os.environ.get("PRINTER", None)
         self.smtpserver = self.config.getSMTPServer()
+        
+    def extractInfoFromCupsOrLprng(self) :    
+        """Returns a tuple (printingsystem, printerhostname, printername, username, jobid, filename) depending on the printing system in use (as seen by the print filter).
+        
+           Returns (None, None, None, None, None, None) if no printing system is recognized.
+        """
+        # Try to detect CUPS
+        if os.environ.has_key("CUPS_SERVERROOT") and os.path.isdir(os.environ.get("CUPS_SERVERROOT", "")) :
+            if len(sys.argv) == 7 :
+                inputfile = sys.argv[6]
+            else :    
+                inputfile = None
+                
+            device_uri = os.environ.get("DEVICE_URI", "")
+            # TODO : check this for more complex urls than ipp://myprinter.dot.com:631/printers/lp
+            try :
+                (backend, destination) = device_uri.split(":", 1) 
+            except ValueError :    
+                raise PyKotaToolError, "Invalid DEVICE_URI : %s\n" % device_uri
+            while destination.startswith("/") :
+                destination = destination[1:]
+            printerhostname = destination.split("/")[0].split(":")[0]
+            return ("CUPS", printerhostname, os.environ.get("PRINTER"), sys.argv[2].strip(), sys.argv[1].strip(), inputfile)
+        else :    
+            # Try to detect LPRng
+            jseen = Jseen = Pseen = nseen = rseen = None
+            for arg in sys.argv :
+                if arg.startswith("-j") :
+                    jseen = arg[2:].strip()
+                elif arg.startswith("-J") :    
+                    Jseen = arg[2:].strip()
+                    if Jseen == "(STDIN)" :
+                        Jseen = None
+                elif arg.startswith("-n") :     
+                    nseen = arg[2:].strip()
+                elif arg.startswith("-P") :    
+                    Pseen = arg[2:].strip()
+                elif arg.startswith("-r") :    
+                    rseen = arg[2:].strip()
+            if jseen and Jseen and Pseen and nseen and rseen :        
+                return ("LPRNG", rseen, Pseen, nseen, jseen, Jseen)
+        return (None, None, None, None, None, None)   # Unknown printing system          
         
     def display_version_and_quit(self) :
@@ -296,4 +340,5 @@
         """Checks the group quota on a printer and deny or accept the job."""
         printerid = self.storage.getPrinterId(printername)
+        policy = self.config.getPrinterPolicy(printername)
         groupid = self.storage.getGroupId(groupname)
         limitby = self.storage.getGroupLimitBy(groupid)
@@ -301,5 +346,4 @@
             balance = self.storage.getGroupBalance(groupid)
             if balance is None :
-                policy = self.config.getPrinterPolicy(printername)
                 if policy in [None, "ALLOW"] :
                     action = "POLICY_ALLOW"
@@ -318,5 +362,4 @@
             if quota is None :
                 # Unknown group or printer or combination
-                policy = self.config.getPrinterPolicy(printername)
                 if policy in [None, "ALLOW"] :
                     action = "POLICY_ALLOW"
@@ -373,9 +416,9 @@
         # then we check the user's own quota
         printerid = self.storage.getPrinterId(printername)
+        policy = self.config.getPrinterPolicy(printername)
         limitby = self.storage.getUserLimitBy(userid)
         if limitby == "balance" : 
             balance = self.storage.getUserBalance(userid)
             if balance is None :
-                policy = self.config.getPrinterPolicy(printername)
                 if policy in [None, "ALLOW"] :
                     action = "POLICY_ALLOW"
@@ -394,5 +437,4 @@
             if quota is None :
                 # Unknown user or printer or combination
-                policy = self.config.getPrinterPolicy(printername)
                 if policy in [None, "ALLOW"] :
                     action = "POLICY_ALLOW"
@@ -438,16 +480,15 @@
         return action
     
-    def warnGroupPQuota(self, groupname, printername=None) :
+    def warnGroupPQuota(self, groupname, printername) :
         """Checks a group quota and send messages if quota is exceeded on current printer."""
-        pname = printername or self.printername
-        admin = self.config.getAdmin(pname)
-        adminmail = self.config.getAdminMail(pname)
-        mailto = self.config.getMailTo(pname)
-        action = self.checkGroupPQuota(groupname, pname)
+        admin = self.config.getAdmin(printername)
+        adminmail = self.config.getAdminMail(printername)
+        mailto = self.config.getMailTo(printername)
+        action = self.checkGroupPQuota(groupname, printername)
         groupmembers = self.storage.getGroupMembersNames(groupname)
         if action.startswith("POLICY_") :
             action = action[7:]
         if action == "DENY" :
-            adminmessage = _("Print Quota exceeded for group %s on printer %s") % (groupname, pname)
+            adminmessage = _("Print Quota exceeded for group %s on printer %s") % (groupname, printername)
             self.logger.log_message(adminmessage)
             if mailto in [ "BOTH", "ADMIN" ] :
@@ -455,7 +496,7 @@
             for username in groupmembers :
                 if mailto in [ "BOTH", "USER" ] :
-                    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)
+                    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)
         elif action == "WARN" :    
-            adminmessage = _("Print Quota soft limit exceeded for group %s on printer %s") % (groupname, pname)
+            adminmessage = _("Print Quota soft limit exceeded for group %s on printer %s") % (groupname, printername)
             self.logger.log_message(adminmessage)
             if mailto in [ "BOTH", "ADMIN" ] :
@@ -463,28 +504,27 @@
             for username in groupmembers :
                 if mailto in [ "BOTH", "USER" ] :
-                    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)
+                    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)
         return action        
         
-    def warnUserPQuota(self, username, printername=None) :
+    def warnUserPQuota(self, username, printername) :
         """Checks a user quota and send him a message if quota is exceeded on current printer."""
-        pname = printername or self.printername
-        admin = self.config.getAdmin(pname)
-        adminmail = self.config.getAdminMail(pname)
-        mailto = self.config.getMailTo(pname)
-        action = self.checkUserPQuota(username, pname)
+        admin = self.config.getAdmin(printername)
+        adminmail = self.config.getAdminMail(printername)
+        mailto = self.config.getMailTo(printername)
+        action = self.checkUserPQuota(username, printername)
         if action.startswith("POLICY_") :
             action = action[7:]
         if action == "DENY" :
-            adminmessage = _("Print Quota exceeded for user %s on printer %s") % (username, pname)
+            adminmessage = _("Print Quota exceeded for user %s on printer %s") % (username, printername)
             self.logger.log_message(adminmessage)
             if mailto in [ "BOTH", "USER" ] :
-                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)
+                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)
             if mailto in [ "BOTH", "ADMIN" ] :
                 self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage)
         elif action == "WARN" :    
-            adminmessage = _("Print Quota soft limit exceeded for user %s on printer %s") % (username, pname)
+            adminmessage = _("Print Quota soft limit exceeded for user %s on printer %s") % (username, printername)
             self.logger.log_message(adminmessage)
             if mailto in [ "BOTH", "USER" ] :
-                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)
+                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)
             if mailto in [ "BOTH", "ADMIN" ] :
                 self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage)
Index: /pykota/trunk/pykota/__init__.py
===================================================================
--- /pykota/trunk/pykota/__init__.py (revision 873)
+++ /pykota/trunk/pykota/__init__.py (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/pykota/logger.py
===================================================================
--- /pykota/trunk/pykota/logger.py (revision 873)
+++ /pykota/trunk/pykota/logger.py (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.6  2003/04/23 22:13:57  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.5  2003/03/29 13:45:27  jalet
 # GPL paragraphs were incorrectly (from memory) copied into the sources.
Index: /pykota/trunk/pykota/requester.py
===================================================================
--- /pykota/trunk/pykota/requester.py (revision 873)
+++ /pykota/trunk/pykota/requester.py (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.7  2003/04/23 22:13:57  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.6  2003/03/29 13:45:27  jalet
 # GPL paragraphs were incorrectly (from memory) copied into the sources.
Index: /pykota/trunk/pykota/storages/__init__.py
===================================================================
--- /pykota/trunk/pykota/storages/__init__.py (revision 873)
+++ /pykota/trunk/pykota/storages/__init__.py (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/pykota/storages/sql.py
===================================================================
--- /pykota/trunk/pykota/storages/sql.py (revision 929)
+++ /pykota/trunk/pykota/storages/sql.py (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.29  2003/04/23 22:13:57  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.28  2003/04/17 09:26:21  jalet
 # repykota now reports account balances too.
Index: /pykota/trunk/pykota/storages/postgresql.py
===================================================================
--- /pykota/trunk/pykota/storages/postgresql.py (revision 915)
+++ /pykota/trunk/pykota/storages/postgresql.py (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.8  2003/04/23 22:13:57  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.7  2003/04/15 11:30:57  jalet
 # More work done on money print charging.
Index: /pykota/trunk/pykota/storage.py
===================================================================
--- /pykota/trunk/pykota/storage.py (revision 900)
+++ /pykota/trunk/pykota/storage.py (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.12  2003/04/23 22:13:57  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.11  2003/04/10 21:47:20  jalet
 # Job history added. Upgrade script neutralized for now !
Index: /pykota/trunk/pykota/config.py
===================================================================
--- /pykota/trunk/pykota/config.py (revision 873)
+++ /pykota/trunk/pykota/config.py (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.22  2003/04/23 22:13:57  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.21  2003/03/29 13:45:27  jalet
 # GPL paragraphs were incorrectly (from memory) copied into the sources.
Index: /pykota/trunk/pykota/version.py
===================================================================
--- /pykota/trunk/pykota/version.py (revision 950)
+++ /pykota/trunk/pykota/version.py (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,7 +21,7 @@
 #
 
-__version__ = "1.04pre1-unofficial"
+__version__ = "1.04pre2-unofficial"
 
-__doc__ = """PyKota : a complete Printing Quota Solution for CUPS."""
+__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
 
 __author__ = """Jerome Alet - alet@librelogiciel.com"""
Index: /pykota/trunk/cgi-bin/printquota.cgi
===================================================================
--- /pykota/trunk/cgi-bin/printquota.cgi (revision 941)
+++ /pykota/trunk/cgi-bin/printquota.cgi (revision 952)
@@ -3,5 +3,5 @@
 # PyKota Print Quota Reports generator
 #
-# PyKota - Print Quotas for CUPS
+# PyKota - Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.6  2003/04/23 22:13:56  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.5  2003/04/17 21:30:09  jalet
 # Now includes the logo
Index: /pykota/trunk/cgi-bin/README
===================================================================
--- /pykota/trunk/cgi-bin/README (revision 873)
+++ /pykota/trunk/cgi-bin/README (revision 952)
@@ -1,5 +1,5 @@
 # $Id$
 
-PyKota - Print Quota for CUPS
+PyKota - Print Quota for CUPS and LPRng
 
 (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/bin/warnpykota
===================================================================
--- /pykota/trunk/bin/warnpykota (revision 934)
+++ /pykota/trunk/bin/warnpykota (revision 952)
@@ -3,5 +3,5 @@
 # PyKota Print Quota Warning sender
 #
-# PyKota - Print Quotas for CUPS
+# PyKota - Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.18  2003/04/23 22:13:56  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.17  2003/04/17 13:32:17  jalet
 # bad documentation string
Index: /pykota/trunk/bin/edpykota
===================================================================
--- /pykota/trunk/bin/edpykota (revision 937)
+++ /pykota/trunk/bin/edpykota (revision 952)
@@ -3,5 +3,5 @@
 # PyKota Print Quota Editor 
 #
-# PyKota - Print Quotas for CUPS
+# PyKota - Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.43  2003/04/23 22:13:56  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.42  2003/04/17 13:38:47  jalet
 # Docstring corrected for better manual page
@@ -252,7 +255,8 @@
   user jerome is put into the groups "coders" and "it" which must
   already exist in the Quota Storage.
-  WARNING : the CUPS PPD file for this printer must still be modified
-            manually, as well as pykota's configuration file for a
-            new printer to be managed successfully.
+  WARNING : the CUPS PPD file for this printer or the /etc/printcap
+            file (depending on your printing backend)  must still be 
+            modified manually, as well as pykota's configuration file
+            for a new printer to be managed successfully.
             
   $ edpykota -g -S 500 -H 550 financial support            
@@ -474,4 +478,6 @@
                                 if groupid is not None :
                                     self.storage.addUserToGroup(ident, groupid)
+                                else :
+                                    self.logger.log_message(_("Group %s not found in the PyKota Storage.") % groupname)
                             self.warnUserPQuota(name, printer)    
                      
Index: /pykota/trunk/bin/pykota
===================================================================
--- /pykota/trunk/bin/pykota (revision 915)
+++ /pykota/trunk/bin/pykota (revision 952)
@@ -3,5 +3,5 @@
 # PyKota accounting filter
 #
-# PyKota - Print Quotas for CUPS
+# PyKota - Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.24  2003/04/23 22:13:56  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.23  2003/04/15 11:30:57  jalet
 # More work done on money print charging.
@@ -115,22 +118,9 @@
 class PyKotaFilter(PyKotaTool) :    
     """Class for the PyKota filter."""
-    def __init__(self, username) :
+    def __init__(self) :
         PyKotaTool.__init__(self)
-        self.username = username
+        (self.printingsystem, self.printerhostname, self.printername, self.username, self.jobid, self.inputfile) = self.extractInfoFromCupsOrLprng()
         self.requester = openRequester(self.config, self.printername)
-        self.printerhostname = self.getPrinterHostname()
-    
-    def getPrinterHostname(self) :
-        """Returns the printer hostname."""
-        device_uri = os.environ.get("DEVICE_URI", "")
-        # TODO : check this for more complex urls than ipp://myprinter.dot.com:631/printers/lp
-        try :
-            (backend, destination) = device_uri.split(":", 1) 
-        except ValueError :    
-            raise PyKotaToolError, "Invalid DEVICE_URI : %s\n" % device_uri
-        while destination.startswith("/") :
-            destination = destination[1:]
-        return destination.split("/")[0].split(":")[0]
-        
+    
     def filterInput(self, inputfile) :
         """Transparent filter."""
@@ -148,33 +138,40 @@
             infile.close()
             
+    def acceptJob(self) :        
+        """Returns the exit code needed by the printing backend to accept the job and print it."""
+        if self.printingsystem == "CUPS" :
+            return 0
+        elif self.printingsystem == "LPRNG" :    
+            return 0
+        else :    
+            # UNKNOWN
+            return -1
+            
+    def removeJob(self) :            
+        """Returns the exit code needed by the printing backend to refuse the job and remove it."""
+        if self.printingsystem == "CUPS" :
+            return 1
+        elif self.printingsystem == "LPRNG" :    
+            return 3
+        else :    
+            # UNKNOWN
+            return -1
+            
 def main() :    
     """Do it, and do it right !"""
+        
+    # Initializes the current tool
+    kotafilter = PyKotaFilter()    
+    
     #
-    # This is a CUPS filter, so we should act and die like a CUPS filter when needed
-    narg = len(sys.argv)
-    if narg not in (6, 7) :    
-        sys.stderr.write("ERROR: %s job-id user title copies options [file]\n" % sys.argv[0])
-        return 1
-    elif narg == 7 :    
-        # input file
-        inputfile = sys.argv[6]
-    else :    
-        # stdin
-        inputfile = None
-        
-    #    
-    # According to CUPS documentation, the job id is the second command line argument
-    jobid = sys.argv[1].strip()
-    
-    #    
-    # According to CUPS documentation, the username is the third command line argument
-    username = sys.argv[2].strip()    
-    
-    # Initializes the current tool
-    kotafilter = PyKotaFilter(username)    
+    # If this is a CUPS filter, we should act and die like a CUPS filter when needed
+    if kotafilter.printingsystem == "CUPS" :
+        if len(sys.argv) not in (6, 7) :    
+            sys.stderr.write("ERROR: %s job-id user title copies options [file]\n" % sys.argv[0])
+            return kotafilter.removeJob()
     
     # Get the page counter directly from the printer itself
     try :
-        counterbeforejob = kotafilter.requester.getPrinterPageCounter(kotafilter.printerhostname) # TODO use printername instead, make them match from CUPS' config files
+        counterbeforejob = kotafilter.requester.getPrinterPageCounter(kotafilter.printerhostname)
     except PyKotaRequesterError, msg :
         # can't get actual page counter, assume printer is off, but warns in log
@@ -192,9 +189,18 @@
         kotafilter.logger.log_message(_("Printer %s not registered in the PyKota system") % kotafilter.printername, "warn")
     else :    
-        userid = kotafilter.storage.getUserId(username)
+        userid = kotafilter.storage.getUserId(kotafilter.username)
         if userid is None :
             # The user is unknown from the Quota Storage perspective
-            # we let the job pass through, but log a warning message
-            kotafilter.logger.log_message(_("User %s not registered in the PyKota system") % username, "warn")
+            # Depending on the default policy for this printer, we
+            # either let the job pass through or reject it, but we
+            # log a message in any case.
+            policy = kotafilter.config.getPrinterPolicy(kotafilter.printername)
+            if policy in [None, "ALLOW"] :
+                action = "POLICY_ALLOW"
+            else :    
+                action = "POLICY_DENY"
+            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")
+            if action == "POLICY_DENY" :
+                return kotafilter.removeJob()
         else :
             # get last job information for this printer
@@ -203,7 +209,7 @@
                 # The printer hasn't been used yet, from PyKota's point of view
                 lasthistoryid = None
-                lastjobid = jobid
+                lastjobid = kotafilter.jobid
                 lastuserid = userid
-                lastusername = username
+                lastusername = kotafilter.username
                 lastpagecounter = counterbeforejob
             else :    
@@ -251,22 +257,22 @@
             
             # warns the last user if he is over quota
-            kotafilter.warnUserPQuota(lastusername)
+            kotafilter.warnUserPQuota(lastusername, kotafilter.printername)
                 
             # Is the current user allowed to print at all ?
-            action = kotafilter.warnUserPQuota(username)
+            action = kotafilter.warnUserPQuota(kotafilter.username, kotafilter.printername)
             
             # adds the current job to history    
-            kotafilter.storage.addJobToHistory(jobid, kotafilter.storage.getUserId(username), printerid, counterbeforejob, action)
+            kotafilter.storage.addJobToHistory(kotafilter.jobid, kotafilter.storage.getUserId(kotafilter.username), printerid, counterbeforejob, action)
             
             # if not allowed to print then die, else proceed.
             if action == "DENY" :
                 # No, just die cleanly
-                return 1
+                return kotafilter.removeJob()
         
     # pass the job untouched to the underlying layer
-    kotafilter.filterInput(inputfile)      
-    
-    return 0
+    kotafilter.filterInput(kotafilter.inputfile)      
+    
+    return kotafilter.acceptJob()
 
 if __name__ == "__main__" :    
-    sys.exit(main() or 0)
+    sys.exit(main())
Index: /pykota/trunk/bin/README
===================================================================
--- /pykota/trunk/bin/README (revision 873)
+++ /pykota/trunk/bin/README (revision 952)
@@ -1,5 +1,5 @@
 # $Id$
 
-PyKota - Print Quota for CUPS
+PyKota - Print Quota for CUPS and LPRng
 
 (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/bin/repykota
===================================================================
--- /pykota/trunk/bin/repykota (revision 950)
+++ /pykota/trunk/bin/repykota (revision 952)
@@ -3,5 +3,5 @@
 # PyKota Print Quota Reports generator
 #
-# PyKota - Print Quotas for CUPS
+# PyKota - Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.32  2003/04/23 22:13:56  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.31  2003/04/23 09:58:17  jalet
 # Prices per page/job are now displayed
Index: /pykota/trunk/man/README
===================================================================
--- /pykota/trunk/man/README (revision 873)
+++ /pykota/trunk/man/README (revision 952)
@@ -1,5 +1,5 @@
 # $Id$
 
-PyKota - Print Quota for CUPS
+PyKota - Print Quota for CUPS and LPRng
 
 (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/initscripts/README.postgresql
===================================================================
--- /pykota/trunk/initscripts/README.postgresql (revision 951)
+++ /pykota/trunk/initscripts/README.postgresql (revision 952)
@@ -1,5 +1,5 @@
 # $Id$
 
-PyKota - Print Quota for CUPS
+PyKota - Print Quota for CUPS and LPRng
 
 (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/initscripts/VERYOLDpykota-upgrade-postgresql.sql
===================================================================
--- /pykota/trunk/initscripts/VERYOLDpykota-upgrade-postgresql.sql (revision 942)
+++ /pykota/trunk/initscripts/VERYOLDpykota-upgrade-postgresql.sql (revision 952)
@@ -1,4 +1,4 @@
 --
--- PyKota - Print Quotas for CUPS
+-- PyKota - Print Quotas for CUPS and LPRng
 --
 -- (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -20,4 +20,7 @@
 --
 -- $Log$
+-- Revision 1.2  2003/04/23 22:13:56  jalet
+-- Preliminary support for LPRng added BUT STILL UNTESTED.
+--
 -- Revision 1.1  2003/04/17 21:33:16  jalet
 -- Version 1.03 is out.
Index: /pykota/trunk/initscripts/pykota-postgresql.sql
===================================================================
--- /pykota/trunk/initscripts/pykota-postgresql.sql (revision 915)
+++ /pykota/trunk/initscripts/pykota-postgresql.sql (revision 952)
@@ -1,4 +1,4 @@
 --
--- PyKota - Print Quotas for CUPS
+-- PyKota - Print Quotas for CUPS and LPRng
 --
 -- (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -20,4 +20,7 @@
 --
 -- $Log$
+-- Revision 1.14  2003/04/23 22:13:56  jalet
+-- Preliminary support for LPRng added BUT STILL UNTESTED.
+--
 -- Revision 1.13  2003/04/15 11:30:57  jalet
 -- More work done on money print charging.
Index: /pykota/trunk/initscripts/README
===================================================================
--- /pykota/trunk/initscripts/README (revision 951)
+++ /pykota/trunk/initscripts/README (revision 952)
@@ -1,5 +1,5 @@
 # $Id$
 
-PyKota - Print Quota for CUPS
+PyKota - Print Quota for CUPS and LPRng
 
 (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/initscripts/upgrade-from-before-1.03.py
===================================================================
--- /pykota/trunk/initscripts/upgrade-from-before-1.03.py (revision 951)
+++ /pykota/trunk/initscripts/upgrade-from-before-1.03.py (revision 952)
@@ -3,5 +3,5 @@
 # PyKota Print Quota Warning sender
 #
-# PyKota - Print Quotas for CUPS
+# PyKota - Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 950)
+++ /pykota/trunk/NEWS (revision 952)
@@ -22,4 +22,8 @@
 PyKota NEWS :
 
+    - 1.04pre2 :
+    
+        - Preliminary support for LPRng added (still untested)
+        
     - 1.04pre1 :
     
Index: /pykota/trunk/po/en/pykota.po
===================================================================
--- /pykota/trunk/po/en/pykota.po (revision 950)
+++ /pykota/trunk/po/en/pykota.po (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.21  2003/04/23 22:13:56  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.20  2003/04/23 09:58:17  jalet
 # Prices per page/job are now displayed
@@ -274,5 +277,5 @@
 msgstr ""
 
-msgid "User %s not registered in the PyKota system"
+msgid "User %s not registered in the PyKota system, applying default policy (%s) for printer %s"
 msgstr ""
 
@@ -319,2 +322,5 @@
 msgid "Price per page: %.3f"
 msgstr ""
+
+msgid "Group %s not found in the PyKota Storage."
+msgstr ""
Index: /pykota/trunk/po/fr/pykota.po
===================================================================
--- /pykota/trunk/po/fr/pykota.po (revision 950)
+++ /pykota/trunk/po/fr/pykota.po (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.20  2003/04/23 22:13:57  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.19  2003/04/23 09:58:17  jalet
 # Prices per page/job are now displayed
@@ -283,6 +286,6 @@
 msgstr "Fichier de configuration %s non trouv�
 
-msgid "User %s not registered in the PyKota system"
-msgstr "Utilisateur %s non enregistr�ans le syst� PyKota"
+msgid "User %s not registered in the PyKota system, applying default policy (%s) for printer %s"
+msgstr "Utilisateur %s non enregistr�ans le syst� PyKota, action par d�ut (%s) appliqu�sur l'imprimante %s"
 
 msgid "Invalid charge amount value %s"
@@ -332,2 +335,5 @@
 msgid "Price per page: %.3f"
 msgstr "Prix par page: %.3f"
+
+msgid "Group %s not found in the PyKota Storage."
+msgstr "Groupe %s non trouv�ans le Quota Storage."
Index: /pykota/trunk/po/pykota.pot
===================================================================
--- /pykota/trunk/po/pykota.pot (revision 950)
+++ /pykota/trunk/po/pykota.pot (revision 952)
@@ -1,5 +1,5 @@
 # PyKota
 #
-# PyKota : Print Quotas for CUPS
+# PyKota : Print Quotas for CUPS and LPRng
 #
 # (c) 2003 Jerome Alet <alet@librelogiciel.com>
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.21  2003/04/23 22:13:56  jalet
+# Preliminary support for LPRng added BUT STILL UNTESTED.
+#
 # Revision 1.20  2003/04/23 09:58:17  jalet
 # Prices per page/job are now displayed
@@ -274,5 +277,5 @@
 msgstr ""
 
-msgid "User %s not registered in the PyKota system"
+msgid "User %s not registered in the PyKota system, applying default policy (%s) for printer %s"
 msgstr ""
 
@@ -319,2 +322,5 @@
 msgid "Price per page: %.3f"
 msgstr ""
+
+msgid "Group %s not found in the PyKota Storage."
+msgstr ""
Index: /pykota/trunk/po/README
===================================================================
--- /pykota/trunk/po/README (revision 873)
+++ /pykota/trunk/po/README (revision 952)
@@ -1,5 +1,5 @@
 # $Id$
 
-PyKota - Print Quota for CUPS
+PyKota - Print Quota for CUPS and LPRng
 
 (c) 2003 Jerome Alet <alet@librelogiciel.com>
