Changeset 1463 for pykota/trunk

Show
Ignore:
Timestamp:
05/10/04 09:23:21 (20 years ago)
Author:
jalet
Message:

pykotme now uses pkpgcounter to compute the job's size.

Location:
pykota/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkpgcounter

    r1462 r1463  
    2424# 
    2525# $Log$ 
     26# Revision 1.9  2004/05/10 07:23:21  jalet 
     27# pykotme now uses pkpgcounter to compute the job's size. 
     28# 
    2629# Revision 1.8  2004/05/08 15:12:23  jalet 
    2730# Improved PCL6 support 
     
    396399     
    397400if __name__ == "__main__" :     
    398     if len(sys.argv) < 2 : 
     401    if (len(sys.argv) < 2) or ((not sys.stdin.isatty()) and ("-" not in sys.argv[1:])) : 
    399402        sys.argv.append("-") 
    400403         
  • pykota/trunk/bin/pykotme

    r1285 r1463  
    2424# 
    2525# $Log$ 
     26# Revision 1.8  2004/05/10 07:23:21  jalet 
     27# pykotme now uses pkpgcounter to compute the job's size. 
     28# 
    2629# Revision 1.7  2004/01/12 22:43:40  jalet 
    2730# New formula to compute a job's price 
     
    123126    def main(self, files, options) : 
    124127        """Gives print quotes.""" 
    125         if not files : 
    126             files = [ sys.stdin ] 
     128        if (not sys.stdin.isatty()) and ("-" not in files) : 
     129            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) 
    127158             
    128         nbpages = 0     
    129         for filename in files : 
    130             if filename is sys.stdin : 
    131                 stream = filename 
    132             else : 
    133                 if filename == "-" : 
    134                     stream = sys.stdin 
    135                 else :     
    136                     try : 
    137                         stream = open(filename, "rb") 
    138                     except IOError, msg :     
    139                         sys.stderr.write("%s\n" % msg) 
    140                         continue 
    141             nb = self.getNbPages(stream) 
    142             if nb is None : 
    143                 sys.stderr.write(_("Unable to compute size of %s in number of pages.\n") % filename) 
    144             else : 
    145                 nbpages += nb 
    146             if not (filename is sys.stdin) :         
    147                 stream.close() 
    148                  
    149         # get current user 
    150         uid = os.geteuid() 
    151         username = pwd.getpwuid(uid)[0] 
    152         user = self.storage.getUser(username) 
    153         if user.Exists and user.LimitBy and (user.LimitBy.lower() == "balance"): 
    154             print _("Your account balance : %.2f") % (user.AccountBalance or 0.0) 
    155              
    156         printers = self.storage.getMatchingPrinters(options["printer"]) 
    157         if not printers : 
    158             raise PyKotaToolError, _("There's no printer matching %s") % options["printer"] 
    159              
    160         print _("Job size : %i pages") % nbpages     
    161         for printer in printers : 
    162             userpquota = self.storage.getUserPQuota(user, printer) 
    163             cost = userpquota.computeJobPrice(nbpages) 
    164             print _("Cost on printer %s : %.2f") % (printer.Name, cost) 
    165              
    166     def getNbPages(self, stream) :         
    167         """Tries to compute the file's size in number of pages, the best we can.""" 
    168         nbpages = [] # in case some user wants to put several %%Pages: entries in the file 
    169         for line in stream.xreadlines() : 
    170             line = line.strip() 
    171             if line.startswith("%%Pages: ") : 
    172                 try : 
    173                     nbpages.append(int(line[9:])) 
    174                 except ValueError :     
    175                     pass 
    176         if nbpages :             
    177             return max(nbpages) 
    178          
    179159if __name__ == "__main__" :  
    180160    retcode = 0 
  • pykota/trunk/NEWS

    r1459 r1463  
    2222PyKota NEWS : 
    2323 
     24    - 1.19alpha6 : 
     25     
     26        - pykotme now uses pkpgcounter to compute the size of the 
     27          job. This modification adds PCL5 and soon PCLXL (PCL6) 
     28          support. You can now get quotes for PCL in addition to  
     29          PostScript. 
     30           
    2431    - 1.19alpha5 : 
    2532     
  • pykota/trunk/pykota/version.py

    r1451 r1463  
    2222# 
    2323 
    24 __version__ = "1.19alpha5_unofficial" 
     24__version__ = "1.19alpha6_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""