Changeset 1475 for pykota/trunk/pykota

Show
Ignore:
Timestamp:
05/13/04 15:59:30 (20 years ago)
Author:
jalet
Message:

Code simplifications

Location:
pykota/trunk/pykota
Files:
2 added
4 removed
6 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/accounters/Makefile.am

    r1417 r1475  
    22 
    33pykota_accounters_PYTHON =      \ 
    4         external.py                             \ 
     4        software.py                             \ 
    55        __init__.py                             \ 
    6         querying.py                             \ 
    7         stupid.py                                
     6        hardware.py 
    87 
  • pykota/trunk/pykota/config.py

    r1371 r1475  
    2222# 
    2323# $Log$ 
     24# Revision 1.46  2004/05/13 13:59:28  jalet 
     25# Code simplifications 
     26# 
    2427# Revision 1.45  2004/03/01 10:22:30  jalet 
    2528# Can now extract per printer pre and post hooks from the configuration file 
     
    303306        """Returns the accounter backend to use for a given printer. 
    304307         
    305            if it is not set, it defaults to 'querying' which means ask printer 
     308           if it is not set, it defaults to 'hardware' which means ask printer 
    306309           for its internal lifetime page counter. 
    307310        """    
    308         validaccounters = [ "querying", "stupid", "external" ]      
     311        validaccounters = [ "hardware", "software" ]      
    309312        fullaccounter = self.getPrinterOption(printername, "accounter").strip() 
    310         if fullaccounter.lower().startswith("external") :     
     313        if fullaccounter.lower().startswith("software") :     
    311314            try : 
    312315                (accounter, args) = [x.strip() for x in fullaccounter.split('(', 1)] 
     
    343346        except PyKotaConfigError :     
    344347            # No requester defined, maybe it is not needed if accounting method 
    345             # is not set to 'querying', but if we are called, then the accounting 
    346             # method really IS 'querying', and so there's a big problem. 
     348            # is not set to 'hardware', but if we are called, then the accounting 
     349            # method really IS 'hardware', and so there's a big problem. 
    347350            raise PyKotaConfigError, _("Option requester for printer %s was not set") % printername 
    348351        else :     
     
    355358            if not args : 
    356359                raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printername) 
    357             validrequesters = [ "snmp", "external" ] # TODO : add more requesters 
     360            validrequesters = [ "external" ]  
    358361            requester = requester.lower() 
    359362            if requester not in validrequesters : 
  • pykota/trunk/pykota/requesters/external.py

    r1433 r1475  
    2222# 
    2323# $Log$ 
     24# Revision 1.12  2004/05/13 13:59:30  jalet 
     25# Code simplifications 
     26# 
    2427# Revision 1.11  2004/04/09 22:24:47  jalet 
    2528# Began work on correct handling of child processes when jobs are cancelled by 
     
    6366# 
    6467 
     68import sys 
    6569import os 
     70import popen2 
     71import signal 
    6672from pykota.requester import PyKotaRequesterError 
    6773 
     
    8288        if printer is None : 
    8389            raise PyKotaRequesterError, _("Unknown printer address in EXTERNAL(%s) for printer %s") % (commandline, self.printername) 
    84         answer = os.popen(commandline) 
     90        error = 1 
     91        pagecounter = None 
     92        child = popen2.Popen4(commandline)     
    8593        try : 
    86             pagecounter = int(answer.readline().strip()) 
     94            pagecounter = int(child.fromchild.readline().strip()) 
    8795        except ValueError :     
     96            pass 
     97        except IOError :     
     98            # we were interrupted by a signal, certainely a SIGTERM 
     99            # caused by the user cancelling the current job 
     100            try : 
     101                os.kill(child.pid, signal.SIGTERM) 
     102            except :     
     103                pass # already killed ? 
     104            self.kotabackend.logger.log_message(_("SIGTERM was sent to external requester %s (pid: %s)") % (commandline, child.pid), "info") 
     105        else :     
     106            error = 0 
     107        child.fromchild.close()     
     108        child.tochild.close() 
     109        status = child.wait() 
     110        if (not error) and os.WIFEXITED(status) and (not os.WEXITSTATUS(status)) : 
     111            return pagecounter 
     112        else :     
    88113            raise PyKotaRequesterError, _("Unable to query printer %s via EXTERNAL(%s)") % (printer, commandline)  
    89         answer.close() 
    90         return pagecounter 
    91114         
  • pykota/trunk/pykota/requesters/Makefile.am

    r1417 r1475  
    33pykota_requesters_PYTHON =      \ 
    44        external.py                             \ 
    5         __init__.py                             \ 
    6         snmp.py 
     5        __init__.py 
    76 
  • pykota/trunk/pykota/tool.py

    r1469 r1475  
    2222# 
    2323# $Log$ 
     24# Revision 1.86  2004/05/13 13:59:28  jalet 
     25# Code simplifications 
     26# 
    2427# Revision 1.85  2004/05/11 08:26:27  jalet 
    2528# Now catches connection problems to SMTP server 
     
    809812             
    810813    def prehook(self, userpquota) : 
    811         """Allows pluging of an external hook before the job gets printed.""" 
     814        """Allows plugging of an external hook before the job gets printed.""" 
    812815        prehook = self.config.getPreHook(userpquota.Printer.Name) 
    813816        if prehook : 
     
    816819         
    817820    def posthook(self, userpquota) : 
    818         """Allows pluging of an external hook after the job gets printed and/or denied.""" 
     821        """Allows plugging of an external hook after the job gets printed and/or denied.""" 
    819822        posthook = self.config.getPostHook(userpquota.Printer.Name) 
    820823        if posthook : 
  • pykota/trunk/pykota/version.py

    r1473 r1475  
    2222# 
    2323 
    24 __version__ = "1.19alpha7_unofficial" 
     24__version__ = "1.19alpha8_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""