Changeset 1980

Show
Ignore:
Timestamp:
12/13/04 21:39:46 (19 years ago)
Author:
jalet
Message:

Added a --debug command line option to pkpgcounter, for people interested
in seeing what happens, and what will be available in the future :-)

Location:
pykota/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/NEWS

    r1977 r1980  
    2222PyKota NEWS : 
    2323 
     24    - 1.21alpha13 : 
     25     
     26        - Added a --debug command line option to pkpgcounter, so 
     27          that people may see what really happens, and what will 
     28          be available in the future :-) 
     29           
    2430    - 1.21alpha12 : 
    2531     
  • pykota/trunk/pykota/pdlanalyzer.py

    r1940 r1980  
    2222# 
    2323# $Log$ 
     24# Revision 1.45  2004/12/13 20:39:46  jalet 
     25# Added a --debug command line option to pkpgcounter, for people interested 
     26# in seeing what happens, and what will be available in the future :-) 
     27# 
    2428# Revision 1.44  2004/11/17 15:10:31  jalet 
    2529# Fixed Epson Stylus Photo problem in software accounting 
     
    186190class PostScriptAnalyzer : 
    187191    """A class to parse PostScript documents.""" 
    188     def __init__(self, infile) : 
     192    def __init__(self, infile, debug=0) : 
    189193        """Initialize PostScript Analyzer.""" 
     194        self.debug = debug 
    190195        self.infile = infile 
    191196        self.copies = 1 
     
    193198    def throughGhostScript(self) : 
    194199        """Get the count through GhostScript, useful for non-DSC compliant PS files.""" 
     200        if self.debug : 
     201            sys.stderr.write("Internal parser sucks, using GhostScript instead...\n") 
    195202        self.infile.seek(0) 
    196203        command = 'gs -sDEVICE=bbox -dNOPAUSE -dBATCH -dQUIET - 2>&1 | grep -c "%%HiResBoundingBox:" 2>/dev/null' 
     
    252259class PDFAnalyzer : 
    253260    """A class to parse PDF documents.""" 
    254     def __init__(self, infile) : 
     261    def __init__(self, infile, debug=0) : 
    255262        """Initialize PDF Analyzer.""" 
     263        self.debug = debug 
    256264        self.infile = infile 
    257265                 
     
    266274class ESCP2Analyzer : 
    267275    """A class to parse ESC/P2 documents.""" 
    268     def __init__(self, infile) : 
     276    def __init__(self, infile, debug=0) : 
    269277        """Initialize ESC/P2 Analyzer.""" 
     278        self.debug = debug 
    270279        self.infile = infile 
    271280                 
     
    356365                    
    357366                    
    358     def __init__(self, infile) : 
     367    def __init__(self, infile, debug=0) : 
    359368        """Initialize PCL Analyzer.""" 
     369        self.debug = debug 
    360370        self.infile = infile 
    361371         
     
    566576                pagecount = endgfx 
    567577                 
    568         #for pnum in range(pagecount) : 
    569         #    # if no number of copies defined, take the preceding one else the one set before any page else 1. 
    570         #    page = pages.get(pnum, pages.get(pnum - 1, pages.get(0, { "copies" : 1, "mediasource" : "Main", "mediasize" : "Default", "mediatype" : "Plain", "orientation" : "Portrait"}))) 
    571         #    print "%s*%s*%s*%s*%s" % (page["copies"], page["mediatype"], page["mediasize"], page["orientation"], page["mediasource"]) 
     578        if self.debug :         
     579            for pnum in range(pagecount) : 
     580                # if no number of copies defined, take the preceding one else the one set before any page else 1. 
     581                page = pages.get(pnum, pages.get(pnum - 1, pages.get(0, { "copies" : 1, "mediasource" : "Main", "mediasize" : "Default", "mediatype" : "Plain", "orientation" : "Portrait"}))) 
     582                print "%s*%s*%s*%s*%s" % (page["copies"], page["mediatype"], page["mediasize"], page["orientation"], page["mediasource"]) 
    572583             
    573584        return pagecount 
     
    614625                   } 
    615626                    
    616     def __init__(self, infile) : 
     627    def __init__(self, infile, debug=0) : 
    617628        """Initialize PCLXL Analyzer.""" 
     629        self.debug = debug 
    618630        self.infile = infile 
    619631        self.endianness = None 
     
    873885            copies = page["copies"] 
    874886            self.pagecount += (copies - 1) 
    875             # print "%s*%s*%s*%s*%s" % (copies, page["mediatype"], page["mediasize"], page["orientation"], page["mediasource"]) 
     887            if self.debug : 
     888                print "%s*%s*%s*%s*%s" % (copies, page["mediatype"], page["mediasize"], page["orientation"], page["mediasource"]) 
    876889             
    877890        return self.pagecount 
     
    879892class PDLAnalyzer :     
    880893    """Generic PDL Analyzer class.""" 
    881     def __init__(self, filename) : 
     894    def __init__(self, filename, debug=0) : 
    882895        """Initializes the PDL analyzer. 
    883896         
     
    886899           supports read() and seek(). 
    887900        """ 
     901        self.debug = debug 
    888902        self.filename = filename 
    889903        try : 
     
    914928        else : 
    915929            try : 
    916                 size = pdlhandler(self.infile).getJobSize() 
     930                size = pdlhandler(self.infile, self.debug).getJobSize() 
    917931            finally :     
    918932                self.closeFile() 
     
    968982              (sdata.find("LANGUAGE = Postscript") != -1))) or \ 
    969983              (sdata.find("%!PS-Adobe") != -1) : 
     984            if self.debug :   
     985                sys.stderr.write("%s is a PostScript file\n" % str(self.filename)) 
    970986            return 1 
    971987        else :     
     
    978994           ((sdata[:128].find("\033%-12345X") != -1) and (sdata.upper().find("LANGUAGE=PDF") != -1)) or \ 
    979995           (sdata.find("%PDF-") != -1) : 
     996            if self.debug :   
     997                sys.stderr.write("%s is a PDF file\n" % str(self.filename)) 
    980998            return 1 
    981999        else :     
     
    9881006           sdata.startswith("\033%8\033") or \ 
    9891007           (sdata.find("\033%-12345X") != -1) : 
     1008            if self.debug :   
     1009                sys.stderr.write("%s is a PCL3/4/5 file\n" % str(self.filename)) 
    9901010            return 1 
    9911011        else :     
     
    9981018             ((sdata.find("LANGUAGE=PCLXL") != -1) or \ 
    9991019              (sdata.find("LANGUAGE = PCLXL") != -1))) : 
     1020            if self.debug :   
     1021                sys.stderr.write("%s is a PCLXL (aka PCL6) file\n" % str(self.filename)) 
    10001022            return 1 
    10011023        else :     
     
    10081030           sdata.startswith("\n\033@") or \ 
    10091031           sdata.startswith("\0\0\0\033\1@EJL") : # ESC/P Raster ??? Seen on Stylus Photo 1284 
     1032            if self.debug :   
     1033                sys.stderr.write("%s is an ESC/P2 file\n" % str(self.filename)) 
    10101034            return 1 
    10111035        else :     
     
    10461070         
    10471071    totalsize = 0     
    1048     for arg in sys.argv[1:] : 
     1072    debug = 0 
     1073    minindex = 1 
     1074    if sys.argv[1] == "--debug" : 
     1075        minindex = 2 
     1076        debug = 1 
     1077    for arg in sys.argv[minindex:] : 
    10491078        try : 
    1050             parser = PDLAnalyzer(arg) 
     1079            parser = PDLAnalyzer(arg, debug) 
    10511080            totalsize += parser.getJobSize() 
    10521081        except PDLAnalyzerError, msg :     
  • pykota/trunk/pykota/version.py

    r1974 r1980  
    2222# 
    2323 
    24 __version__ = "1.21alpha12_unofficial" 
     24__version__ = "1.21alpha13_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""