Changeset 1488

Show
Ignore:
Timestamp:
05/21/04 22:53:34 (20 years ago)
Author:
jalet
Message:

Now pykotme doesn't spawn a new process anymore to compute job's size, but
use the PDLAnalyzer class directly

Location:
pykota/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pykotme

    r1463 r1488  
    2424# 
    2525# $Log$ 
     26# Revision 1.9  2004/05/21 20:53:34  jalet 
     27# Now pykotme doesn't spawn a new process anymore to compute job's size, but 
     28# use the PDLAnalyzer class directly 
     29# 
    2630# Revision 1.8  2004/05/10 07:23:21  jalet 
    2731# pykotme now uses pkpgcounter to compute the job's size. 
     
    6367from pykota.config import PyKotaConfigError 
    6468from pykota.storage import PyKotaStorageError 
     69from pykota.pdlanalyzer import PDLAnalyzer, PDLAnalyzerError 
    6570 
    6671__doc__ = """pykotme v%s (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres 
     
    122127Please e-mail bugs to: %s""" % (version.__version__, version.__author__) 
    123128         
     129         
    124130class PyKotMe(PyKotaTool) :         
    125131    """A class for pykotme.""" 
     
    128134        if (not sys.stdin.isatty()) and ("-" not in files) : 
    129135            files.append("-") 
    130         pipe = os.popen("pkpgcounter %s" % " ".join([' "%s"' % f for f in files])) 
    131         answer = pipe.readline().strip() 
    132         status = pipe.close() 
    133         try : 
    134             if status is None : 
    135                 nbpages = int(answer) 
    136             else :         
    137                 raise ValueError, "ERROR in pkpgcounter"  
    138         except ValueError, msg :     
    139             sys.stderr.write(_("Unable to compute size of %s in number of pages.\n") % files) 
    140             sys.stderr.write("%s\n" % msg) 
    141         else :     
    142             # get current user 
    143             uid = os.geteuid() 
    144             username = pwd.getpwuid(uid)[0] 
    145             user = self.storage.getUser(username) 
    146             if user.Exists and user.LimitBy and (user.LimitBy.lower() == "balance"): 
    147                 print _("Your account balance : %.2f") % (user.AccountBalance or 0.0) 
    148                  
    149             printers = self.storage.getMatchingPrinters(options["printer"]) 
    150             if not printers : 
    151                 raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] 
    152                  
    153             print _("Job size : %i pages") % nbpages     
    154             for printer in printers : 
    155                 userpquota = self.storage.getUserPQuota(user, printer) 
    156                 cost = userpquota.computeJobPrice(nbpages) 
    157                 print _("Cost on printer %s : %.2f") % (printer.Name, cost) 
     136        totalsize = 0     
     137        for filename in files :     
     138            try : 
     139                parser = PDLAnalyzer(filename) 
     140                totalsize += parser.getJobSize() 
     141            except PDLAnalyzerError, msg :     
     142                sys.stderr.write("%s\n" % msg) 
     143                sys.stderr.flush() 
     144             
     145        # get current user 
     146        uid = os.geteuid() 
     147        username = pwd.getpwuid(uid)[0] 
     148        user = self.storage.getUser(username) 
     149        if user.Exists and user.LimitBy and (user.LimitBy.lower() == "balance"): 
     150            print _("Your account balance : %.2f") % (user.AccountBalance or 0.0) 
     151             
     152        printers = self.storage.getMatchingPrinters(options["printer"]) 
     153        if not printers : 
     154            raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] 
     155             
     156        print _("Job size : %i pages") % totalsize     
     157        for printer in printers : 
     158            userpquota = self.storage.getUserPQuota(user, printer) 
     159            cost = userpquota.computeJobPrice(totalsize) 
     160            print _("Cost on printer %s : %.2f") % (printer.Name, cost) 
    158161             
    159162if __name__ == "__main__" :  
  • pykota/trunk/NEWS

    r1487 r1488  
    2424    - 1.19alpha10 : 
    2525     
     26        - pykotme now uses generic PDL Analyzer directly instead 
     27          of spawning a new process. 
     28           
    2629        - Improvements to generic PDL Analyzer. 
    2730