Changeset 3436

Show
Ignore:
Timestamp:
10/06/08 00:22:07 (15 years ago)
Author:
jerome
Message:

Removed spaces at EOL.

Location:
pkpgcounter/trunk
Files:
38 modified

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/bin/pkpgcounter

    r564 r3436  
    11#! /usr/bin/env python 
    2 # -*- coding: UTF-8 -*- 
     2# -*- coding: utf-8 -*- 
    33# 
    44# pkpgcounter : a generic Page Description Language parser 
     
    99# the Free Software Foundation, either version 3 of the License, or 
    1010# (at your option) any later version. 
    11 #  
     11# 
    1212# This program is distributed in the hope that it will be useful, 
    1313# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1414# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1515# GNU General Public License for more details. 
    16 #  
     16# 
    1717# You should have received a copy of the GNU General Public License 
    1818# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    7171  -v | --version        Prints pkpgcounter's version number then exits. 
    7272  -h | --help           Prints this message then exits. 
    73    
    74   -d | --debug          Activate debug mode.  
    75    
     73 
     74  -d | --debug          Activate debug mode. 
     75 
    7676  -cCOLORSPACE, --colorspace=COLORSPACE 
    7777                        Activate the computation of ink usage, and defines the 
    7878                        colorspace to use. Supported values are 'BW' (Black), 
    7979                        'RGB', 'CMYK', 'CMY', and 'GC' (Grayscale vs Color). 
    80                         'GC' is useful if you only need to differentiate  
     80                        'GC' is useful if you only need to differentiate 
    8181                        grayscale pages from coloured pages but don't care 
    8282                        about ink usage per se. 
    83                          
     83 
    8484  -rRESOLUTION, --resolution=RESOLUTION 
    8585                        The resolution in DPI to use when checking ink usage. 
    8686                        Lower resolution is faster but less accurate. Default 
    8787                        is 72 dpi. 
    88    
    89 examples :                               
     88 
     89examples : 
    9090 
    9191  $ pkpgcounter file1.ps file2.escp2 file3.pclxl <file4.pcl345 
    92    
     92 
    9393  Will launch pkpgcounter and will output the total number of pages 
    9494  needed to print all the documents specified. 
    95    
     95 
    9696  $ pkpgcounter --colorspace bw --resolution 150 file1.ps 
    97    
     97 
    9898  Will output the percent of black ink needed on each page of 
    9999  the file1.ps file rendered at 150 dpi. 
    100    
    101 %(__gplblurb__)s   
     100 
     101%(__gplblurb__)s 
    102102 
    103103Please e-mail bugs to: %(__authoremail__)s""" 
    104104 
    105 if __name__ == "__main__" :  
     105if __name__ == "__main__" : 
    106106    if (len(sys.argv) >= 2) and (sys.argv[1] in ("-h", "--help")) : 
    107107        print __doc__ % globals() 
    108     else :     
     108    else : 
    109109        analyzer.main() 
    110110 
  • pkpgcounter/trunk/BUGS

    r564 r3436  
    2020 
    2121pkpgcounter BUGS : 
    22     
     22 
    2323  - All parsers need more testing, especially those which allow the number 
    2424    of copies to be specified as part of the data streams, as well as those 
  • pkpgcounter/trunk/clean.sh

    r564 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
  • pkpgcounter/trunk/CREDITS

    r3409 r3436  
    2020 
    2121The following people helped the pkpgcounter project : 
    22    
    23    
     22 
     23 
    2424  - Eduardo Gielamo Oliveira & Rodolfo Broco Manin : initial PCL parser. 
    25    
     25 
    2626  - Valcir C. Vargas : helped on PCL3GUI support. 
    27    
    28   - Daniel Franklin : pkpgcounter's algorithm for the computation  
     27 
     28  - Daniel Franklin : pkpgcounter's algorithm for the computation 
    2929    of ink coverage comes from Daniel's PrintBill project. 
    30      
    31   - Aur�en Croc : reverse engineered Samsung QPDL and published   
     30 
     31  - Aur�en Croc : reverse engineered Samsung QPDL and published 
    3232                    a language specification. 
    3333 
    3434  - Franck (?) : sent a path to improve the PostScript parser when 
    3535                 the PS code generated several copies. 
    36                   
    37   - Yves Lavoie : reported a bug with Python 2.5                  
    38    
     36 
     37  - Yves Lavoie : reported a bug with Python 2.5 
     38 
    3939  - Kumar Appaiah : put pkpgcounter in Debian. 
    40    
     40 
    4141  - Roger Jochem : reported problems and test files for custom 
    4242                   made printer drivers. 
     
    5050  THINK YOU DESERVE TO BE LISTED, JUST SEND ME AN EMAIL 
    5151  ASKING FOR BEING INCLUDED. 
    52    
     52 
    5353  I APOLOGIZE IN ADVANCE IF I'VE FORGOTTEN TO ADD YOUR NAME. 
    54    
    55   ALSO, SOME PEOPLE MAY HAVE REFUSED TO BE LISTED HERE, THIS  
     54 
     55  ALSO, SOME PEOPLE MAY HAVE REFUSED TO BE LISTED HERE, THIS 
    5656  IS YOUR RIGHT TO DO SO TOO, JUST TELL ME. 
    57    
     57 
    5858============================================================== 
  • pkpgcounter/trunk/man/genman.sh

    r564 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    1919# $Id$ 
    2020# 
    21 for prog in pkpgcounter ; do  
     21for prog in pkpgcounter ; do 
    2222    echo "$prog" ; 
    2323    help2man --no-info \ 
     
    2727             --source="C@LL - Conseil Internet & Logiciels Libres" \ 
    2828             --output="temp$prog.1" \ 
    29              $prog ;  
     29             $prog ; 
    3030    /bin/sed -e "s/--/\\\-\\\-/g" <"temp$prog.1" >"$prog.1" ; 
    3131    /bin/rm -f "temp$prog.1" 
  • pkpgcounter/trunk/NEWS

    r3402 r3436  
    2222 
    2323  * 3.51 : 
    24    
     24 
    2525    - Partial rewrite of the PostScript parser, with huge performance increase. 
    26      
     26 
    2727    - Fixed a problem in the PostScript parser where the number of copies set with 
    28       e.g. "dvips -c 9 -o output.ps input.dvi" wasn't correctly detected.  
     28      e.g. "dvips -c 9 -o output.ps input.dvi" wasn't correctly detected. 
    2929 
    3030    - Increased accuracy in the PDF parser, with some speed expense but 
    3131      some big room for future improvements. 
    32        
     32 
    3333  * 3.50 : 
    34    
     34 
    3535    - Added support for Canon BJ/BJC documents in page counting mode. 
    36      
     36 
    3737    - Added support for Structured Fax documents in page counting mode. 
    38      
     38 
    3939    - Added support for ASCII PNM (Netpbm) documents in page counting mode. 
    40      
     40 
    4141    - Fixed a problem with the parsing of SPL1 (GDI) documents : all such 
    4242      documents should now be correctly parsed. 
    43      
     43 
    4444    - Improved the PCL3/4/5 parser. 
    45      
     45 
    4646  * 3.40 : 
    47    
     47 
    4848    - Fixed a major bug in the detection of OpenDocument (ISO/IEC DIS 26300) 
    4949      files. 
    50        
     50 
    5151    - Added support for page counting in Microsoft Word (c) (tm) (r) (etc...) 
    5252      documents. 
    53        
     53 
    5454    - Added support for ink accounting in Microsoft Word (c) (tm) (r) (etc...) 
    5555      and OpenDocument (ISO/IEC DIS 26300) documents. 
    56        
    57     - Now automatically detects missing executable dependencies at runtime.   
    58        
     56 
     57    - Now automatically detects missing executable dependencies at runtime. 
     58 
    5959  * 3.30 : 
    60    
     60 
    6161    - Added support for all file formats supported by the Python Imaging 
    6262      Library. 
    63      
    64     - Added a minimal parser for Hewlett-Packard LIDIL documents, as  
     63 
     64    - Added a minimal parser for Hewlett-Packard LIDIL documents, as 
    6565      produced by the hpijs driver. 
    66        
     66 
    6767    - Improved general reliability. 
    68      
     68 
    6969    - Improved detection of PCL3/4/5 jobs. 
    70      
    71     - Major code cleaning.   
    72        
     70 
     71    - Major code cleaning. 
     72 
    7373  * 3.20 : 
    74     
     74 
    7575    - Added a minimal parser for Brother HBP documents. 
    76      
     76 
    7777    - Added support for Canon ImageRunner commands to the PCLXL parser, 
    7878      much like it was already done for the PCL3/4/5 parser. 
    79        
     79 
    8080  * 3.10 : 
    81    
     81 
    8282    - Added a minimal parser for ESC/PAGES03 style documents. 
    83      
     83 
    8484    - Fixed another problem in the code handling the output of Canon's 
    8585      ImageRunner printer drivers. 
    86      
     86 
    8787  * 3.00 : 
    88    
     88 
    8989    - Fixed a problem in the code handling the output of Canon's ImageRunner 
    9090      printer drivers. 
    91        
    92     - Licensing terms changed to GNU GPL v3.0 or higher.   
    93      
     91 
     92    - Licensing terms changed to GNU GPL v3.0 or higher. 
     93 
    9494  * 2.18 : 
    95    
     95 
    9696    - Fixed an incompatibility with Python v2.5 
    97      
    98   * 2.17 :  
    99    
     97 
     98  * 2.17 : 
     99 
    100100    - Fixed problems in the handling of PJL number of copies (COPIES= and QTY=) 
    101101      which caused the number of copies for each page to be squared. 
    102      
    103   * 2.16 :  
    104    
     102 
     103  * 2.16 : 
     104 
    105105    - Fixed a problem in the PCL3/4/5 parser to accomodate line based 
    106106      report generators which expect the printer to skip to next page 
    107107      based on lines per page instead of sending a specific command. 
    108        
     108 
    109109  * 2.15 : 
    110     
     110 
    111111    - Fixed a regexp in the PDF parser which caused some files to be 
    112112      incorrectly accounted for. 
    113      
     113 
    114114    - Improved the detection of the number of copies in PostScript documents. 
    115      
     115 
    116116  * 2.14 : 
    117    
     117 
    118118    - Fixed a problem with some PS drivers which don't output %%Page: 
    119119      comments. 
    120        
    121   * 2.13 :  
    122     
     120 
     121  * 2.13 : 
     122 
    123123    - Nowrecognizes the GC colorspace if you only want to differentiate 
    124124      grayscale pages from coloured pages. In this colorspace, the 
    125125      percents are always "G : 100.0   C : 0.0" or "G : 0.0   C : 100.0" 
    126126      respectively for a grayscale page and a coloured page. 
    127    
     127 
    128128  * 2.12 : 
    129    
     129 
    130130    - Fixed a problem with the PostScript parser. 
    131      
     131 
    132132  * 2.11 : 
    133    
     133 
    134134    - Improved overall robustness in ink accounting mode. 
    135      
     135 
    136136  * 2.10 : 
    137    
     137 
    138138    - Added a plain text parser, with support for both page counting and 
    139139      ink coverage. 
    140      
     140 
    141141    - Added a minimal SPL1 parser. 
    142      
     142 
    143143    - Fixed a problem in the PCLXL parser related to Kyocera printer drivers. 
    144      
     144 
    145145  * 2.00 : 
    146    
     146 
    147147    - The PCL3/4/5 parser was rewritten from scratch and is now 
    148148      table driven. 
    149        
     149 
    150150    - Improved the PostScript parser. 
    151      
     151 
    152152  * 1.85 : 
    153    
     153 
    154154    - Added support for Samsung QPDL (aka SPL2) file format in page 
    155155      counting mode, thanks to the work done by Aur�en Croc on 
    156156      reverse engineering the file format. 
    157        
     157 
    158158  * 1.85alpha : 
    159    
     159 
    160160    - Added test document and program to generate the test document 
    161161      to check the functionning of the ink coverage computation algorithm. 
    162        
     162 
    163163  * 1.84 : 
    164    
     164 
    165165    - Computation of ink coverage now works and is documented. 
    166166      The supported file formats are : PS, PDF, PCLXL, PCL3/4/5, 
    167167      DVI and TIFF. 
    168        
     168 
    169169  * 1.84alpha : 
    170    
     170 
    171171    - Added initial support for the computation of ink coverage. 
    172172      See python analyzer.py --help for details. The same command 
    173173      line options work for pkpgcounter, although it's not 
    174174      documented yet. 
    175      
     175 
    176176  * 1.83 : 
    177    
    178     - Fixed a famously known 'brown paper bag' issue with file type autodetection.  
    179      
     177 
     178    - Fixed a famously known 'brown paper bag' issue with file type autodetection. 
     179 
    180180  * 1.82 : 
    181    
    182     - Fixed PCL3/4/5 parser to detect recent Xerox drivers' output.  
    183      
     181 
     182    - Fixed PCL3/4/5 parser to detect recent Xerox drivers' output. 
     183 
    184184  * 1.81 : 
    185    
     185 
    186186    - Improved the gs+Acrobat Reader fix done in 1.78. 
    187      
     187 
    188188  * 1.80 : 
    189    
     189 
    190190    - Added support for Zenographics ZjStream input format. 
    191      
     191 
    192192  * 1.79 : 
    193    
     193 
    194194    - Fixed a small problem in PostScript parser with dvips output. 
    195      
     195 
    196196  * 1.78 : 
    197    
     197 
    198198    - Launches gs less often when printing is done from Acrobat 
    199199      Reader. 
    200      
    201   * 1.77 :  
    202    
     200 
     201  * 1.77 : 
     202 
    203203    - Fixed some problems with the code introduced in 1.76. 
    204      
     204 
    205205    - Improved PCLXL parser's speed by almost 10%. 
    206      
     206 
    207207  * 1.76 : 
    208    
     208 
    209209    - Improved the PCLXL parser wrt undocumented tags. 
    210      
     210 
    211211    - Preliminary support for Kyocera Prescribe commands. 
    212      
     212 
    213213  * 1.75 : 
    214    
     214 
    215215    - Added preliminary support for Canon ImageRunner's "LIPS" or "UFR" 
    216       (I don't know which) Page Description Language.  
    217        
     216      (I don't know which) Page Description Language. 
     217 
    218218  * 1.74 : 
    219    
     219 
    220220    - Fixed a problem in the retrieval of named media sizes in PCLXL. 
    221      
     221 
    222222    - Changed copyright years. 
    223      
     223 
    224224  * 1.73 : 
    225    
     225 
    226226    - Fixed duplex detection code in PCL3/4/5 parser. 
    227      
     227 
    228228    - Fixed PCLXL detection code. 
    229      
     229 
    230230    - Fixed retrieval of custom media types' names in PCLXL. 
    231      
     231 
    232232    - Added inactive code to compute ink coverage ala PrintBill. 
    233      
     233 
    234234  * 1.72 : 
    235    
     235 
    236236    - Improved heuristic to detect when ghostscript has to be used to do 
    237237      the parsing. 
    238     
     238 
    239239  * 1.71 : 
    240    
     240 
    241241    - Now uses ghostscript as the parser when the PS stream was created by a 
    242242      particular MSWindows driver. 
    243      
     243 
    244244    - Only complains about Psyco missing at install time, and stays 
    245245      quiet when running without Psyco. 
    246        
     246 
    247247  * 1.70 : 
    248    
     248 
    249249    - Fixed some PJL escaping issue in the PCLXL and PCL3/4/5 parsers. 
    250      
     250 
    251251  * 1.69 : 
    252    
    253     - Improved PCL3/4/5 parser. 
    254      
     252 
     253    - Improved PCL3/4/5 parser. 
     254 
    255255    - Improved PCLXL parser wrt PJL stuff. 
    256      
     256 
    257257  * 1.68 : 
    258    
     258 
    259259    - Improved PostScript parser. 
    260      
     260 
    261261  * 1.67 : 
    262    
     262 
    263263    - Improved PostScript parser. 
    264      
    265     - Improved PCL3/4/5 parser. 
    266      
    267   * 1.66 :  
    268    
     264 
     265    - Improved PCL3/4/5 parser. 
     266 
     267  * 1.66 : 
     268 
    269269    - Improved PCLXL parser. 
    270      
    271     - Improved PCL3/4/5 parser. 
    272      
     270 
     271    - Improved PCL3/4/5 parser. 
     272 
    273273  * 1.65 : 
    274      
     274 
    275275    - Improved PostScript parser. 
    276      
    277     - Improved PCL3/4/5 parser. 
    278      
     276 
     277    - Improved PCL3/4/5 parser. 
     278 
    279279  * 1.64 : 
    280      
    281     - Improved PCL3/4/5 parser. 
    282      
     280 
     281    - Improved PCL3/4/5 parser. 
     282 
    283283  * 1.63 : 
    284    
     284 
    285285    - Now handles PJL statements to extract number of copies, duplex mode 
    286286      and paper size in the PCLXL and PCL3/4/5 parsers. 
    287      
     287 
    288288  * 1.62 : 
    289    
     289 
    290290    - Better handling of the number of copies in the PCLXL parser. 
    291      
     291 
    292292    - Better handling of the number of copies in the PCL3/4/5 parser. 
    293        
     293 
    294294  * 1.61 : 
    295    
    296     - Improved PCL3/4/5 parser. 
    297      
     295 
     296    - Improved PCL3/4/5 parser. 
     297 
    298298    - Better handling of the number of copies in the PostScript parser. 
    299299      Now the number can be different from page to page. 
    300      
    301   * 1.60 :  
    302    
     300 
     301  * 1.60 : 
     302 
    303303    - Improved PCLXL parser. 
    304      
     304 
    305305  * 1.59 : 
    306      
     306 
    307307    - Major rewrite of the PDF parser to correctly handle all line endings. 
    308        
     308 
    309309  * 1.58 : 
    310    
     310 
    311311    - Fix for PDF files which contain several versions of the same PDF object. 
    312      
     312 
    313313    - Doesn't break when python-psyco is not available. 
    314      
    315   * 1.57 :  
    316    
    317     - Fixed a recently introduced bug in binary postscript handling code.   
    318      
     314 
     315  * 1.57 : 
     316 
     317    - Fixed a recently introduced bug in binary postscript handling code. 
     318 
    319319  * 1.56 : 
    320    
     320 
    321321    - Renamed the library from pdlanalyzer into pkpgpdls to avoid problems 
    322322      when the code will be integrated back into PyKota. 
    323        
    324   * 1.55 :  
    325    
     323 
     324  * 1.55 : 
     325 
    326326    - Added support for OpenOffice.org Writer and Impress documents. 
    327      
     327 
    328328  * 1.54 : 
    329     
     329 
    330330    - Added online documentation and a manual page. 
    331      
    332   * 1.53 :  
    333    
     331 
     332  * 1.53 : 
     333 
    334334    - Moved code around to improve maintainability. 
    335      
    336   * 1.52 :  
    337    
     335 
     336  * 1.52 : 
     337 
    338338    - Added support for the TIFF format. 
    339      
    340   * 1.51 :  
    341    
     339 
     340  * 1.51 : 
     341 
    342342    - Added support for the DVI format. 
    343      
     343 
    344344  * 1.50 : 
    345    
     345 
    346346    - Major code changes to modularize. The pkpgcounter command line tool 
    347347      is now just an almost empty skeleton, which uses the pdlanalyzer 
    348348      library. 
    349        
    350     - Several improvements to the parsing code.   
    351        
     349 
     350    - Several improvements to the parsing code. 
     351 
    352352  * 1.00 : 
    353353 
  • pkpgcounter/trunk/pkpgpdls/analyzer.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    4343        self.colorspace = colorspace 
    4444        self.resolution = resolution 
    45      
    46      
    47 class PDLAnalyzer :     
     45 
     46 
     47class PDLAnalyzer : 
    4848    """Class for PDL autodetection.""" 
    4949    def __init__(self, filename, options=AnalyzerOptions()) : 
    5050        """Initializes the PDL analyzer. 
    51          
     51 
    5252           filename is the name of the file or '-' for stdin. 
    53            filename can also be a file-like object which  
     53           filename can also be a file-like object which 
    5454           supports read() and seek(). 
    5555        """ 
    5656        self.options = options 
    5757        self.filename = filename 
    58         self.workfile = None  
     58        self.workfile = None 
    5959        self.mustclose = None 
    60          
    61     def getJobSize(self) :     
     60 
     61    def getJobSize(self) : 
    6262        """Returns the job's size.""" 
    6363        size = 0 
     
    6767                pdlhandler = self.detectPDLHandler() 
    6868                size = pdlhandler.getJobSize() 
    69             except pdlparser.PDLParserError, msg :     
     69            except pdlparser.PDLParserError, msg : 
    7070                raise pdlparser.PDLParserError, "Unsupported file format for %s (%s)" % (self.filename, msg) 
    71         finally :     
     71        finally : 
    7272            self.closeFile() 
    7373        return size 
    74              
     74 
    7575    def getInkCoverage(self, colorspace=None, resolution=None) : 
    7676        """Extracts the percents of ink coverage from the input file.""" 
     
    8989                    pdlhandler.convertToTiffMultiPage24NC(filename, self.options.resolution) 
    9090                    result = inkcoverage.getInkCoverage(filename, cspace) 
    91                 finally :     
     91                finally : 
    9292                    dummyfile.close() 
    93             except pdlparser.PDLParserError, msg :     
     93            except pdlparser.PDLParserError, msg : 
    9494                raise pdlparser.PDLParserError, "Unsupported file format for %s (%s)" % (self.filename, msg) 
    9595        finally : 
    9696            self.closeFile() 
    9797        return result 
    98          
    99     def openFile(self) :     
     98 
     99    def openFile(self) : 
    100100        """Opens the job's data stream for reading.""" 
    101101        self.mustclose = False  # by default we don't want to close the file when finished 
    102102        if hasattr(self.filename, "read") and hasattr(self.filename, "seek") : 
    103             # filename is in fact a file-like object  
     103            # filename is in fact a file-like object 
    104104            infile = self.filename 
    105105        elif self.filename == "-" : 
    106106            # we must read from stdin 
    107107            infile = sys.stdin 
    108         else :     
     108        else : 
    109109            # normal file 
    110110            self.workfile = open(self.filename, "rb") 
    111111            self.mustclose = True 
    112112            return 
    113              
     113 
    114114        # Use a temporary file, always seekable contrary to standard input. 
    115115        self.workfile = tempfile.NamedTemporaryFile(mode="w+b") 
    116116        self.filename = self.workfile.name 
    117117        while True : 
    118             data = infile.read(pdlparser.MEGABYTE)  
     118            data = infile.read(pdlparser.MEGABYTE) 
    119119            if not data : 
    120120                break 
    121121            self.workfile.write(data) 
    122         self.workfile.flush()     
     122        self.workfile.flush() 
    123123        self.workfile.seek(0) 
    124              
    125     def closeFile(self) :         
     124 
     125    def closeFile(self) : 
    126126        """Closes the job's data stream if we have to.""" 
    127127        if self.mustclose : 
    128             self.workfile.close()     
    129          
     128            self.workfile.close() 
     129 
    130130    def readFirstAndLastBlocks(self, inputfile) : 
    131131        """Reads the first and last blocks of data.""" 
     
    136136            inputfile.seek(-pdlparser.LASTBLOCKSIZE, 2) 
    137137            lastblock = inputfile.read(pdlparser.LASTBLOCKSIZE) 
    138         except IOError :     
     138        except IOError : 
    139139            lastblock = "" 
    140         return (firstblock, lastblock)      
    141              
    142     def detectPDLHandler(self) :     
     140        return (firstblock, lastblock) 
     141 
     142    def detectPDLHandler(self) : 
    143143        """Tries to autodetect the document format. 
    144          
     144 
    145145           Returns the correct PDL handler class or None if format is unknown 
    146         """    
     146        """ 
    147147        if not os.stat(self.filename).st_size : 
    148148            raise pdlparser.PDLParserError, "input file %s is empty !" % str(self.filename) 
    149149        (firstblock, lastblock) = self.readFirstAndLastBlocks(self.workfile) 
    150              
     150 
    151151        # IMPORTANT : the order is important below. FIXME. 
    152152        for module in (postscript, \ 
     
    170170                       mscrap, \ 
    171171                       plain) :     # IMPORTANT : don't move this one up ! 
    172             try :                
    173                 return module.Parser(self, self.filename,  
     172            try : 
     173                return module.Parser(self, self.filename, 
    174174                                           (firstblock, lastblock)) 
    175175            except pdlparser.PDLParserError : 
    176176                pass # try next parser 
    177177        raise pdlparser.PDLParserError, "Analysis of first data block failed." 
    178              
    179 def main() :     
     178 
     179def main() : 
    180180    """Entry point for PDL Analyzer.""" 
    181181    import optparse 
    182182    from copy import copy 
    183      
     183 
    184184    def check_cichoice(option, opt, value) : 
    185185        """To add a CaseIgnore Choice option type.""" 
     
    187187        if valower in [v.lower() for v in option.cichoices] : 
    188188            return valower 
    189         else :     
     189        else : 
    190190            choices = ", ".join([repr(o) for o in option.cichoices]) 
    191191            raise optparse.OptionValueError( 
    192192                "option %s: invalid choice: %r (choose from %s)" 
    193193                % (opt, value, choices)) 
    194      
     194 
    195195    class MyOption(optparse.Option) : 
    196196        """New Option class, with CaseIgnore Choice type.""" 
     
    199199        TYPE_CHECKER = copy(optparse.Option.TYPE_CHECKER) 
    200200        TYPE_CHECKER["cichoice"] = check_cichoice 
    201          
    202     parser = optparse.OptionParser(option_class=MyOption,  
     201 
     202    parser = optparse.OptionParser(option_class=MyOption, 
    203203                                   usage="python analyzer.py [options] file1 [file2 ...]") 
    204     parser.add_option("-v", "--version",  
    205                             action="store_true",  
     204    parser.add_option("-v", "--version", 
     205                            action="store_true", 
    206206                            dest="version", 
    207207                            help="Show pkpgcounter's version number and exit.") 
    208     parser.add_option("-d", "--debug",  
    209                             action="store_true",  
     208    parser.add_option("-d", "--debug", 
     209                            action="store_true", 
    210210                            dest="debug", 
    211211                            help="Activate debug mode.") 
    212     parser.add_option("-c", "--colorspace",  
     212    parser.add_option("-c", "--colorspace", 
    213213                            dest="colorspace", 
    214214                            type="cichoice", 
    215215                            cichoices=["bw", "rgb", "cmyk", "cmy", "gc"], 
    216216                            help="Activate the computation of ink usage, and defines the colorspace to use. Supported values are 'BW', 'RGB', 'CMYK', 'CMY', and 'GC'.") 
    217     parser.add_option("-r", "--resolution",  
    218                             type="int",  
    219                             default=72,  
     217    parser.add_option("-r", "--resolution", 
     218                            type="int", 
     219                            default=72, 
    220220                            dest="resolution", 
    221221                            help="The resolution in DPI to use when checking ink usage. Lower resolution is faster but less accurate. Default is 72 dpi.") 
     
    223223    if options.version : 
    224224        print "%s" % version.__version__ 
    225     elif not (72 <= options.resolution <= 1200) :     
     225    elif not (72 <= options.resolution <= 1200) : 
    226226        sys.stderr.write("ERROR: the argument to the --resolution command line option must be between 72 and 1200.\n") 
    227227        sys.stderr.flush() 
     
    229229        if (not arguments) or ((not sys.stdin.isatty()) and ("-" not in arguments)) : 
    230230            arguments.append("-") 
    231         totalsize = 0     
     231        totalsize = 0 
    232232        lines = [] 
    233233        try : 
     
    246246                                except KeyError : 
    247247                                    pass 
    248                             lines.append("      ".join(lineparts))      
    249                 except (IOError, pdlparser.PDLParserError), msg :     
     248                            lines.append("      ".join(lineparts)) 
     249                except (IOError, pdlparser.PDLParserError), msg : 
    250250                    sys.stderr.write("ERROR: %s\n" % msg) 
    251251                    sys.stderr.flush() 
    252         except KeyboardInterrupt :             
     252        except KeyboardInterrupt : 
    253253            sys.stderr.write("WARN: Aborted at user's request.\n") 
    254254            sys.stderr.flush() 
    255         if not options.colorspace :     
     255        if not options.colorspace : 
    256256            print "%i" % totalsize 
    257         else :     
     257        else : 
    258258            print "\n".join(lines) 
    259      
    260 if __name__ == "__main__" :     
     259 
     260if __name__ == "__main__" : 
    261261    main() 
  • pkpgcounter/trunk/pkpgpdls/bj.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3030    """A parser for Canon BJ documents.""" 
    3131    format = "Canon BJ/BJC" 
    32     def isValid(self) :         
     32    def isValid(self) : 
    3333        """Returns True if data is BJ/BJC, else False.""" 
    3434        if self.firstblock.startswith("\033[K\002\000") : 
    3535            return True 
    36         else :     
     36        else : 
    3737            return False 
    38              
     38 
    3939    def getJobSize(self) : 
    4040        """Counts pages in a Canon BJ document. 
    41          
     41 
    4242           Algorithm by Jerome Alet. 
    43             
     43 
    4444           The documentation used for this was : 
    45           
     45 
    4646           ghostscript-8.60/src/gdevbj*.c 
    4747        """ 
     
    5757                        # through the Set Initial Condition command 
    5858                        pageheader = minfile[pos:pos+7] 
    59                         if pageheader in ("\033[K\002\000\000\017",  
     59                        if pageheader in ("\033[K\002\000\000\017", 
    6060                                          "\033[K\002\000\000\044", 
    6161                                          "\033[K\002\000\004\044") : 
     
    6565            except IndexError : # EOF ? 
    6666                pass 
    67         finally :         
     67        finally : 
    6868            minfile.close() # reached EOF 
    6969        return pagecount 
  • pkpgcounter/trunk/pkpgpdls/cfax.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    2929    """A parser for Structured Fax documents.""" 
    3030    format = "Structured Fax" 
    31     def isValid(self) :         
     31    def isValid(self) : 
    3232        """Returns True if data is Structured Fax, else False.""" 
    3333        if self.firstblock.startswith("Sfff") : 
    3434            return True 
    35         else :     
     35        else : 
    3636            return False 
    37              
     37 
    3838    def getJobSize(self) : 
    3939        """Counts pages in a Structured Fax document. 
    40          
     40 
    4141           Algorithm by Jerome Alet. 
    42             
     42 
    4343           The documentation used for this was : 
    44           
     44 
    4545           http://delphi.pjh2.de/articles/graphic/sff_format.php 
    4646        """ 
     
    5757             offsetlastpage, 
    5858             offsetdocumentend) = unpack("<4sBBHHHII", docheader) 
    59             self.infile.seek(offsetfirstpage - len(docheader), 1)      
     59            self.infile.seek(offsetfirstpage - len(docheader), 1) 
    6060            while True : 
    6161                headerid = self.infile.read(1) 
    6262                if not headerid : 
    6363                    break 
    64                 headerid = ord(headerid)     
     64                headerid = ord(headerid) 
    6565                if 1 <= headerid <= 216 : # Normal record header 
    6666                    self.infile.seek(headerid, 1) 
     
    6969                    if not additionalbyte : 
    7070                        break 
    71                     additionalbyte = ord(additionalbyte)     
     71                    additionalbyte = ord(additionalbyte) 
    7272                    if 1 <= additionalbyte <= 255 : 
    7373                        # Skip additional user information (reserved) 
    7474                        self.infile.seek(additionalbyte, 1) 
    75                 elif not headerid :         
     75                elif not headerid : 
    7676                    # Record with more than 216 MH-coded bytes 
    7777                    recordlen = self.infile.read(2) 
    7878                    if not recordlen : 
    7979                        break 
    80                     recordlen = unpack("<H", recordlen)[0]     
     80                    recordlen = unpack("<H", recordlen)[0] 
    8181                    self.infile.seek(recordlen, 1) 
    8282                elif headerid == 254 : # Page header 
    8383                    pageheader = self.infile.read(17) 
    84                     if not pageheader :  
     84                    if not pageheader : 
    8585                        break 
    8686                    headerlen = ord(pageheader[0]) 
     
    9595                     offsetpreviouspage, 
    9696                     offsetnextpage) = unpack("<4BHHII", pageheader[1:]) 
    97                     pagecount += 1     
     97                    pagecount += 1 
    9898                    if (offsetnextpage == 1) or (vres == 255) : 
    9999                        break # End Of Document 
    100                     self.infile.seek(offsetnextpage, 1)     
    101         except struct.error :      
     100                    self.infile.seek(offsetnextpage, 1) 
     101        except struct.error : 
    102102             raise pdlparser.PDLParserError, "Invalid Structured Fax datas" 
    103         return max(docpagecount, pagecount)      
     103        return max(docpagecount, pagecount) 
  • pkpgcounter/trunk/pkpgpdls/dvi.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3434    required = [ "dvips", "gs" ] 
    3535    format = "DVI" 
    36     def isValid(self) :         
     36    def isValid(self) : 
    3737        """Returns True if data is DVI, else False.""" 
    3838        try : 
     
    4040                and (ord(self.lastblock[-1]) == 0xdf) : 
    4141                return True 
    42             else :     
     42            else : 
    4343                return False 
    44         except IndexError :           
     44        except IndexError : 
    4545            return False 
    46              
     46 
    4747    def getJobSize(self) : 
    4848        """Counts pages in a DVI document. 
    49          
     49 
    5050           Algorithm by Jerome Alet. 
    51             
     51 
    5252           The documentation used for this was : 
    53           
     53 
    5454           http://www.math.umd.edu/~asnowden/comp-cont/dvi.html 
    5555        """ 
     
    6464                while minfile[pos] == eofchar : 
    6565                    pos -= 1 
    66                 idbyte = minfile[pos]     
     66                idbyte = minfile[pos] 
    6767                if idbyte != minfile[1] : 
    6868                    raise IndexError, "Invalid DVI file." 
     
    7373            except IndexError : # EOF ? 
    7474                pass 
    75         finally :         
     75        finally : 
    7676            minfile.close() # reached EOF 
    7777        return pagecount 
  • pkpgcounter/trunk/pkpgpdls/escp2.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    2929    """A parser for ESC/P2 documents.""" 
    3030    format = "ESC/P2" 
    31     def isValid(self) :         
     31    def isValid(self) : 
    3232        """Returns True if data is ESC/P2, else False.""" 
    3333        if self.firstblock.startswith("\033@") or \ 
     
    3636           self.firstblock.startswith("\0\0\0\033\1@EJL") : # ESC/P Raster ??? Seen on Stylus Photo 1284 
    3737            return True 
    38         else :     
     38        else : 
    3939            return False 
    40              
    41     def getJobSize(self) :     
     40 
     41    def getJobSize(self) : 
    4242        """Counts pages in an ESC/P2 document.""" 
    4343        # with Gimpprint, at least, for each page there 
    4444        # are two Reset Printer sequences (ESC + @) 
    4545        marker1 = "\033@" 
    46          
     46 
    4747        # with other software or printer driver, we 
    4848        # may prefer to search for "\r\n\fESCAPE" 
     
    5050        marker2r = "\r\f\033" 
    5151        marker2rn = "\r\n\f\033" 
    52          
     52 
    5353        # and ghostscript's stcolor for example seems to 
    5454        # output ESC + @ + \f for each page plus one 
    5555        marker3 = "\033@\f" 
    56          
     56 
    5757        # while ghostscript's escp driver outputs instead 
    5858        # \f + ESC + @ 
    5959        marker4 = "\f\033@" 
    60          
     60 
    6161        data = self.infile.read() 
    6262        pagecount1 = data.count(marker1) 
     
    6464        pagecount3 = data.count(marker3) 
    6565        pagecount4 = data.count(marker4) 
    66              
    67         if pagecount2 :     
     66 
     67        if pagecount2 : 
    6868            return pagecount2 
    69         elif pagecount3 > 1 :      
     69        elif pagecount3 > 1 : 
    7070            return pagecount3 - 1 
    71         elif pagecount4 :     
     71        elif pagecount4 : 
    7272            return pagecount4 
    73         else :     
    74             return int(pagecount1 / 2)        
     73        else : 
     74            return int(pagecount1 / 2) 
  • pkpgcounter/trunk/pkpgpdls/escpages03.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3333    """A parser for ESC/PageS03 documents.""" 
    3434    format = "ESC/PageS03" 
    35     def isValid(self) :         
     35    def isValid(self) : 
    3636        """Returns True if data is TIFF, else False.""" 
    3737        if self.firstblock.startswith("\033\1@EJL") and \ 
    3838            (self.firstblock.find("=ESC/PAGES03\n") != -1) : 
    3939            return True 
    40         else :     
     40        else : 
    4141            return False 
    42      
     42 
    4343    def getJobSize(self) : 
    4444        """Counts pages in an ESC/PageS03 document. 
    45          
     45 
    4646           Algorithm by Jerome Alet. 
    4747           Reverse engineered the file format. 
     
    6161        lgendsequence = len(endsequence) 
    6262        try : 
    63             try :     
     63            try : 
    6464                while True : 
    6565                    if minfile[startpos] == startsequence : 
     
    8282                            if pagecount.startswith('"') and pagecount.endswith('"') : 
    8383                                pagecount = pagecount[1:-1] 
    84                             pagecount = int(pagecount)     
     84                            pagecount = int(pagecount) 
    8585                            if pagecount <= 0 : 
    8686                                pagecount = 1 # TODO : 0 or 1000000 ??? ;-) 
    8787                            break 
    88                         startpos += 1     
    89             except IndexError :             
     88                        startpos += 1 
     89            except IndexError : 
    9090                pass 
    91         finally :         
     91        finally : 
    9292            minfile.close() 
    9393        return pagecount 
  • pkpgcounter/trunk/pkpgpdls/hbp.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3232    """A parser for HBP documents.""" 
    3333    format = "Brother HBP" 
    34     def isValid(self) :         
     34    def isValid(self) : 
    3535        """Returns True if data is HBP, else False.""" 
    3636        if self.firstblock.find("@PJL ENTER LANGUAGE = HBP\n") != -1 : 
    3737            return True 
    38         else :     
     38        else : 
    3939            return False 
    40              
     40 
    4141    def getJobSize(self) : 
    4242        """Counts pages in a HBP document. 
    43          
     43 
    4444           Algorithm by Jerome Alet. 
    45             
     45 
    4646           The documentation used for this was : 
    47           
     47 
    4848           http://sf.net/projects/hbp-for-brother/ 
    49             
     49 
    5050           IMPORTANT : this may not work since @F should be sufficient, 
    5151           but the documentation really is unclear and I don't know 
     
    5555        minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) 
    5656        pagecount = 0 
    57          
     57 
    5858        formfeed = "@G" + chr(0) + chr(0) + chr(1) + chr(0xff) + "@F" 
    5959        fflen = len(formfeed) 
     
    6666                        pagecount += 1 
    6767                        pos += fflen 
    68                     else :         
     68                    else : 
    6969                        pos += 1 
    7070            except IndexError : # EOF ? 
    7171                pass 
    72         finally :         
     72        finally : 
    7373            minfile.close() # reached EOF 
    7474        return pagecount 
  • pkpgcounter/trunk/pkpgpdls/__init__.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
  • pkpgcounter/trunk/pkpgpdls/inkcoverage.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    2828try : 
    2929    from PIL import Image 
    30 except ImportError :     
     30except ImportError : 
    3131    sys.stderr.write("ERROR: You MUST install the Python Imaging Library (python-imaging) for pkpgcounter to work.\n") 
    3232    raise pdlparser.PDLParserError, "The Python Imaging Library is missing." 
     
    3434def getPercent(img, nbpix) : 
    3535    """Extracts the percents per color component from a picture. 
    36        
     36 
    3737       Faster without Psyco on my own machine. 
    3838    """ 
    39     result = {}      
     39    result = {} 
    4040    bands = img.split() 
    4141    for (i, bandname) in enumerate(img.getbands()) : 
    4242        result[bandname] = 100.0 * (reduce(lambda current, next: current + (next[1] * next[0]), enumerate(bands[i].histogram()), 0) / 255.0) / nbpix 
    43     return result     
    44      
     43    return result 
     44 
    4545def getPercentCMYK(img, nbpix) : 
    4646    """Extracts the percents of Cyan, Magenta, Yellow, and Black from a picture. 
    47       
     47 
    4848       PIL doesn't produce useable CMYK for our algorithm, so we use the algorithm from PrintBill. 
    4949       Psyco speeds this function up by around 2.5 times on my computer. 
     
    5151    if img.mode != "RGB" : 
    5252        img = img.convert("RGB") 
    53     cyan = magenta = yellow = black = 0     
     53    cyan = magenta = yellow = black = 0 
    5454    for (r, g, b) in img.getdata() : 
    5555        if r == g == b : 
    5656            black += 255 - r 
    57         else :     
     57        else : 
    5858            cyan += 255 - r 
    5959            magenta += 255 - g 
     
    6464             "K" : 100.0 * (black / 255.0) / nbpix, 
    6565           } 
    66          
    67 def getPercentGC(img, nbpix) :         
     66 
     67def getPercentGC(img, nbpix) : 
    6868    """Determines if a page is in grayscale or colour mode.""" 
    6969    if img.mode != "RGB" : 
     
    7575            return { "G" : 0.0, "C" : 100.0 } 
    7676    return { "G" : 100.0, "C" : 0.0 } 
    77      
     77 
    7878def getPercentBW(img, nbpix) : 
    7979    """Extracts the percents of Black from a picture, once converted to gray levels.""" 
     
    8181        img = img.convert("L") 
    8282    return { "B" : 100.0 - getPercent(img, nbpix)["L"] } 
    83      
     83 
    8484def getPercentRGB(img, nbpix) : 
    8585    """Extracts the percents of Red, Green, Blue from a picture, once converted to RGB.""" 
    8686    if img.mode != "RGB" : 
    8787        img = img.convert("RGB") 
    88     return getPercent(img, nbpix)     
    89      
     88    return getPercent(img, nbpix) 
     89 
    9090def getPercentCMY(img, nbpix) : 
    9191    """Extracts the percents of Cyan, Magenta, and Yellow from a picture once converted to RGB.""" 
     
    9595             "Y" : 100.0 - result["B"], 
    9696           } 
    97      
     97 
    9898def getInkCoverage(fname, colorspace) : 
    99     """Returns a list of dictionnaries containing for each page,  
    100        for each color component, the percent of ink coverage on  
     99    """Returns a list of dictionnaries containing for each page, 
     100       for each color component, the percent of ink coverage on 
    101101       that particular page. 
    102102    """ 
     
    107107        try : 
    108108            import psyco 
    109         except ImportError :     
     109        except ImportError : 
    110110            pass 
    111         else :     
     111        else : 
    112112            psyco.bind(getPercentCMYK) 
    113      
     113 
    114114    index = 0 
    115115    try : 
    116116        image = Image.open(fname) 
    117     except (IOError, OverflowError), msg :    
     117    except (IOError, OverflowError), msg : 
    118118        raise pdlparser.PDLParserError, "%s (%s)" % (msg, fname) 
    119     else :     
     119    else : 
    120120        try : 
    121121            while True : 
    122122                nbpixels = image.size[0] * image.size[1] 
    123123                result.append(computation(image, nbpixels)) 
    124                 index += 1               
     124                index += 1 
    125125                image.seek(index) 
    126         except EOFError :         
     126        except EOFError : 
    127127            pass 
    128128        return (colorspace, result) 
  • pkpgcounter/trunk/pkpgpdls/lidil.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    2222"""This modules implements a page counter for HP LIDIL format. 
    2323 
    24    Documentation used :  
    25     
     24   Documentation used : 
     25 
    2626        hplip-2.7.10/prnt/ldl.py 
    2727        hplip-2.7.10/prnt/hpijs/ldlencap.h 
     
    5252    """A parser for HP LIDIL documents.""" 
    5353    format = "Hewlett-Packard LIDIL" 
    54     def isValid(self) :     
     54    def isValid(self) : 
    5555        """Returns True if data is LIDIL, else False.""" 
    5656        # Beginning Of File marker is a Sync packet, followed with 
     
    6161        # with a Reset packet. We ignore the preceding Sync packet 
    6262        # for simplicity's sake. 
    63         EOFMarker = "$\x00\x10\x00\x08\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff$$\x00\x10\x00\x06\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff$"  
     63        EOFMarker = "$\x00\x10\x00\x08\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff$$\x00\x10\x00\x06\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff$" 
    6464        if self.firstblock.startswith(BOFMarker) \ 
    6565           and self.lastblock.endswith(EOFMarker) : 
    6666            return True 
    67         else :     
     67        else : 
    6868            return False 
    69          
     69 
    7070    def getJobSize(self) : 
    7171        """Computes the number of pages in a HP LIDIL document.""" 
     
    8080                    # Invalid header or no Frame Sync byte. 
    8181                    raise pdlparser.PDLParserError, "This file doesn't seem to be valid Hewlett-Packard LIDIL datas." 
    82                 (framesync,      
     82                (framesync, 
    8383                 cmdlength, 
    8484                 dummy, 
     
    9393                        ejectpage += 1 
    9494                self.infile.seek(cmdlength + datalength - len(header), 1) # relative seek 
    95         except struct.error :     
     95        except struct.error : 
    9696            raise pdlparser.PDLParserError, "This file doesn't seem to be valid Hewlett-Packard LIDIL datas." 
    97              
     97 
    9898        # Number of page eject commands should be sufficient, 
    9999        # but we never know : someone could try to cheat the printer 
  • pkpgcounter/trunk/pkpgpdls/mscrap.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3333    required = [ "xvfb-run", "xauth", "abiword", "gs" ] 
    3434    format = "Microsoft shitty" 
    35     def isValid(self) :     
     35    def isValid(self) : 
    3636        """Returns True if data is MS crap, else False. 
    37          
     37 
    3838           Identifying datas taken from the file command's magic database. 
    3939           IMPORTANT : some magic values are not reused here because they 
    4040           IMPORTANT : seem to be specific to some particular i18n release. 
    41         """    
     41        """ 
    4242        if self.firstblock.startswith("PO^Q`") \ 
    4343           or self.firstblock.startswith("\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1") \ 
     
    4949            if self.isMissing(self.required) : 
    5050                return False 
    51             else :     
     51            else : 
    5252                return True 
    53         else :     
     53        else : 
    5454            return False 
    55              
     55 
    5656    def getJobSize(self) : 
    5757        """Counts pages in a Microsoft Word (r) (tm) (c) (etc...) document. 
     
    7171                (first, last) = self.parent.readFirstAndLastBlocks(psinputfile) 
    7272                import postscript 
    73                 return postscript.Parser(self.parent,  
    74                                          outfname,  
     73                return postscript.Parser(self.parent, 
     74                                         outfname, 
    7575                                         (first, last)).getJobSize() 
    7676            finally : 
    7777                psinputfile.close() 
    78         finally :     
     78        finally : 
    7979            workfile.close() 
    8080        raise pdlparser.PDLParserError, "Impossible to count pages in %(infname)s" % locals() 
  • pkpgcounter/trunk/pkpgpdls/ooo.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3232    required = [ "xvfb-run", "xauth", "abiword", "gs" ] 
    3333    format = "ISO/IEC DIS 26300" 
    34     def isValid(self) :         
     34    def isValid(self) : 
    3535        """Returns True if data is OpenDocument, else False.""" 
    3636        if self.firstblock[:2] == "PK" : 
     
    3939                self.contentxml = self.archive.read("content.xml") 
    4040                self.metaxml = self.archive.read("meta.xml") 
    41             except :     
     41            except : 
    4242                return False 
    4343            else : 
    4444                return True 
    45         else :     
     45        else : 
    4646            return False 
    47              
     47 
    4848    def getJobSize(self) : 
    4949        """Counts pages in an OpenOffice.org document. 
    50          
     50 
    5151           Algorithm by Jerome Alet. 
    5252        """ 
  • pkpgcounter/trunk/pkpgpdls/pcl345.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3838class Parser(pdlparser.PDLParser) : 
    3939    """A parser for PCL3, PCL4, PCL5 documents.""" 
    40     totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(outfname)s" -',  
     40    totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(outfname)s" -', 
    4141                       'pcl6 -sDEVICE=pswrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(outfname)s" -', 
    4242                     ] 
     
    4848                    2 : "Letter", 
    4949                    3 : "Legal", 
    50                     6 : "Ledger",  
     50                    6 : "Ledger", 
    5151                    25 : "A5", 
    5252                    26 : "A4", 
     
    6262                    100 : "B5Envelope", 
    6363                    101 : "Custom", 
    64                  }    
    65                   
     64                 } 
     65 
    6666    mediasources = { # ESC&l####H 
    6767                     0 : "Default", 
     
    7575                     8 : "Tray1", 
    7676                   } 
    77                     
     77 
    7878    orientations = { # ESC&l####O 
    7979                     0 : "Portrait", 
     
    8282                     3 : "ReverseLandscape", 
    8383                   } 
    84                     
     84 
    8585    mediatypes = { # ESC&l####M 
    8686                     0 : "Plain", 
     
    9090                     4 : "Transparent", 
    9191                   } 
    92          
    93     def isValid(self) :     
     92 
     93    def isValid(self) : 
    9494        """Returns True if data is PCL3/4/5, else False.""" 
    9595        try : 
     
    9797            while self.firstblock[pos] == chr(0) : 
    9898                pos += 1 
    99         except IndexError :         
     99        except IndexError : 
    100100            return False 
    101         else :     
     101        else : 
    102102            firstblock = self.firstblock[pos:] 
    103103            if firstblock.startswith("\033E\033") or \ 
     
    111111               (firstblock.startswith(chr(0xcd)+chr(0xca)) and (firstblock.find("\033E\033") != -1)) : 
    112112                return True 
    113             else :     
     113            else : 
    114114                return False 
    115          
     115 
    116116    def setPageDict(self, attribute, value) : 
    117117        """Initializes a page dictionnary.""" 
    118118        dic = self.pages.setdefault(self.pagecount, { "linescount" : 1, 
    119                                                       "copies" : 1,  
    120                                                       "mediasource" : "Main",  
    121                                                       "mediasize" : "Default",  
    122                                                       "mediatype" : "Plain",  
    123                                                       "orientation" : "Portrait",  
    124                                                       "escaped" : "",  
     119                                                      "copies" : 1, 
     120                                                      "mediasource" : "Main", 
     121                                                      "mediasize" : "Default", 
     122                                                      "mediatype" : "Plain", 
     123                                                      "orientation" : "Portrait", 
     124                                                      "escaped" : "", 
    125125                                                      "duplex": 0 }) 
    126126        dic[attribute] = value 
    127          
    128     def readByte(self) :     
     127 
     128    def readByte(self) : 
    129129        """Reads a byte from the input stream.""" 
    130130        tag = ord(self.minfile[self.pos]) 
    131131        self.pos += 1 
    132132        return tag 
    133          
    134     def endPage(self) :     
     133 
     134    def endPage(self) : 
    135135        """Handle the FF marker.""" 
    136136        #self.logdebug("FORMFEED %i at %08x" % (self.pagecount, self.pos-1)) 
     
    138138            # Increments page count only if we are not inside an HPGL2 block 
    139139            self.pagecount += 1 
    140          
    141     def escPercent(self) :     
     140 
     141    def escPercent(self) : 
    142142        """Handles the ESC% sequence.""" 
    143143        if self.minfile[self.pos : self.pos+7] == r"-12345X" : 
     
    147147            quotes = 0 
    148148            char = chr(self.readByte()) 
    149             while ((char < ASCIILIMIT) or (quotes % 2)) and (char not in (FORMFEED, ESCAPE, NUL)) :   
     149            while ((char < ASCIILIMIT) or (quotes % 2)) and (char not in (FORMFEED, ESCAPE, NUL)) : 
    150150                buffer.append(char) 
    151151                if char == '"' : 
     
    155155            #self.logdebug("ESCAPED : %s" % "".join(buffer)) 
    156156            self.pos -= 1   # Adjust position 
    157         else :     
     157        else : 
    158158            while 1 : 
    159159                (value, end) = self.getInteger() 
     
    162162                    while self.minfile[self.pos] != ESCAPE : 
    163163                        self.pos += 1 
    164                     self.pos -= 1     
    165                     return  
    166                 elif end == 'A' :     
     164                    self.pos -= 1 
     165                    return 
     166                elif end == 'A' : 
    167167                    self.exitHPGL2() 
    168168                    return 
    169                 elif end is None :     
     169                elif end is None : 
    170170                    return 
    171          
    172     def enterHPGL2(self) :     
     171 
     172    def enterHPGL2(self) : 
    173173        """Enters HPGL2 mode.""" 
    174174        #self.logdebug("ENTERHPGL2 %08x" % self.pos) 
    175175        self.hpgl2 = True 
    176          
    177     def exitHPGL2(self) :     
     176 
     177    def exitHPGL2(self) : 
    178178        """Exits HPGL2 mode.""" 
    179179        #self.logdebug("EXITHPGL2 %08x" % self.pos) 
    180180        self.hpgl2 = False 
    181          
    182     def handleTag(self, tagtable) :     
     181 
     182    def handleTag(self, tagtable) : 
    183183        """Handles tags.""" 
    184184        tagtable[self.readByte()]() 
    185          
    186     def escape(self) :     
     185 
     186    def escape(self) : 
    187187        """Handles the ESC character.""" 
    188188        #self.logdebug("ESCAPE") 
    189189        self.handleTag(self.esctags) 
    190          
    191     def escAmp(self) :     
     190 
     191    def escAmp(self) : 
    192192        """Handles the ESC& sequence.""" 
    193193        #self.logdebug("AMP") 
    194194        self.handleTag(self.escamptags) 
    195          
    196     def escStar(self) :     
     195 
     196    def escStar(self) : 
    197197        """Handles the ESC* sequence.""" 
    198198        #self.logdebug("STAR") 
    199199        self.handleTag(self.escstartags) 
    200          
    201     def escLeftPar(self) :     
     200 
     201    def escLeftPar(self) : 
    202202        """Handles the ESC( sequence.""" 
    203203        #self.logdebug("LEFTPAR") 
    204204        self.handleTag(self.escleftpartags) 
    205          
    206     def escRightPar(self) :     
     205 
     206    def escRightPar(self) : 
    207207        """Handles the ESC( sequence.""" 
    208208        #self.logdebug("RIGHTPAR") 
    209209        self.handleTag(self.escrightpartags) 
    210          
    211     def escE(self) :     
     210 
     211    def escE(self) : 
    212212        """Handles the ESCE sequence.""" 
    213213        #self.logdebug("RESET") 
    214214        self.resets += 1 
    215          
    216     def escAmpl(self) :     
     215 
     216    def escAmpl(self) : 
    217217        """Handles the ESC&l sequence.""" 
    218218        while 1 : 
     
    244244                self.setPageDict("copies", value) 
    245245                #self.logdebug("COPIES %i" % value) 
    246             elif end == 'F' :     
     246            elif end == 'F' : 
    247247                self.linesperpagevalues.append(value) 
    248248                self.linesperpage = value 
     
    250250            #else : 
    251251            #    self.logdebug("Unexpected end <%s> and value <%s>" % (end, value)) 
    252                  
    253     def escAmpa(self) :     
     252 
     253    def escAmpa(self) : 
    254254        """Handles the ESC&a sequence.""" 
    255255        while 1 : 
     
    257257            if value is None : 
    258258                return 
    259             if end == 'G' :     
     259            if end == 'G' : 
    260260                #self.logdebug("BACKSIDES %i" % value) 
    261261                self.backsides.append(value) 
    262262                self.setPageDict("duplex", value) 
    263                  
    264     def escAmpp(self) :     
     263 
     264    def escAmpp(self) : 
    265265        """Handles the ESC&p sequence.""" 
    266266        while 1 : 
     
    268268            if value is None : 
    269269                return 
    270             if end == 'X' :     
     270            if end == 'X' : 
    271271                self.pos += value 
    272272                #self.logdebug("SKIPTO %08x" % self.pos) 
    273                  
    274     def escStarb(self) :     
     273 
     274    def escStarb(self) : 
    275275        """Handles the ESC*b sequence.""" 
    276276        while 1 : 
     
    278278            if (end is None) and (value is None) : 
    279279                return 
    280             if end in ('V', 'W', 'v', 'w') :     
     280            if end in ('V', 'W', 'v', 'w') : 
    281281                self.pos += (value or 0) 
    282282                #self.logdebug("SKIPTO %08x" % self.pos) 
    283                  
    284     def escStarr(self) :     
     283 
     284    def escStarr(self) : 
    285285        """Handles the ESC*r sequence.""" 
    286286        while 1 : 
     
    289289                if end is None : 
    290290                    return 
    291                 elif end in ('B', 'C') :         
     291                elif end in ('B', 'C') : 
    292292                    #self.logdebug("EndGFX") 
    293293                    if self.startgfx : 
    294294                        self.endgfx.append(1) 
    295                     else :     
     295                    else : 
    296296                        #self.logdebug("EndGFX found before StartGFX, ignored.") 
    297297                        pass 
     
    299299                #self.logdebug("StartGFX %i" % value) 
    300300                self.startgfx.append(value) 
    301                  
    302     def escStaroptAmpu(self) :     
     301 
     302    def escStaroptAmpu(self) : 
    303303        """Handles the ESC*o ESC*p ESC*t and ESC&u sequences.""" 
    304304        while 1 : 
     
    306306            if value is None : 
    307307                return 
    308          
    309     def escSkipSomethingW(self) :     
     308 
     309    def escSkipSomethingW(self) : 
    310310        """Handles the ESC???###W sequences.""" 
    311311        while 1 : 
     
    313313            if value is None : 
    314314                return 
    315             if end == 'W' :     
     315            if end == 'W' : 
    316316                self.pos += value 
    317317                #self.logdebug("SKIPTO %08x" % self.pos) 
    318                  
    319     def newLine(self) :             
     318 
     319    def newLine(self) : 
    320320        """Handles new lines markers.""" 
    321321        if not self.hpgl2 : 
    322322            dic = self.pages.get(self.pagecount, None) 
    323323            if dic is None : 
    324                 self.setPageDict("linescount", 1)                               
     324                self.setPageDict("linescount", 1) 
    325325                dic = self.pages.get(self.pagecount) 
    326             nblines = dic["linescount"]     
    327             self.setPageDict("linescount", nblines + 1)                               
     326            nblines = dic["linescount"] 
     327            self.setPageDict("linescount", nblines + 1) 
    328328            if (self.linesperpage is not None) \ 
    329329               and (dic["linescount"] > self.linesperpage) : 
    330330                self.pagecount += 1 
    331          
    332     def getInteger(self) :     
     331 
     332    def getInteger(self) : 
    333333        """Returns an integer value and the end character.""" 
    334334        sign = 1 
     
    346346                else : 
    347347                    return (value, char) 
    348             else :     
    349                 value = ((value or 0) * 10) + int(char)     
    350          
    351     def skipByte(self) :     
     348            else : 
     349                value = ((value or 0) * 10) + int(char) 
     350 
     351    def skipByte(self) : 
    352352        """Skips a byte.""" 
    353353        #self.logdebug("SKIPBYTE %08x ===> %02x" % (self.pos, ord(self.minfile[self.pos]))) 
    354354        self.pos += 1 
    355          
    356     def handleImageRunner(self) :     
     355 
     356    def handleImageRunner(self) : 
    357357        """Handles Canon ImageRunner tags.""" 
    358358        tag = self.readByte() 
     
    367367        else : 
    368368            self.pos -= 1 # Adjust position 
    369                  
    370     def getJobSize(self) :      
     369 
     370    def getJobSize(self) : 
    371371        """Count pages in a PCL5 document. 
    372           
     372 
    373373           Should also work for PCL3 and PCL4 documents. 
    374             
     374 
    375375           Algorithm from pclcount 
    376            (c) 2003, by Eduardo Gielamo Oliveira & Rodolfo Broco Manin  
     376           (c) 2003, by Eduardo Gielamo Oliveira & Rodolfo Broco Manin 
    377377           published under the terms of the GNU General Public Licence v2. 
    378            
     378 
    379379           Backported from C to Python by Jerome Alet, then enhanced 
    380380           with more PCL tags detected. I think all the necessary PCL tags 
    381381           are recognized to correctly handle PCL5 files wrt their number 
    382382           of pages. The documentation used for this was : 
    383           
     383 
    384384           HP PCL/PJL Reference Set 
    385385           PCL5 Printer Language Technical Quick Reference Guide 
    386            http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13205/bpl13205.pdf  
     386           http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13205/bpl13205.pdf 
    387387        """ 
    388388        infileno = self.infile.fileno() 
     
    405405        self.imagerunnermarker2 = chr(0x10) + chr(0x02) 
    406406        self.isimagerunner = (minfile[:2] == self.imagerunnermarker1) 
    407          
     407 
    408408        tags = [ lambda : None] * 256 
    409409        tags[ord(LINEFEED)] = self.newLine 
     
    412412        tags[ord(ASCIILIMIT)] = self.skipByte 
    413413        tags[ord(self.imagerunnermarker1[0])] = self.handleImageRunner 
    414          
     414 
    415415        self.esctags = [ lambda : None ] * 256 
    416416        self.esctags[ord('%')] = self.escPercent 
     
    420420        self.esctags[ord(')')] = self.escRightPar 
    421421        self.esctags[ord('E')] = self.escE 
    422          
     422 
    423423        self.escamptags = [lambda : None ] * 256 
    424424        self.escamptags[ord('a')] = self.escAmpa 
     
    428428        self.escamptags[ord('n')] = self.escSkipSomethingW 
    429429        self.escamptags[ord('u')] = self.escStaroptAmpu 
    430          
     430 
    431431        self.escstartags = [ lambda : None ] * 256 
    432432        self.escstartags[ord('b')] = self.escStarb 
     
    441441        self.escstartags[ord('m')] = self.escSkipSomethingW 
    442442        self.escstartags[ord('v')] = self.escSkipSomethingW 
    443          
     443 
    444444        self.escleftpartags = [ lambda : None ] * 256 
    445445        self.escleftpartags[ord('s')] = self.escSkipSomethingW 
    446446        self.escleftpartags[ord('f')] = self.escSkipSomethingW 
    447          
     447 
    448448        self.escrightpartags = [ lambda : None ] * 256 
    449449        self.escrightpartags[ord('s')] = self.escSkipSomethingW 
    450          
     450 
    451451        self.pos = 0 
    452452        try : 
     
    454454                while 1 : 
    455455                    tags[self.readByte()]() 
    456             except IndexError : # EOF ?             
     456            except IndexError : # EOF ? 
    457457                pass 
    458458        finally : 
    459459            self.minfile.close() 
    460          
     460 
    461461        self.logdebug("Pagecount : \t\t\t%i" % self.pagecount) 
    462462        self.logdebug("Resets : \t\t\t%i" % self.resets) 
     
    482482        self.logdebug("NbBackSides : \t\t\t%i" % nbbacksides) 
    483483        self.logdebug("IsImageRunner : \t\t\t%s" % self.isimagerunner) 
    484          
     484 
    485485        if self.isimagerunner : 
    486486            self.logdebug("Adjusting PageCount : +1") 
    487487            self.pagecount += 1      # ImageRunner adjustment 
    488         elif self.linesperpage is not None :     
     488        elif self.linesperpage is not None : 
    489489            self.logdebug("Adjusting PageCount : +1") 
    490490            self.pagecount += 1      # Adjusts for incomplete last page 
     
    507507            self.logdebug("Adjusting PageCount : -1") 
    508508            self.pagecount -= 1 
    509                      
     509 
    510510        self.pagecount = self.pagecount or nbmediasourcesdefault or nbmediasizes or nborientations or self.resets 
    511          
     511 
    512512        if not self.pagecount : 
    513513            if self.resets == len(self.startgfx) : 
    514                 self.pagecount = self.resets  
    515          
    516         defaultpjlcopies = 1     
     514                self.pagecount = self.resets 
     515 
     516        defaultpjlcopies = 1 
    517517        defaultduplexmode = "Simplex" 
    518518        defaultpapersize = "" 
     
    539539                    pjlcopies = nbqty 
    540540                else : 
    541                     if oldpjlcopies == -1 :     
     541                    if oldpjlcopies == -1 : 
    542542                        pjlcopies = defaultpjlcopies 
    543                     else :     
    544                         pjlcopies = oldpjlcopies     
    545                 if page["duplex"] :         
     543                    else : 
     544                        pjlcopies = oldpjlcopies 
     545                if page["duplex"] : 
    546546                    duplexmode = "Duplex" 
    547                 else :     
     547                else : 
    548548                    defaultdm = pjlparser.default_variables.get("DUPLEX", "") 
    549549                    if defaultdm : 
    550550                        if defaultdm.upper() == "ON" : 
    551551                            defaultduplexmode = "Duplex" 
    552                         else :     
     552                        else : 
    553553                            defaultduplexmode = "Simplex" 
    554554                    envdm = pjlparser.environment_variables.get("DUPLEX", "") 
     
    556556                        if envdm.upper() == "ON" : 
    557557                            duplexmode = "Duplex" 
    558                         else :     
     558                        else : 
    559559                            duplexmode = "Simplex" 
    560                     else :         
     560                    else : 
    561561                        duplexmode = oldduplexmode or defaultduplexmode 
    562562                defaultps = pjlparser.default_variables.get("PAPER", "") 
     
    566566                if envps : 
    567567                    papersize = envps 
    568                 else :     
     568                else : 
    569569                    if not oldpapersize : 
    570570                        papersize = defaultpapersize 
    571                     else :     
     571                    else : 
    572572                        papersize = oldpapersize 
    573             else :         
     573            else : 
    574574                if oldpjlcopies == -1 : 
    575575                    pjlcopies = defaultpjlcopies 
    576                 else :     
     576                else : 
    577577                    pjlcopies = oldpjlcopies 
    578                  
     578 
    579579                duplexmode = (page["duplex"] and "Duplex") or oldduplexmode or defaultduplexmode 
    580                 if not oldpapersize :     
     580                if not oldpapersize : 
    581581                    papersize = defaultpapersize 
    582                 else :     
     582                else : 
    583583                    papersize = oldpapersize 
    584584                papersize = oldpapersize or page["mediasize"] 
    585585            if page["mediasize"] != "Default" : 
    586586                papersize = page["mediasize"] 
    587             if not duplexmode :     
     587            if not duplexmode : 
    588588                duplexmode = oldduplexmode or defaultduplexmode 
    589             oldpjlcopies = pjlcopies     
     589            oldpjlcopies = pjlcopies 
    590590            oldduplexmode = duplexmode 
    591591            oldpapersize = papersize 
     
    598598                                              page["mediasource"], \ 
    599599                                              duplexmode)) 
    600          
     600 
    601601        return self.pagecount 
  • pkpgcounter/trunk/pkpgpdls/pclxl.py

    r3409 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3232class Parser(pdlparser.PDLParser) : 
    3333    """A parser for PCLXL (aka PCL6) documents.""" 
    34     totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -',  
     34    totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -', 
    3535                       'pcl6 -sDEVICE=pswrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -', 
    3636                     ] 
    3737    required = [ "pcl6", "gs" ] 
    3838    format = "PCLXL (aka PCL6)" 
    39     mediasizes = {  
     39    mediasizes = { 
    4040                    0 : "Letter", 
    4141                    1 : "Legal", 
     
    6161                    21 : "JISExec", 
    6262                    96 : "Default", 
    63                  }    
    64                   
    65     mediasources = {              
     63                 } 
     64 
     65    mediasources = { 
    6666                     0 : "Default", 
    6767                     1 : "Auto", 
     
    7373                     7 : "ThirdCassette", 
    7474                   } 
    75                     
    76     orientations = {                
     75 
     76    orientations = { 
    7777                     0 : "Portrait", 
    7878                     1 : "Landscape", 
     
    8181                     4 : "Default", 
    8282                   } 
    83              
    84     def isValid(self) :     
     83 
     84    def isValid(self) : 
    8585        """Returns True if data is HP PCLXL aka PCL6, or Brother's' XL2HB, else False.""" 
    8686        if (((self.firstblock[:128].find("\033%-12345X") != -1) and \ 
     
    9494            self.format = "XL2HB" 
    9595            return True 
    96         else :     
     96        else : 
    9797            return False 
    98              
     98 
    9999    def beginPage(self, nextpos) : 
    100100        """Indicates the beginning of a new page, and extracts media information.""" 
    101101        # self.logdebug("BeginPage at %x" % nextpos) 
    102102        self.pagecount += 1 
    103          
     103 
    104104        # Default values 
    105105        mediatypelabel = "Plain" 
     
    108108        orientationlabel = "Portrait" 
    109109        duplexmode = None 
    110          
     110 
    111111        # Now go upstream to decode media type, size, source, and orientation 
    112112        # this saves time because we don't need a complete parser ! 
     
    117117            if val in (0x44, 0x48, 0x41) : # if previous endPage or openDataSource or beginSession (first page) 
    118118                break 
    119             if val == 0x26 :     
     119            if val == 0x26 : 
    120120                mediasource = ord(minfile[pos - 2]) 
    121121                mediasourcelabel = self.mediasources.get(mediasource, str(mediasource)) 
     
    132132                        mediasizelabel = minfile[pos+2:pos+2+arraylength].title() 
    133133                        pos -= 1 
    134                     else :     
     134                    else : 
    135135                        # if we just found an ubyte, then the media 
    136136                        # size is known by its index 
    137137                        mediasize = ord(minfile[pos+1]) 
    138138                        mediasizelabel = self.mediasizes.get(mediasize, str(mediasize)) 
    139                     pos -= 1  
     139                    pos -= 1 
    140140                    # self.logdebug("Media size : %s" % mediasizelabel) 
    141             elif val == 0x28 :     
     141            elif val == 0x28 : 
    142142                orientation = ord(minfile[pos - 2]) 
    143143                orientationlabel = self.orientations.get(orientation, str(orientation)) 
    144144                pos -= 4 
    145             elif val == 0x27 :     
     145            elif val == 0x27 : 
    146146                savepos = pos 
    147147                pos -= 1 
    148                 startpos = size = None  
     148                startpos = size = None 
    149149                while pos > 0 : # safety check : don't go back to far ! 
    150150                    val = ord(minfile[pos]) 
    151                     pos -= 1     
     151                    pos -= 1 
    152152                    if val == 0xc8 : 
    153153                        length = self.tags[ord(minfile[pos+2])] # will probably always be a byte or uint16 
    154                         if length == 1 :     
     154                        if length == 1 : 
    155155                            startpos = pos + 4 
    156156                            size = unpack("B", self.minfile[pos+3:startpos])[0] 
    157                         elif length == 2 :     
     157                        elif length == 2 : 
    158158                            startpos = pos + 5 
    159159                            size = unpack(self.unpackShort, self.minfile[pos+3:startpos])[0] 
    160                         elif length == 4 :     
     160                        elif length == 4 : 
    161161                            startpos = pos + 7 
    162162                            size = unpack(self.unpackLong, self.minfile[pos+3:startpos])[0] 
    163                         else :     
     163                        else : 
    164164                            raise pdlparser.PDLParserError, "Error on size at %s : %s" % (pos+2, length) 
    165165                        break 
    166166                mediatypelabel = minfile[startpos:startpos+size] 
    167167                # self.logdebug("Media type : %s" % mediatypelabel) 
    168             elif val == 0x34 :     
     168            elif val == 0x34 : 
    169169                duplexmode = "Simplex" 
    170170                pos -= 2 
    171             elif val in (0x35, 0x36) :     
     171            elif val in (0x35, 0x36) : 
    172172                duplexmode = "Duplex" 
    173173                pos -= 2 
    174             # else : TODO : CUSTOM MEDIA SIZE AND UNIT !  
    175             else :     
     174            # else : TODO : CUSTOM MEDIA SIZE AND UNIT ! 
     175            else : 
    176176                pos -= 1  # ignored 
    177         self.pages[self.pagecount] = { "copies" : 1,  
    178                                        "orientation" : orientationlabel,  
    179                                        "mediatype" : mediatypelabel,  
     177        self.pages[self.pagecount] = { "copies" : 1, 
     178                                       "orientation" : orientationlabel, 
     179                                       "mediatype" : mediatypelabel, 
    180180                                       "mediasize" : mediasizelabel, 
    181181                                       "mediasource" : mediasourcelabel, 
    182182                                       "duplex" : duplexmode, 
    183                                      }  
     183                                     } 
    184184        return 0 
    185          
    186     def endPage(self, nextpos) :     
     185 
     186    def endPage(self, nextpos) : 
    187187        """Indicates the end of a page.""" 
    188188        # self.logdebug("EndPage at %x" % nextpos) 
     
    198198                # self.logdebug("Number of copies : %i" % nbcopies) 
    199199                self.pages[self.pagecount]["copies"] = nbcopies 
    200             except KeyError :     
     200            except KeyError : 
    201201                self.logdebug("It looks like this PCLXL file is corrupted.") 
    202202        return 0 
    203          
    204     def setColorSpace(self, nextpos) :     
     203 
     204    def setColorSpace(self, nextpos) : 
    205205        """Changes the color space.""" 
    206206        if self.minfile[nextpos-4:nextpos-1] == self.RGBColorSpace : # TODO : doesn't seem to handle all cases ! 
    207207            self.iscolor = True 
    208208        return 0 
    209              
     209 
    210210    def array_Generic(self, nextpos, size) : 
    211211        """Handles all arrays.""" 
     
    220220        except KeyError : 
    221221            raise pdlparser.PDLParserError, "Error on array size at %x" % nextpos 
    222              
    223     def array_8(self, nextpos) :     
     222 
     223    def array_8(self, nextpos) : 
    224224        """Handles byte arrays.""" 
    225225        return self.array_Generic(nextpos, 1) 
    226          
     226 
    227227    def array_16(self, nextpos) : 
    228228        """Handles 16 bits arrays.""" 
    229229        return self.array_Generic(nextpos, 2) 
    230          
     230 
    231231    def array_32(self, nextpos) : 
    232232        """Handles 32 bits arrays and Canon ImageRunner tags.""" 
     
    243243                toskip += length 
    244244            # self.logdebug("Canon ImageRunner skip until %x" % (nextpos+toskip)) 
    245             return toskip     
     245            return toskip 
    246246        else : 
    247247            # This is a normal PCLXL array 
    248248            return self.array_Generic(nextpos, 4) 
    249          
     249 
    250250    def embeddedDataSmall(self, nextpos) : 
    251251        """Handle small amounts of data.""" 
    252252        return 1 + ord(self.minfile[nextpos]) 
    253          
     253 
    254254    def embeddedData(self, nextpos) : 
    255255        """Handle normal amounts of data.""" 
    256256        return 4 + unpack(self.unpackLong, self.minfile[nextpos:nextpos+4])[0] 
    257          
    258     def skipHPPCLXL(self, nextpos) :     
     257 
     258    def skipHPPCLXL(self, nextpos) : 
    259259        """Skip the 'HP-PCL XL' statement if needed.""" 
    260260        minfile = self.minfile 
     
    265265            while minfile[pos] != '\n' : 
    266266                pos += 1 
    267             length = (pos - nextpos + 1)     
    268             # self.logdebug("Skip HP PCLXL statement until %x" % (nextpos + length))   
     267            length = (pos - nextpos + 1) 
     268            # self.logdebug("Skip HP PCLXL statement until %x" % (nextpos + length)) 
    269269            return length 
    270         else :     
     270        else : 
    271271            return 0 
    272          
     272 
    273273    def littleEndian(self, nextpos) : 
    274274        """Toggles to little endianness.""" 
     
    278278        # self.logdebug("LittleEndian at %x" % (nextpos - 1)) 
    279279        return self.skipHPPCLXL(nextpos) 
    280          
     280 
    281281    def bigEndian(self, nextpos) : 
    282282        """Toggles to big endianness.""" 
     
    286286        # self.logdebug("BigEndian at %x" % (nextpos - 1)) 
    287287        return self.skipHPPCLXL(nextpos) 
    288      
     288 
    289289    def reservedForFutureUse(self, nextpos) : 
    290290        """Outputs something when a reserved byte is encountered.""" 
    291291        self.logdebug("Byte at %x is out of the PCLXL Protocol Class 2.0 Specification" % nextpos) 
    292         return 0     
    293          
     292        return 0 
     293 
    294294    def x46_class3(self, nextpos) : 
    295295        """Undocumented tag 0x46 in class 3.0 streams.""" 
     
    301301            try : 
    302302                offset = self.x46_functions[funcid] 
    303             except KeyError :     
     303            except KeyError : 
    304304                self.logdebug("Unexpected subfunction 0x%02x for undocumented tag 0x46 at %x" % (funcid, nextpos)) 
    305305                break 
    306             else :     
     306            else : 
    307307                pos -= offset 
    308308                length = self.tags[ord(self.minfile[pos])] 
     
    315315                        raise pdlparser.PDLParserError, "Error on size '%s' at %x" % (length, pos+1) 
    316316            val = ord(minfile[pos]) 
    317         return 0     
    318          
    319     def escape(self, nextpos) :     
     317        return 0 
     318 
     319    def escape(self, nextpos) : 
    320320        """Handles the ESC code.""" 
    321321        pos = endpos = nextpos 
     
    331331                    quotes += 1 
    332332                endpos += 1 
    333                  
    334             # Store this in a per page mapping.     
     333 
     334            # Store this in a per page mapping. 
    335335            # NB : First time will be at page 0 (i.e. **before** page 1) ! 
    336336            stuff = self.escapedStuff.setdefault(self.pagecount, []) 
     
    338338            self.logdebug("Escaped datas : [%s]" % repr(minfile[pos : endpos])) 
    339339        return endpos - pos 
    340          
     340 
    341341    def skipKyoceraPrescribe(self, nextpos) : 
    342342        """Skips Kyocera Prescribe commands.""" 
     
    351351                    self.logdebug("Prescribe commands : [%s]" % repr(minfile[nextpos-1:pos])) 
    352352                    break 
    353                 pos += 1     
     353                pos += 1 
    354354            return (pos - nextpos) 
    355355        else : 
    356356            return 0 
    357              
     357 
    358358    def getJobSize(self) : 
    359359        """Counts pages in a PCLXL (PCL6) document. 
    360          
     360 
    361361           Algorithm by Jerome Alet. 
    362             
     362 
    363363           The documentation used for this was : 
    364           
     364 
    365365           HP PCL XL Feature Reference 
    366366           Protocol Class 2.0 
    367            http://www.hpdevelopersolutions.com/downloads/64/358/xl_ref20r22.pdf  
    368             
     367           http://www.hpdevelopersolutions.com/downloads/64/358/xl_ref20r22.pdf 
     368 
    369369           Protocol Class 2.1 Supplement 
    370370           xl_ref21.pdf 
    371             
     371 
    372372           Protocol Class 3.0 Supplement 
    373373           xl_refsup30r089.pdf 
    374374        """ 
    375          
     375 
    376376        infileno = self.infile.fileno() 
    377377        self.minfile = minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) 
    378          
     378 
    379379        self.iscolor = False 
    380          
     380 
    381381        found = False 
    382382        while not found : 
     
    392392                if endian == 0x29 : 
    393393                    self.littleEndian(0) 
    394                 elif endian == 0x28 :     
     394                elif endian == 0x28 : 
    395395                    self.bigEndian(0) 
    396396                # elif endian == 0x27 : # TODO : This is the ASCII binding code : what does it do exactly ? 
    397                 #  
    398                 else :     
     397                # 
     398                else : 
    399399                    raise pdlparser.PDLParserError, "Unknown endianness marker 0x%02x at start !" % endian 
    400400        if not found : 
    401401            raise pdlparser.PDLParserError, "This file doesn't seem to be PCLXL (aka PCL6)" 
    402              
     402 
    403403        # Initialize Media Sources 
    404404        for i in range(8, 256) : 
    405405            self.mediasources[i] = "ExternalTray%03i" % (i - 7) 
    406              
     406 
    407407        # Initialize table of tags 
    408         self.tags = [ 0 ] * 256     
    409          
     408        self.tags = [ 0 ] * 256 
     409 
    410410        self.tags[0x1b] = self.escape # The escape code 
    411          
     411 
    412412        self.tags[0x21] = self.skipKyoceraPrescribe # 0x21 is not normally used 
    413          
     413 
    414414        # GhostScript's sources tell us that HP printers 
    415415        # only accept little endianness, but we can handle both. 
    416416        self.tags[0x28] = self.bigEndian    # BigEndian 
    417417        self.tags[0x29] = self.littleEndian # LittleEndian 
    418          
     418 
    419419        self.tags[0x43] = self.beginPage    # BeginPage 
    420420        self.tags[0x44] = self.endPage      # EndPage 
    421421        self.tags[0x45] = self.reservedForFutureUse # reserved 
    422          
    423         self.tags[0x46] = self.x46_class3  
    424          
     422 
     423        self.tags[0x46] = self.x46_class3 
     424 
    425425        self.tags[0x4a] = self.reservedForFutureUse # reserved 
    426426        self.tags[0x4b] = self.reservedForFutureUse # reserved 
     
    428428        self.tags[0x4d] = self.reservedForFutureUse # reserved 
    429429        self.tags[0x4e] = self.reservedForFutureUse # reserved 
    430          
     430 
    431431        self.tags[0x56] = self.reservedForFutureUse # TODO : documentation not clear about reserved status 
    432          
     432 
    433433        self.tags[0x57] = self.reservedForFutureUse # reserved 
    434          
     434 
    435435        self.tags[0x59] = self.reservedForFutureUse # reserved 
    436436        self.tags[0x5a] = self.reservedForFutureUse # reserved 
    437          
     437 
    438438        self.tags[0x6a] = self.setColorSpace    # to detect color/b&w mode 
    439          
     439 
    440440        self.tags[0x87] = self.reservedForFutureUse # reserved 
    441441        self.tags[0x88] = self.reservedForFutureUse # reserved 
    442442        self.tags[0x89] = self.reservedForFutureUse # reserved 
    443443        self.tags[0x8a] = self.reservedForFutureUse # reserved 
    444          
     444 
    445445        self.tags[0x8b] = self.reservedForFutureUse # reserved 
    446          
     446 
    447447        self.tags[0x8c] = self.reservedForFutureUse # reserved 
    448448        self.tags[0x8d] = self.reservedForFutureUse # reserved 
     
    450450        self.tags[0x8f] = self.reservedForFutureUse # reserved 
    451451        self.tags[0x90] = self.reservedForFutureUse # reserved 
    452          
     452 
    453453        self.tags[0x9a] = self.reservedForFutureUse # reserved 
    454454        self.tags[0x9c] = self.reservedForFutureUse # reserved 
    455          
     455 
    456456        self.tags[0xa4] = self.reservedForFutureUse # reserved 
    457457        self.tags[0xa5] = self.reservedForFutureUse # reserved 
    458458        self.tags[0xa6] = self.reservedForFutureUse # reserved 
    459459        self.tags[0xa7] = self.reservedForFutureUse # reserved 
    460          
     460 
    461461        self.tags[0xaa] = self.reservedForFutureUse # reserved 
    462462        self.tags[0xab] = self.reservedForFutureUse # reserved 
     
    465465        self.tags[0xae] = self.reservedForFutureUse # reserved 
    466466        self.tags[0xaf] = self.reservedForFutureUse # reserved 
    467          
     467 
    468468        self.tags[0xb7] = self.reservedForFutureUse # reserved 
    469          
     469 
    470470        self.tags[0xba] = self.reservedForFutureUse # reserved 
    471471        self.tags[0xbb] = self.reservedForFutureUse # reserved 
     
    473473        self.tags[0xbd] = self.reservedForFutureUse # reserved 
    474474        self.tags[0xbe] = self.reservedForFutureUse # reserved 
    475          
     475 
    476476        # self.tags[0xbf] = self.passThrough # PassThrough mode should already be taken care of automatically 
    477          
     477 
    478478        self.tags[0xc0] = 1 # ubyte 
    479479        self.tags[0xc1] = 2 # uint16 
     
    482482        self.tags[0xc4] = 4 # sint32 
    483483        self.tags[0xc5] = 4 # real32 
    484          
     484 
    485485        self.tags[0xc6] = self.reservedForFutureUse # reserved 
    486486        self.tags[0xc7] = self.reservedForFutureUse # reserved 
    487          
     487 
    488488        self.tags[0xc8] = self.array_8  # ubyte_array 
    489489        self.tags[0xc9] = self.array_16 # uint16_array 
     
    492492        self.tags[0xcc] = self.array_32 # sint32_array 
    493493        self.tags[0xcd] = self.array_32 # real32_array and unfortunately Canon ImageRunner 
    494          
     494 
    495495        self.tags[0xce] = self.reservedForFutureUse # reserved 
    496496        self.tags[0xcf] = self.reservedForFutureUse # reserved 
    497          
     497 
    498498        self.tags[0xd0] = 2 # ubyte_xy 
    499499        self.tags[0xd1] = 4 # uint16_xy 
     
    512512        self.tags[0xde] = self.reservedForFutureUse # reserved 
    513513        self.tags[0xdf] = self.reservedForFutureUse # reserved 
    514          
     514 
    515515        self.tags[0xe0] = 4  # ubyte_box 
    516516        self.tags[0xe1] = 8  # uint16_box 
     
    529529        self.tags[0xee] = self.reservedForFutureUse # reserved 
    530530        self.tags[0xef] = self.reservedForFutureUse # reserved 
    531          
     531 
    532532        self.tags[0xf0] = self.reservedForFutureUse # reserved 
    533533        self.tags[0xf1] = self.reservedForFutureUse # reserved 
     
    538538        self.tags[0xf6] = self.reservedForFutureUse # reserved 
    539539        self.tags[0xf7] = self.reservedForFutureUse # reserved 
    540          
     540 
    541541        self.tags[0xf8] = 1 # attr_ubyte 
    542542        self.tags[0xf9] = 2 # attr_uint16 
    543          
     543 
    544544        self.tags[0xfa] = self.embeddedData      # dataLength 
    545545        self.tags[0xfb] = self.embeddedDataSmall # dataLengthByte 
    546          
     546 
    547547        self.tags[0xfc] = self.reservedForFutureUse # reserved 
    548548        self.tags[0xfd] = self.reservedForFutureUse # reserved 
    549549        self.tags[0xfe] = self.reservedForFutureUse # reserved 
    550550        self.tags[0xff] = self.reservedForFutureUse # reserved 
    551              
    552         # color spaces     
     551 
     552        # color spaces 
    553553        self.BWColorSpace = "".join([chr(0x00), chr(0xf8), chr(0x03)]) 
    554554        self.GrayColorSpace = "".join([chr(0x01), chr(0xf8), chr(0x03)]) 
    555555        self.RGBColorSpace = "".join([chr(0x02), chr(0xf8), chr(0x03)]) 
    556          
     556 
    557557        # set number of copies 
    558         self.setNumberOfCopies = "".join([chr(0xf8), chr(0x31)])  
    559          
     558        self.setNumberOfCopies = "".join([chr(0xf8), chr(0x31)]) 
     559 
    560560        # subcodes for undocumented tag 0x46 and the negative 
    561561        # offset to grab the value from. 
     
    569569                               0x98 : 2, 
    570570                             } 
    571                               
     571 
    572572        # Markers for Canon ImageRunner printers 
    573573        self.imagerunnermarker1 = chr(0xcd) + chr(0xca) + chr(0x10) + chr(0x00) 
    574574        self.imagerunnermarker2 = chr(0xcd) + chr(0xca) + chr(0x10) + chr(0x02) 
    575                               
    576         self.pages = { 0 : { "copies" : 1,  
    577                              "orientation" : "Default",  
    578                              "mediatype" : "Plain",  
    579                              "mediasize" : "Default",  
    580                              "mediasource" : "Default",  
     575 
     576        self.pages = { 0 : { "copies" : 1, 
     577                             "orientation" : "Default", 
     578                             "mediatype" : "Plain", 
     579                             "mediasize" : "Default", 
     580                             "mediasource" : "Default", 
    581581                             "duplex" : None, 
    582                            }  
    583                      }       
     582                           } 
     583                     } 
    584584        tags = self.tags 
    585585        self.pagecount = 0 
     
    592592                    try : 
    593593                        tag = ord(minfile[pos]) 
    594                     except OverflowError :     
     594                    except OverflowError : 
    595595                        pos = oldpos + 1 
    596596                    pos += 1 
    597597                    length = tags[tag] 
    598598                    if length : 
    599                         if callable(length) :     
     599                        if callable(length) : 
    600600                            length = length(pos) 
    601                         oldpos = pos     
    602                         pos += length     
    603             except IndexError : # EOF ?             
     601                        oldpos = pos 
     602                        pos += length 
     603            except IndexError : # EOF ? 
    604604                pass 
    605605        finally : 
    606606            self.minfile.close() 
    607              
     607 
    608608        # now handle number of copies for each page (may differ). 
    609609        if self.iscolor : 
    610610            colormode = "Color" 
    611         else :     
     611        else : 
    612612            colormode = "BW" 
    613              
     613 
    614614        defaultduplexmode = "Simplex" 
    615615        defaultpapersize = "" 
    616         defaultpjlcopies = 1     
     616        defaultpjlcopies = 1 
    617617        oldpjlcopies = -1 
    618618        oldduplexmode = "" 
     
    622622            # in PCLXL documentation. 
    623623            # NB : is number of copies is 0, the page won't be output 
    624             # but the formula below is still correct : we want  
     624            # but the formula below is still correct : we want 
    625625            # to decrease the total number of pages in this case. 
    626626            page = self.pages.get(pnum, self.pages.get(1, { "copies" : 1, "mediasize" : "Default", "duplex" : None })) 
     
    641641                    pjlcopies = nbqty 
    642642                else : 
    643                     if oldpjlcopies == -1 :     
     643                    if oldpjlcopies == -1 : 
    644644                        pjlcopies = defaultpjlcopies 
    645                     else :     
    646                         pjlcopies = oldpjlcopies     
    647                 if page["duplex"] :         
     645                    else : 
     646                        pjlcopies = oldpjlcopies 
     647                if page["duplex"] : 
    648648                    duplexmode = page["duplex"] 
    649                 else :     
     649                else : 
    650650                    defaultdm = pjlparser.default_variables.get("DUPLEX", "") 
    651651                    if defaultdm : 
    652652                        if defaultdm.upper() == "ON" : 
    653653                            defaultduplexmode = "Duplex" 
    654                         else :     
     654                        else : 
    655655                            defaultduplexmode = "Simplex" 
    656656                    envdm = pjlparser.environment_variables.get("DUPLEX", "") 
     
    658658                        if envdm.upper() == "ON" : 
    659659                            duplexmode = "Duplex" 
    660                         else :     
     660                        else : 
    661661                            duplexmode = "Simplex" 
    662                     else :         
     662                    else : 
    663663                        if not oldduplexmode : 
    664664                            duplexmode = defaultduplexmode 
    665                         else :     
     665                        else : 
    666666                            duplexmode = oldduplexmode 
    667667                defaultps = pjlparser.default_variables.get("PAPER", "") 
     
    671671                if envps : 
    672672                    papersize = envps 
    673                 else :     
     673                else : 
    674674                    if not oldpapersize : 
    675675                        papersize = defaultpapersize 
    676                     else :     
     676                    else : 
    677677                        papersize = oldpapersize 
    678             else :         
     678            else : 
    679679                if oldpjlcopies == -1 : 
    680680                    pjlcopies = defaultpjlcopies 
    681                 else :     
     681                else : 
    682682                    pjlcopies = oldpjlcopies 
    683683                if not oldduplexmode : 
    684684                    duplexmode = defaultduplexmode 
    685                 else :     
     685                else : 
    686686                    duplexmode = oldduplexmode 
    687                 if not oldpapersize :     
     687                if not oldpapersize : 
    688688                    papersize = defaultpapersize 
    689                 else :     
     689                else : 
    690690                    papersize = oldpapersize 
    691691                duplexmode = oldduplexmode 
     
    693693            if page["mediasize"] != "Default" : 
    694694                papersize = page["mediasize"] 
    695             if not duplexmode :     
     695            if not duplexmode : 
    696696                duplexmode = oldduplexmode or defaultduplexmode 
    697             oldpjlcopies = pjlcopies     
     697            oldpjlcopies = pjlcopies 
    698698            oldduplexmode = duplexmode 
    699699            oldpapersize = papersize 
    700700            copies = max(pjlcopies, page["copies"]) # Was : pjlcopies * page["copies"] 
    701701            self.pagecount += (copies - 1) 
    702             self.logdebug("%s*%s*%s*%s*%s*%s*%s" % (copies,  
    703                                                  page["mediatype"],  
    704                                                  papersize,  
    705                                                  page["orientation"],  
    706                                                  page["mediasource"],  
    707                                                  duplexmode,  
     702            self.logdebug("%s*%s*%s*%s*%s*%s*%s" % (copies, 
     703                                                 page["mediatype"], 
     704                                                 papersize, 
     705                                                 page["orientation"], 
     706                                                 page["mediasource"], 
     707                                                 duplexmode, 
    708708                                                 colormode)) 
    709709        return self.pagecount 
  • pkpgcounter/trunk/pkpgpdls/pdf.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3737PDFDELIMITERS = r"()<>[]{}/%" 
    3838PDFMEDIASIZE = "/MediaBox [xmin ymin xmax ymax]" # an example. MUST be present in Page objects 
    39          
     39 
    4040class Parser(pdlparser.PDLParser) : 
    4141    """A parser for PDF documents.""" 
     
    4444    openmode = "rU" 
    4545    format = "PDF" 
    46     def isValid(self) :     
     46    def isValid(self) : 
    4747        """Returns True if data is PDF, else False.""" 
    4848        if self.firstblock.startswith("%PDF-") or \ 
     
    5151           (self.firstblock.find("%PDF-") != -1) : 
    5252            return True 
    53         else :     
     53        else : 
    5454            return False 
    55          
    56     def veryFastAndNotAlwaysCorrectgetJobSize(self) :     
     55 
     56    def veryFastAndNotAlwaysCorrectgetJobSize(self) : 
    5757        """Counts pages in a PDF document. 
    58          
     58 
    5959           This method works great in the general case, 
    6060           and is around 30 times faster than the active 
     
    7070    def getJobSize(self) : 
    7171        """Counts pages in a PDF document. 
    72          
     72 
    7373           A faster way seems to be possible by extracting the 
    7474           "/Type/Pages/Count xxxx" value where there's no /Parent 
    7575           (i.e. the root of the page tree) 
    7676           Unfortunately I can't make a regexp work for this currently. 
    77             
     77 
    7878           At least the actual method below is accurate, even if 25% 
    7979           slower than the old one. But we will be able to extract 
     
    8484        oregexp = re.compile(r"\s+(\d+)\s+(\d+)\s+(obj\s*.+?\s*?endobj)", \ 
    8585                             re.DOTALL) 
    86                               
     86 
    8787        # Regular expression indicating a new page 
    8888        npregexp = re.compile(r"/Type\s*/Page[/>\s]") 
    89          
    90         # Regular expression indicating an empty page  
     89 
     90        # Regular expression indicating an empty page 
    9191        # (usually to delete an existing one with a lower minor number) 
    92         epregexp = re.compile(r"obj\s*<<\s*/Type\s*/Page\s*>>\s*endobj")  
    93          
     92        epregexp = re.compile(r"obj\s*<<\s*/Type\s*/Page\s*>>\s*endobj") 
     93 
    9494        # First we build a mapping of objects to keep because 
    9595        # if two objects with the same major number are found, 
     
    109109                #else : 
    110110                #    self.logdebug("Object %i.%i OK" % (major, minor)) 
    111                  
    112         # Now that we have deleted all unneeded objects, we         
     111 
     112        # Now that we have deleted all unneeded objects, we 
    113113        # can count the ones which are new pages, minus the ones 
    114114        # which are empty and not displayed pages (in fact pages 
  • pkpgcounter/trunk/pkpgpdls/pdlparser.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    2525import os 
    2626 
    27 KILOBYTE = 1024     
    28 MEGABYTE = 1024 * KILOBYTE     
     27KILOBYTE = 1024 
     28MEGABYTE = 1024 * KILOBYTE 
    2929FIRSTBLOCKSIZE = 16 * KILOBYTE 
    3030LASTBLOCKSIZE = int(KILOBYTE / 4) 
     
    3838        return self.message 
    3939    __str__ = __repr__ 
    40          
     40 
    4141class PDLParser : 
    4242    """Generic PDL parser.""" 
     
    5656        if not self.isValid() : 
    5757            raise PDLParserError, "Invalid file format !" 
    58         else :     
     58        else : 
    5959            self.logdebug("Input file is in the '%s' file format." % self.format) 
    6060        try : 
    61             import psyco  
    62         except ImportError :     
     61            import psyco 
     62        except ImportError : 
    6363            pass # Psyco is not installed 
    64         else :     
     64        else : 
    6565            # Psyco is installed, tell it to compile 
    6666            # the CPU intensive methods : PCL and PCLXL 
     
    6969        self.infile = open(self.filename, self.openmode) 
    7070        # self.logdebug("Opened %s in '%s' mode." % (self.filename, self.openmode)) 
    71              
     71 
    7272    def __del__(self) : 
    7373        """Ensures the input file gets closed.""" 
    7474        if self.infile : 
    7575            self.infile.close() 
    76              
     76 
    7777    def findExecutable(self, command) : 
    7878        """Finds an executable in the PATH and returns True if found else False.""" 
     
    8383                    return True 
    8484        return False 
    85          
    86     def isMissing(self, commands) :     
    87         """Returns True if some required commands are missing, else False."""  
     85 
     86    def isMissing(self, commands) : 
     87        """Returns True if some required commands are missing, else False.""" 
    8888        howmanythere = 0 
    8989        for command in commands : 
     
    9191                sys.stderr.write("ERROR: %(command)s is missing or not executable. You MUST install it for pkpgcounter to be able to do what you want.\n" % locals()) 
    9292                sys.stderr.flush() 
    93             else :     
     93            else : 
    9494                howmanythere += 1 
    9595        if howmanythere == len(commands) : 
    9696            return False 
    97         else :    
     97        else : 
    9898            return True 
    99          
    100     def logdebug(self, message) :        
     99 
     100    def logdebug(self, message) : 
    101101        """Logs a debug message if needed.""" 
    102102        if self.parent.options.debug : 
    103103            sys.stderr.write("%s\n" % message) 
    104              
    105     def isValid(self) :     
     104 
     105    def isValid(self) : 
    106106        """Returns True if data is in the expected format, else False.""" 
    107107        raise RuntimeError, "Not implemented !" 
    108          
    109     def getJobSize(self) :     
     108 
     109    def getJobSize(self) : 
    110110        """Counts pages in a document.""" 
    111111        raise RuntimeError, "Not implemented !" 
    112          
     112 
    113113    def convertToTiffMultiPage24NC(self, outfname, dpi) : 
    114114        """Converts the input file to TIFF format, X dpi, 24 bits per pixel, uncompressed. 
    115115           Writes TIFF datas to the file named by outfname. 
    116         """    
     116        """ 
    117117        if self.totiffcommands : 
    118118            if self.isMissing(self.required) : 
     
    127127                    if os.WEXITSTATUS(status) : 
    128128                        error = True 
    129                 else :         
     129                else : 
    130130                    error = True 
    131131                if not os.path.exists(outfname) : 
     
    133133                elif not os.stat(outfname).st_size : 
    134134                    error = True 
    135                 else :         
     135                else : 
    136136                    break       # Conversion worked fine it seems. 
    137137                sys.stderr.write("Command failed : %s\n" % repr(commandline)) 
    138138            if error : 
    139139                raise PDLParserError, "Problem during conversion to TIFF." 
    140         else :         
     140        else : 
    141141            raise PDLParserError, "Impossible to compute ink coverage for this file format." 
  • pkpgcounter/trunk/pkpgpdls/pil.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    2626try : 
    2727    from PIL import Image 
    28 except ImportError :     
     28except ImportError : 
    2929    sys.stderr.write("ERROR: You MUST install the Python Imaging Library (python-imaging) for pkpgcounter to work.\n") 
    3030    raise pdlparser.PDLParserError, "The Python Imaging Library is missing." 
     
    3434class Parser(pdlparser.PDLParser) : 
    3535    """A parser for plain text documents.""" 
    36     totiffcommands = [ 'convert "%(infname)s" "%(outfname)s"' ]   
     36    totiffcommands = [ 'convert "%(infname)s" "%(outfname)s"' ] 
    3737    required = [ "convert" ] 
    38     def isValid(self) :     
    39         """Returns True if data is an image format supported by PIL, else False."""    
     38    def isValid(self) : 
     39        """Returns True if data is an image format supported by PIL, else False.""" 
    4040        try : 
    4141            image = Image.open(self.filename) 
    42         except (IOError, OverflowError) :     
     42        except (IOError, OverflowError) : 
    4343            return False 
    44         else :     
     44        else : 
    4545            self.format = "%s (%s)" % (image.format, image.format_description) 
    4646            return True 
    47              
     47 
    4848    def getJobSize(self) : 
    4949        """Counts pages in an image file.""" 
     
    5252        try : 
    5353            while True : 
    54                 index += 1               
     54                index += 1 
    5555                image.seek(index) 
    56         except EOFError :         
     56        except EOFError : 
    5757            pass 
    58         return index     
     58        return index 
  • pkpgcounter/trunk/pkpgpdls/pjl.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3535        return self.message 
    3636    __str__ = __repr__ 
    37          
     37 
    3838class PJLParser : 
    3939    """A parser for PJL documents. 
    40      
     40 
    4141       Information extracted for bpl11897.pdf which was 
    4242       downloaded from Hewlett-Packard's website. 
     
    5252        self.parsed = 0 
    5353        self.parse() 
    54          
    55     def __str__(self) :     
     54 
     55    def __str__(self) : 
    5656        """Outputs our variables as a string of text.""" 
    5757        if not self.parsed : 
     
    6262            for (k, v) in self.default_variables.items() : 
    6363                mybuffer.append("  %s : %s" % (k, v)) 
    64         if self.environment_variables :         
     64        if self.environment_variables : 
    6565            mybuffer.append("Environment variables :") 
    6666            for (k, v) in self.environment_variables.items() : 
    6767                mybuffer.append("  %s : %s" % (k, v)) 
    68         return "\n".join(mybuffer)         
    69              
    70     def logdebug(self, message) :     
     68        return "\n".join(mybuffer) 
     69 
     70    def logdebug(self, message) : 
    7171        """Logs a debug message if needed.""" 
    7272        if self.debug : 
    7373            sys.stderr.write("%s\n" % message) 
    74              
    75     def cleanvars(self) :         
     74 
     75    def cleanvars(self) : 
    7676        """Cleans the variables dictionnaries.""" 
    7777        for dicname in ("default", "environment") : 
     
    8080                if len(v) == 1 : 
    8181                    varsdic[k] = v[0] 
    82          
     82 
    8383    def parse(self) : 
    8484        """Parses a JL job.""" 
     
    9595                                  or ((self.jlmarker == "@EJL") and (parts[1].upper() == "JI"))) : 
    9696                        # this is what we are interested in ! 
    97                         try :     
     97                        try : 
    9898                            (varname, value) = "".join(parts[2:]).split("=", 1) # TODO : parse multiple assignments on the same SET/JI statement 
    99                         except :     
     99                        except : 
    100100                            self.logdebug("Invalid JL SET statement [%s]" % repr(statement)) 
    101                         else :     
     101                        else : 
    102102                            # all still looks fine... 
    103103                            if parts[1].upper() == "DEFAULT" : 
    104104                                varsdic = self.default_variables 
    105                             else :     
    106                                 varsdic = self.environment_variables  
     105                            else : 
     106                                varsdic = self.environment_variables 
    107107                            variable = varsdic.setdefault(varname.upper(), []) 
    108108                            variable.append(value) 
     
    121121        self.parsed = 1 
    122122        # self.logdebug("%s\n" % str(self)) 
    123          
     123 
    124124class EJLParser(PJLParser) : 
    125125    """A parser for EJL (Epson Job Language) documents.""" 
    126126    JL = "EJL" 
    127          
    128 def test() :         
     127 
     128def test() : 
    129129    """Test function.""" 
    130130    if (len(sys.argv) < 2) or ((not sys.stdin.isatty()) and ("-" not in sys.argv[1:])) : 
     
    135135            infile = sys.stdin 
    136136            mustclose = 0 
    137         else :     
     137        else : 
    138138            if arg.endswith(".ejl") : 
    139139                klass = EJLParser 
     
    142142        try : 
    143143            parser = klass(infile.read(), debug=1) 
    144         except PJLParserError, msg :     
     144        except PJLParserError, msg : 
    145145            sys.stderr.write("ERROR: %s\n" % msg) 
    146146            sys.stderr.flush() 
    147         if mustclose :     
     147        if mustclose : 
    148148            infile.close() 
    149         print str(parser)             
    150      
    151 if __name__ == "__main__" :     
     149        print str(parser) 
     150 
     151if __name__ == "__main__" : 
    152152    test() 
  • pkpgcounter/trunk/pkpgpdls/plain.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    2929    totiffcommands = [ 'enscript --quiet --portrait --no-header --columns 1 --output - "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -', 
    3030                       'a2ps --borders 0 --quiet --portrait --no-header --columns 1 --output - "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -', 
    31                      ]   
     31                     ] 
    3232    required = [ "a2ps | enscript", "gs" ] 
    33     openmode = "rU"                  
     33    openmode = "rU" 
    3434    format = "plain text" 
    35     def isValid(self) :     
     35    def isValid(self) : 
    3636        """Returns True if data is plain text, else False. 
    37          
     37 
    3838           It's hard to detect a plain text file, so we just try to 
    3939           extract lines from the first block (sufficiently large). 
    4040           If it's impossible to find one we consider it's not plain text. 
    41         """    
     41        """ 
    4242        lines = self.firstblock.split("\r\n") 
    4343        if len(lines) == 1 : 
     
    4747        if len(lines) > 1 : 
    4848            return True 
    49         else :     
     49        else : 
    5050            return False 
    51              
     51 
    5252    def getJobSize(self) : 
    5353        """Counts pages in a plain text document.""" 
     
    5858        for line in self.infile : 
    5959            if line.endswith("\n") : 
    60                 linecount += 1     
     60                linecount += 1 
    6161                if (linecount > pagesize) : 
    6262                    pagecount += 1 
    6363                    linecount = 0 
    64                 else :     
     64                else : 
    6565                    cnt = line.count("\f") 
    6666                    if cnt : 
    6767                        pagecount += cnt 
    6868                        linecount = 0 
    69             else :         
     69            else : 
    7070                raise pdlparser.PDLParserError, "Unsupported file format. Please send the file to %s" % version.__authoremail__ 
    7171        return pagecount + 1    # NB : empty files are catched in isValid() 
  • pkpgcounter/trunk/pkpgpdls/pnmascii.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    2626class Parser(pdlparser.PDLParser) : 
    2727    """A parser for PNM (ascii) documents.""" 
    28     openmode = "rU"                  
     28    openmode = "rU" 
    2929    format = "PNM (ascii)" 
    30     def isValid(self) :     
     30    def isValid(self) : 
    3131        """Returns True if data is ASCII PNM, else False.""" 
    3232        if self.firstblock.split()[0] in ("P1", "P2", "P3") : 
    3333            self.marker = self.firstblock[:2] 
    3434            return True 
    35         else :     
     35        else : 
    3636            return False 
    37              
     37 
    3838    def getJobSize(self) : 
    3939        """Counts pages in a PNM (ascii) document.""" 
     
    4747                # Special case of cmyk map 
    4848                divby = 4 
    49             # Unfortunately any whitespace is valid,  
     49            # Unfortunately any whitespace is valid, 
    5050            # so we do it the slow way... 
    5151            pagecount += line.split().count(marker) 
    52              
    53         if not (pagecount % divby) :     
     52 
     53        if not (pagecount % divby) : 
    5454            return pagecount // divby 
    55         else :     
     55        else : 
    5656            return pagecount 
  • pkpgcounter/trunk/pkpgpdls/postscript.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3434    openmode = "rU" 
    3535    format = "PostScript" 
    36     def isValid(self) :     
     36    def isValid(self) : 
    3737        """Returns True if data is PostScript, else False.""" 
    3838        if self.firstblock.startswith("%!") or \ 
     
    4545              (self.firstblock.find("%!PS-Adobe") != -1) : 
    4646            return True 
    47         else :     
     47        else : 
    4848            return False 
    49          
     49 
    5050    def throughGhostScript(self) : 
    5151        """Get the count through GhostScript, useful for non-DSC compliant PS files.""" 
     
    6262            except (IOError, OSError, AttributeError, ValueError), msg : 
    6363                raise pdlparser.PDLParserError, "Problem during analysis of Binary PostScript document : %s" % msg 
    64         finally :         
     64        finally : 
    6565            if fromchild.close() is not None : 
    6666                raise pdlparser.PDLParserError, "Problem during analysis of Binary PostScript document" 
    67         self.logdebug("GhostScript said : %s pages" % pagecount)     
     67        self.logdebug("GhostScript said : %s pages" % pagecount) 
    6868        return pagecount * self.copies 
    69          
    70     def setcopies(self, pagenum, txtvalue) :     
     69 
     70    def setcopies(self, pagenum, txtvalue) : 
    7171        """Tries to extract a number of copies from a textual value and set the instance attributes accordingly.""" 
    7272        try : 
    7373            number = int(txtvalue) 
    74         except (ValueError, TypeError) :      
     74        except (ValueError, TypeError) : 
    7575            pass 
    76         else :     
     76        else : 
    7777            if number > self.pages[pagenum]["copies"] : 
    7878                self.pages[pagenum]["copies"] = number 
    79                  
     79 
    8080    def natively(self) : 
    8181        """Count pages in a DSC compliant PostScript document.""" 
     
    9494            if nbparts >= 1 : 
    9595                part0 = parts[0] 
    96             else :     
     96            else : 
    9797                part0 = "" 
    9898            if part0 == r"%ADOPrintSettings:" : 
    9999                acrobatmarker = True 
    100             elif part0 == "!R!" :     
     100            elif part0 == "!R!" : 
    101101                prescribe = True 
    102102            elif part0 == r"%%Pages:" : 
     
    119119                if nbparts > 1 : 
    120120                    self.setcopies(pagecount, parts[1]) 
    121             elif part0 == r"%RBINumCopies:" :    
     121            elif part0 == r"%RBINumCopies:" : 
    122122                if nbparts > 1 : 
    123123                    self.setcopies(pagecount, parts[1]) 
     
    135135                    # treats both "%%Page: x x" and "%%Page: (x-y) z" (probably N-up mode) 
    136136                    newpagenum = int(line.split(']')[0].split()[-1]) 
    137                 except :     
     137                except : 
    138138                    notinteger = True # It seems that sometimes it's not an integer but an EPS file name 
    139                 else :     
     139                else : 
    140140                    notinteger = False 
    141141                    if newpagenum == oldpagenum : 
     
    143143                    else : 
    144144                        oldpagenum = newpagenum 
    145                 if proceed and not notinteger :         
     145                if proceed and not notinteger : 
    146146                    pagecount += 1 
    147147                    self.pages[pagecount] = { "copies" : self.pages[pagecount-1]["copies"] } 
     
    155155                self.setcopies(pagecount, part0) 
    156156            previousline = line 
    157              
    158         # extract max number of copies to please the ghostscript parser, just     
     157 
     158        # extract max number of copies to please the ghostscript parser, just 
    159159        # in case we will use it later 
    160160        self.copies = max([ v["copies"] for (k, v) in self.pages.items() ]) 
    161          
     161 
    162162        # now apply the number of copies to each page 
    163         if not pagecount and pagescomment :     
     163        if not pagecount and pagescomment : 
    164164            pagecount = pagescomment 
    165165        for pnum in range(1, pagecount + 1) : 
     
    168168            pagecount += (copies - 1) 
    169169            self.logdebug("%s * page #%s" % (copies, pnum)) 
    170              
     170 
    171171        self.logdebug("Internal parser said : %s pages" % pagecount) 
    172172        return (pagecount, notrust) 
    173          
    174     def getJobSize(self) :     
     173 
     174    def getJobSize(self) : 
    175175        """Count pages in PostScript document.""" 
    176176        self.copies = 1 
     
    182182            except pdlparser.PDLParserError, msg : 
    183183                self.logdebug(msg) 
    184         return max(nbpages, newnbpages)     
     184        return max(nbpages, newnbpages) 
  • pkpgcounter/trunk/pkpgpdls/qpdl.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3333    """A parser for QPDL (aka SPL2) documents.""" 
    3434    format = "QPDL (aka SPL2)" 
    35     mediasizes = {  
     35    mediasizes = { 
    3636                    # The first values are identical to that of PCLXL 
    3737                    0 : "Letter", 
     
    5757                    23 : "C6", 
    5858                    24 : "Folio", 
    59                  }    
    60                   
    61     mediasources = {              
     59                 } 
     60 
     61    mediasources = { 
    6262                     # Again, values are identical to that of PCLXL 
    6363                     0 : "Default", 
     
    7070                     7 : "ThirdCassette", 
    7171                   } 
    72              
    73     def isValid(self) :     
     72 
     73    def isValid(self) : 
    7474        """Returns True if data is QPDL aka SPL2, else False.""" 
    7575        if ((self.firstblock[:128].find("\033%-12345X") != -1) and \ 
     
    7777              (self.firstblock.find("LANGUAGE = QPDL") != -1))) : 
    7878            return True 
    79         else :     
     79        else : 
    8080            return False 
    81              
     81 
    8282    def beginPage(self, nextpos) : 
    8383        """Indicates the beginning of a new page, and extracts media information.""" 
    8484        self.pagecount += 1 
    85          
     85 
    8686        copies = unpack(self.unpackShort, self.minfile[nextpos+1:nextpos+3])[0] 
    8787        mediasize = ord(self.minfile[nextpos+3]) 
    8888        mediasource = ord(self.minfile[nextpos+8]) 
    8989        duplexmode = unpack(self.unpackShort, self.minfile[nextpos+10:nextpos+12])[0] 
    90          
    91         self.pages[self.pagecount] = { "copies" : copies,  
     90 
     91        self.pages[self.pagecount] = { "copies" : copies, 
    9292                                       "mediasize" : self.mediasizes.get(mediasize, str(mediasize)), 
    9393                                       "mediasource" : self.mediasources.get(mediasource, str(mediasource)), 
    9494                                       "duplex" : duplexmode, 
    95                                      }  
     95                                     } 
    9696        return 16       # Length of a page header 
    97          
    98     def endPage(self, nextpos) :     
     97 
     98    def endPage(self, nextpos) : 
    9999        """Indicates the end of a page.""" 
    100100        epcopies = unpack(self.unpackShort, self.minfile[nextpos:nextpos+2])[0] 
     
    103103            self.logdebug("ERROR: discrepancy between beginPage (%i) and endPage (%i) copies" % (bpcopies, epcopies)) 
    104104        return 2        # Length of a page footer 
    105          
     105 
    106106    def beginBand(self, nextpos) : 
    107107        """Indicates the beginning of a new band.""" 
    108108        bandlength = unpack(self.unpackLong, self.minfile[nextpos+6:nextpos+10])[0] 
    109109        return bandlength + 10 # Length of a band header - length of checksum 
    110          
     110 
    111111    def littleEndian(self) : 
    112112        """Toggles to little endianness.""" 
     
    115115        self.unpackLong = self.unpackType[4] 
    116116        return 0 
    117          
     117 
    118118    def bigEndian(self) : 
    119119        """Toggles to big endianness.""" 
     
    122122        self.unpackLong = self.unpackType[4] 
    123123        return 0 
    124      
    125     def escape(self, nextpos) :     
     124 
     125    def escape(self, nextpos) : 
    126126        """Handles the ESC code.""" 
    127127        pos = endpos = nextpos 
     
    137137                    quotes += 1 
    138138                endpos += 1 
    139                  
    140             # Store this in a per page mapping.     
     139 
     140            # Store this in a per page mapping. 
    141141            # NB : First time will be at page 0 (i.e. **before** page 1) ! 
    142142            stuff = self.escapedStuff.setdefault(self.pagecount, []) 
     
    144144            self.logdebug("Escaped datas : [%s]" % repr(minfile[pos : endpos])) 
    145145        return endpos - pos 
    146          
    147     def maybeEOF(self, nextpos) :     
     146 
     147    def maybeEOF(self, nextpos) : 
    148148        """Tries to detect the EOF marker.""" 
    149149        if self.minfile[nextpos:nextpos+9] == self.eofmarker : 
    150150            return 9 
    151         else :     
     151        else : 
    152152            return 0 
    153          
     153 
    154154    def getJobSize(self) : 
    155155        """Counts pages in a QPDL (SPL2) document. 
    156          
     156 
    157157           Algorithm by Jerome Alet. 
    158             
     158 
    159159           The documentation used for this was : 
    160           
     160 
    161161           Sp�fication Technique (documentation non officielle) 
    162162           Le Language SPL2 
     
    165165        """ 
    166166        # Initialize table of tags 
    167         self.tags = [ lambda pos : 0 ] * 256     
     167        self.tags = [ lambda pos : 0 ] * 256 
    168168        self.tags[0x00] = self.beginPage 
    169169        self.tags[0x01] = self.endPage 
     
    171171        self.tags[0x0c] = self.beginBand 
    172172        self.tags[0x1b] = self.escape # The escape code 
    173          
     173 
    174174        self.eofmarker = "\033%-12345X" 
    175          
     175 
    176176        infileno = self.infile.fileno() 
    177         self.pages = { 0 : { "copies" : 1,  
    178                              "orientation" : "Default",  
    179                              "mediatype" : "Plain",  
    180                              "mediasize" : "Default",  
    181                              "mediasource" : "Default",  
     177        self.pages = { 0 : { "copies" : 1, 
     178                             "orientation" : "Default", 
     179                             "mediatype" : "Plain", 
     180                             "mediasize" : "Default", 
     181                             "mediasource" : "Default", 
    182182                             "duplex" : None, 
    183                            }  
    184                      }       
     183                           } 
     184                     } 
    185185        self.minfile = minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) 
    186186        self.pagecount = 0 
     
    195195                    pos += 1 
    196196                    pos += tags[tag](pos) 
    197             except IndexError : # EOF ?             
     197            except IndexError : # EOF ? 
    198198                pass 
    199199        finally : 
    200200            self.minfile.close() 
    201              
     201 
    202202        defaultduplexmode = "Simplex" 
    203203        defaultpapersize = "" 
    204         defaultpjlcopies = 1     
     204        defaultpjlcopies = 1 
    205205        oldpjlcopies = -1 
    206206        oldduplexmode = "" 
     
    208208        for pnum in range(1, self.pagecount + 1) : 
    209209            # NB : is number of copies is 0, the page won't be output 
    210             # but the formula below is still correct : we want  
     210            # but the formula below is still correct : we want 
    211211            # to decrease the total number of pages in this case. 
    212212            page = self.pages.get(pnum, self.pages.get(1, { "copies" : 1, "mediasize" : "Default", "duplex" : None })) 
     
    227227                    pjlcopies = nbqty 
    228228                else : 
    229                     if oldpjlcopies == -1 :     
     229                    if oldpjlcopies == -1 : 
    230230                        pjlcopies = defaultpjlcopies 
    231                     else :     
    232                         pjlcopies = oldpjlcopies     
    233                 if page["duplex"] :         
     231                    else : 
     232                        pjlcopies = oldpjlcopies 
     233                if page["duplex"] : 
    234234                    duplexmode = page["duplex"] 
    235                 else :     
     235                else : 
    236236                    defaultdm = pjlparser.default_variables.get("DUPLEX", "") 
    237237                    if defaultdm : 
    238238                        if defaultdm.upper() == "ON" : 
    239239                            defaultduplexmode = "Duplex" 
    240                         else :     
     240                        else : 
    241241                            defaultduplexmode = "Simplex" 
    242242                    envdm = pjlparser.environment_variables.get("DUPLEX", "") 
     
    244244                        if envdm.upper() == "ON" : 
    245245                            duplexmode = "Duplex" 
    246                         else :     
     246                        else : 
    247247                            duplexmode = "Simplex" 
    248                     else :         
     248                    else : 
    249249                        if not oldduplexmode : 
    250250                            duplexmode = defaultduplexmode 
    251                         else :     
     251                        else : 
    252252                            duplexmode = oldduplexmode 
    253253                defaultps = pjlparser.default_variables.get("PAPER", "") 
     
    257257                if envps : 
    258258                    papersize = envps 
    259                 else :     
     259                else : 
    260260                    if not oldpapersize : 
    261261                        papersize = defaultpapersize 
    262                     else :     
     262                    else : 
    263263                        papersize = oldpapersize 
    264             else :         
     264            else : 
    265265                if oldpjlcopies == -1 : 
    266266                    pjlcopies = defaultpjlcopies 
    267                 else :     
     267                else : 
    268268                    pjlcopies = oldpjlcopies 
    269269                if not oldduplexmode : 
    270270                    duplexmode = defaultduplexmode 
    271                 else :     
     271                else : 
    272272                    duplexmode = oldduplexmode 
    273                 if not oldpapersize :     
     273                if not oldpapersize : 
    274274                    papersize = defaultpapersize 
    275                 else :     
     275                else : 
    276276                    papersize = oldpapersize 
    277277                duplexmode = oldduplexmode 
     
    279279            if page["mediasize"] != "Default" : 
    280280                papersize = page["mediasize"] 
    281             if not duplexmode :     
     281            if not duplexmode : 
    282282                duplexmode = oldduplexmode or defaultduplexmode 
    283             oldpjlcopies = pjlcopies     
     283            oldpjlcopies = pjlcopies 
    284284            oldduplexmode = duplexmode 
    285285            oldpapersize = papersize 
    286286            copies = max(pjlcopies, page["copies"]) # Was : pjlcopies * page["copies"] 
    287287            self.pagecount += (copies - 1) 
    288             self.logdebug("%s*%s*%s*%s" % (copies,  
    289                                            papersize,  
    290                                            page["mediasource"],  
     288            self.logdebug("%s*%s*%s*%s" % (copies, 
     289                                           papersize, 
     290                                           page["mediasource"], 
    291291                                           duplexmode)) 
    292292        return self.pagecount 
  • pkpgcounter/trunk/pkpgpdls/spl1.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3434    """A parser for SPL1 documents.""" 
    3535    format = "SPL1 (aka GDI)" 
    36     def isValid(self) :     
     36    def isValid(self) : 
    3737        """Returns True if data is SPL1, else False.""" 
    3838        if ((self.firstblock[:128].find("\033%-12345X") != -1) and \ 
     
    4141              (self.firstblock.find("LANGUAGE = SMART") != -1))) : 
    4242            return True 
    43         else :     
     43        else : 
    4444            return False 
    45              
     45 
    4646    def littleEndian(self) : 
    4747        """Toggles to little endianness.""" 
     
    5151        # self.logdebug("Little Endian") 
    5252        return 0 
    53          
     53 
    5454    def bigEndian(self) : 
    5555        """Toggles to big endianness.""" 
     
    5959        # self.logdebug("Big Endian") 
    6060        return 0 
    61      
    62     def escape(self, nextpos) :     
     61 
     62    def escape(self, nextpos) : 
    6363        """Handles the ESC code.""" 
    6464        self.isbitmap = False 
     
    6767        if minfile[pos : pos+8] == r"%-12345X" : 
    6868            endpos = pos + 9 
    69         elif minfile[pos-1] in ESCAPECHARS :     
     69        elif minfile[pos-1] in ESCAPECHARS : 
    7070            endpos = pos 
    71         else :     
     71        else : 
    7272            return 0 
    7373        endmark = (chr(0x1b), chr(0x00)) 
     
    7979                quotes += 1 
    8080            endpos += 1 
    81              
    82         # Store this in a per page mapping.     
     81 
     82        # Store this in a per page mapping. 
    8383        # NB : First time will be at page 0 (i.e. **before** page 1) ! 
    8484        stuff = self.escapedStuff.setdefault(self.pagecount, []) 
     
    9090        self.logdebug("Escaped datas : [%s]" % repr(datas)) 
    9191        return endpos - pos + 1 
    92          
     92 
    9393    def getJobSize(self) : 
    9494        """Counts pages in an SPL1 document. 
    95          
     95 
    9696           Algorithm by Jerome Alet. 
    9797        """ 
     
    110110                    if tag in ESCAPECHARS : 
    111111                        pos += self.escape(pos+1) 
    112                     else :     
     112                    else : 
    113113                        if not self.isbitmap : 
    114114                            raise pdlparser.PDLParserError, "Unfortunately SPL1 is incompletely recognized. Parsing aborted. Please report the problem to %s" % version.__authoremail__ 
     
    116116                         seqnum) = unpack(">IH", minfile[pos:pos+6]) 
    117117                        # self.logdebug("Offset : %i      Sequence Number : %i" % (offset, seqnum)) 
    118                         if not seqnum :  
     118                        if not seqnum : 
    119119                            # Sequence number resets to 0 for each new page. 
    120120                            self.pagecount += 1 
    121121                        pos += 4 + offset 
    122             except struct.error, msg :      
     122            except struct.error, msg : 
    123123                raise pdlparser.PDLParserError, "Unfortunately SPL1 is incompletely recognized (%s). Parsing aborted. Please report the problem to %s" % (msg, version.__authoremail__) 
    124             except IndexError : # EOF ?             
     124            except IndexError : # EOF ? 
    125125                pass 
    126126        finally : 
  • pkpgcounter/trunk/pkpgpdls/tiff.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    3434    required = [ "cp" ] 
    3535    format = "TIFF" 
    36     def isValid(self) :         
     36    def isValid(self) : 
    3737        """Returns True if data is TIFF, else False.""" 
    3838        littleendian = (chr(0x49)*2) + chr(0x2a) + chr(0) 
     
    4040        if self.firstblock[:4] in (littleendian, bigendian) : 
    4141            return True 
    42         else :     
     42        else : 
    4343            return False 
    44      
     44 
    4545    def getJobSize(self) : 
    4646        """Counts pages in a TIFF document. 
    47          
     47 
    4848           Algorithm by Jerome Alet. 
    49             
     49 
    5050           The documentation used for this was : 
    51             
     51 
    5252           http://www.ee.cooper.edu/courses/course_pages/past_courses/EE458/TIFF/ 
    5353        """ 
     
    6363            integerbyteorder = ">I" 
    6464            shortbyteorder = ">H" 
    65         else :     
     65        else : 
    6666            raise pdlparser.PDLParserError, "Unknown file endianness." 
    67         pos = 4     
     67        pos = 4 
    6868        try : 
    69             try :     
     69            try : 
    7070                nextifdoffset = unpack(integerbyteorder, minfile[pos : pos + 4])[0] 
    7171                while nextifdoffset : 
     
    7474                    nextifdoffset = unpack(integerbyteorder, minfile[pos : pos + 4])[0] 
    7575                    pagecount += 1 
    76             except IndexError :             
     76            except IndexError : 
    7777                pass 
    78         finally :         
     78        finally : 
    7979            minfile.close() 
    8080        return pagecount 
  • pkpgcounter/trunk/pkpgpdls/version.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
  • pkpgcounter/trunk/pkpgpdls/zjstream.py

    r3410 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    2828class Parser(pdlparser.PDLParser) : 
    2929    """A parser for ZjStream documents.""" 
    30     def isValid(self) :     
     30    def isValid(self) : 
    3131        """Returns True if data is ZjStream, else False.""" 
    3232        if self.firstblock[:4] == "ZJZJ" : 
    3333            self.format = "Zenographics ZjStream (little endian)" 
    3434            return self.littleEndian() 
    35         elif self.firstblock[:4] == "JZJZ" :     
     35        elif self.firstblock[:4] == "JZJZ" : 
    3636            self.format = "Zenographics ZjStream (big endian)" 
    3737            return self.bigEndian() 
    38         else :     
     38        else : 
    3939            return False 
    40          
     40 
    4141    def littleEndian(self) : 
    4242        """Toggles to little endianness.""" 
    4343        self.unpackHeader = "<IIIHH" 
    4444        return True 
    45          
     45 
    4646    def bigEndian(self) : 
    4747        """Toggles to big endianness.""" 
    4848        self.unpackHeader = ">IIIHH" 
    4949        return True 
    50          
     50 
    5151    def getJobSize(self) : 
    5252        """Computes the number of pages in a ZjStream document.""" 
     
    6666                 signature) = unpack(unpackHeader, header) 
    6767                self.infile.seek(totalChunkSize - len(header), 1) 
    68                 if chunkType == 2 :     
     68                if chunkType == 2 : 
    6969                    #self.logdebug("startPage") 
    7070                    startpagecount += 1 
     
    7474                #elif chunkType == 0 : 
    7575                #    self.logdebug("startDoc") 
    76                 #elif chunkType == 1 :     
     76                #elif chunkType == 1 : 
    7777                #    self.logdebug("endDoc") 
    78                 #     
     78                # 
    7979                #self.logdebug("Chunk size : %s" % totalChunkSize) 
    8080                #self.logdebug("Chunk type : 0x%08x" % chunkType) 
     
    8585        except struct.error : 
    8686            raise pdlparser.PDLParserError, "This file doesn't seem to be valid ZjStream datas." 
    87              
     87 
    8888        # Number of endpage commands should be sufficient, 
    8989        # but we never know : someone could try to cheat the printer 
  • pkpgcounter/trunk/README

    r3409 r3436  
    2626 
    2727        - PostScript (both DSC compliant and binary) 
    28          
     28 
    2929        - PDF 
    30          
     30 
    3131        - PCL3/4/5 
    32          
     32 
    3333        - PCLXL (aka PCL6) 
    34          
     34 
    3535        - DVI 
    36          
     36 
    3737        - OpenDocument (ISO/IEC DIS 26300) 
    38          
     38 
    3939        - Microsoft Word (c) (tm) (r) (etc...) 
    40          
     40 
    4141        - Plain text 
    42          
     42 
    4343        - TIFF 
    44          
     44 
    4545        - Several other image formats 
    46          
     46 
    4747        - ESC/P2 
    48          
     48 
    4949        - Zenographics ZjStream 
    50          
     50 
    5151        - Samsung QPDL (aka SPL2) 
    52          
     52 
    5353        - Samsung SPL1 
    54          
     54 
    5555        - ESC/PageS03 
    56          
     56 
    5757        - Brother HBP 
    5858 
    5959        - Brother XL2HB 
    60          
     60 
    6161        - Hewlett-Packard Lightweight Imaging Device Interface Language 
    62          
     62 
    6363        - Structured Fax 
    64          
     64 
    6565        - Canon BJ/BJC 
    66          
     66 
    6767        - ASCII PNM (Netpbm) 
    68          
    69 The eleven latter ones, as well as some TIFF documents, are currently  
    70 only supported in page counting mode.  
    7168 
    72 By default, when launched pkpgcounter prints on its standard output  
    73 a single integer representing the total number of pages in all the  
    74 files which filenames you've passed on the command line.  
     69The eleven latter ones, as well as some TIFF documents, are currently 
     70only supported in page counting mode. 
     71 
     72By default, when launched pkpgcounter prints on its standard output 
     73a single integer representing the total number of pages in all the 
     74files which filenames you've passed on the command line. 
    7575 
    7676With no argument, or with a single dash in non-option arguments, 
     
    8787 
    8888  0 - Download pkpgcounter from : 
    89    
     89 
    9090        http://www.pykota.com/software/pkpgcounter/download 
    91          
    92       and extract it :   
    93        
     91 
     92      and extract it : 
     93 
    9494        $ tar -zxf pkpgcounter-x.yy.tar.gz 
    95          
     95 
    9696        where x.yy is pkpgcounter' version number. 
    97          
     97 
    9898  1 - Run the installation script : 
    99        
     99 
    100100        $ python setup.py install 
    101          
    102       This will usually install the pkpgcounter into /usr/bin and   
     101 
     102      This will usually install the pkpgcounter into /usr/bin and 
    103103      the library into /usr/lib/python2.?/site-packages/pkpgpdls/ 
    104          
     104 
    105105  2 - Use pkpgcounter : 
    106    
     106 
    107107      $ pkpgcounter file1.ps file2.pclxl ... <fileN.escp2 
    108        
     108 
    109109      pkpgcounter will display the total size in pages of all the files 
    110110      passed on the command line. 
    111        
     111 
    112112      $ pkpgcounter --colorspace bw --resolution 150 file1.ps 
    113    
     113 
    114114      Will output the percent of black ink needed on each page of 
    115115      the file1.ps file rendered at 150 dpi. 
    116        
    117   3 - That's all !     
    118    
     116 
     117  3 - That's all ! 
     118 
    119119DEPENDENCIES : 
    120120 
    121121  Most of the time, pkpgcounter only depends on the presence of : 
    122    
     122 
    123123  - The Python Imaging Library (python-imaging) 
    124    
     124 
    125125  But, depending on the file formats you plan to work with, and on the 
    126126  accounting mode you want to use (pages vs ink), you may need to install 
    127127  some or all of the additional software listed below. Usually, if one is 
    128   needed then pkpgcounter will complain. So your best bet is probably  
     128  needed then pkpgcounter will complain. So your best bet is probably 
    129129  to NOT INSTALL anything until pkpgcounter asks you to do so on its 
    130130  standard error stream. Here's the list of software which may be needed 
     
    132132 
    133133  - GhostScript (gs) 
    134    
     134 
    135135  - The X Virtual Frame Buffer (xvfb) 
    136    
     136 
    137137  - The X authority file utility xauth (xbase-clients) 
    138    
     138 
    139139  - The dvips converter from TeX DVI to PostScript (tetex-bin) 
    140    
     140 
    141141  - The ImageMagick image manipulation toolkit (imagemagick) 
    142    
     142 
    143143  - The AbiWord word processor (abiword) 
    144144 
    145145  - The GhostPCL/GhostPDL's pcl6 converter from PCL to PostScript 
    146          
     146 
    147147============================================================================= 
    148148 
    149 Troubleshooting :  
     149Troubleshooting : 
    150150----------------- 
    151151 
    152152  If pkpgcounter gives incorrect results to you, please make an incorrectly 
    153   parsed data file available to us on some website, and tell us which  
    154   driver was used, how many pages are in the file, and any additional  
     153  parsed data file available to us on some website, and tell us which 
     154  driver was used, how many pages are in the file, and any additional 
    155155  information you think is relevant. 
    156    
     156 
    157157  If pkpgcounter complain about your system lacking the Python Psyco module, 
    158158  please consider installing it to speedup file parsing. However, don't forget 
    159   that Psyco currently only runs on the 32 bits x86 platform, so no need to  
     159  that Psyco currently only runs on the 32 bits x86 platform, so no need to 
    160160  install it if you've got another system type. 
    161    
     161 
    162162============================================================================= 
    163163 
     
    167167 
    168168    http://www.fea.unicamp.br/pclcount/ 
    169      
    170 Their software is distributed under either the terms of a BSD-like license,     
     169 
     170Their software is distributed under either the terms of a BSD-like license, 
    171171or the terms of the GNU General Public License of the Free Software Foundation. 
    172172 
     
    176176The old parser was still available until pkpgcounter v2.18 was published, but 
    177177was definitely removed after that, just before pkpgcounter v3.00 was published. 
    178      
    179 pkpgcounter's PCLXL (aka PCL6) parser doesn't originate from PCLCount, but  
     178 
     179pkpgcounter's PCLXL (aka PCL6) parser doesn't originate from PCLCount, but 
    180180was written from scratch, just like all the other parsers included in 
    181181pkpgcounter. 
     
    183183============================================================================= 
    184184 
    185 pkpgcounter's ink coverage algorithm for the CMYK colorspace is a  
    186 direct Python port from the PrintBill project by Daniel Franklin.  
    187 PrintBill is distributed under the terms of the GNU General Public  
    188 License of the Free Software Foundation, version 2 or higher. The  
    189 algorithms used for the other colorspaces are a complete rewrite of  
    190 PrintBill's algorithms using both Python and the Python Imaging  
    191 Library's facilities.  
     185pkpgcounter's ink coverage algorithm for the CMYK colorspace is a 
     186direct Python port from the PrintBill project by Daniel Franklin. 
     187PrintBill is distributed under the terms of the GNU General Public 
     188License of the Free Software Foundation, version 2 or higher. The 
     189algorithms used for the other colorspaces are a complete rewrite of 
     190PrintBill's algorithms using both Python and the Python Imaging 
     191Library's facilities. 
    192192 
    193193============================================================================= 
  • pkpgcounter/trunk/setup.py

    r564 r3436  
    11#! /usr/bin/env python 
    2 # -*- coding: UTF-8 -*- 
     2# -*- coding: utf-8 -*- 
    33# 
    44# pkpgcounter : a generic Page Description Language parser 
     
    99# the Free Software Foundation, either version 3 of the License, or 
    1010# (at your option) any later version. 
    11 #  
     11# 
    1212# This program is distributed in the hope that it will be useful, 
    1313# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1414# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1515# GNU General Public License for more details. 
    16 #  
     16# 
    1717# You should have received a copy of the GNU General Public License 
    1818# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    2828try : 
    2929    from distutils.core import setup 
    30 except ImportError, msg :     
     30except ImportError, msg : 
    3131    sys.stderr.write("%s\n" % msg) 
    3232    sys.stderr.write("You need the DistUtils Python module.\nunder Debian, you may have to install the python-dev package.\nOf course, YMMV.\n") 
    3333    sys.exit(-1) 
    34      
    35 try :     
     34 
     35try : 
    3636    from PIL import Image 
    37 except ImportError :     
     37except ImportError : 
    3838    sys.stderr.write("You need the Python Imaging Library (aka PIL).\nYou can grab it from http://www.pythonware.com\n") 
    3939    sys.exit(-1) 
    40      
    41 try :     
     40 
     41try : 
    4242    import psyco 
    43 except ImportError :     
     43except ImportError : 
    4444    sys.stderr.write("WARN: If you are running on a 32 Bits x86 platform, you should install the Python Psyco module if possible, this would greatly speedup parsing. NB : Psyco doesn't work on other platforms, so don't worry if you're in this case.\n") 
    45      
     45 
    4646sys.path.insert(0, "pkpgpdls") 
    4747from pkpgpdls.version import __version__, __doc__ 
     
    5353    directory = os.sep.join(["share", "locale", lang, "LC_MESSAGES"]) 
    5454    data_files.append((directory, [ mofile ])) 
    55      
    56 docdir = "share/doc/pkpgcounter"     
     55 
     56docdir = "share/doc/pkpgcounter" 
    5757docfiles = ["README", "COPYING", "BUGS", "CREDITS", "NEWS"] 
    5858data_files.append((docdir, docfiles)) 
    5959 
    6060directory = os.sep.join(["share", "man", "man1"]) 
    61 manpages = glob.glob(os.sep.join(["man", "*.1"]))     
     61manpages = glob.glob(os.sep.join(["man", "*.1"])) 
    6262data_files.append((directory, manpages)) 
    6363 
     
    7171      scripts = [ "bin/pkpgcounter" ], 
    7272      data_files = data_files) 
    73        
     73 
  • pkpgcounter/trunk/tests/gstests.py

    r564 r3436  
    11#! /usr/bin/env python 
    2 # -*- coding: UTF-8 -*- 
     2# -*- coding: utf-8 -*- 
    33# 
    44# pkpgcounter : a generic Page Description Language parser 
     
    99# the Free Software Foundation, either version 3 of the License, or 
    1010# (at your option) any later version. 
    11 #  
     11# 
    1212# This program is distributed in the hope that it will be useful, 
    1313# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1414# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1515# GNU General Public License for more details. 
    16 #  
     16# 
    1717# You should have received a copy of the GNU General Public License 
    1818# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    4343        self.md5sum = self.computeChecksum() 
    4444        self.mastersize = None 
    45          
    46     def __del__(self) :     
     45 
     46    def __del__(self) : 
    4747        """Remove temporary file, if any.""" 
    4848        if self.tmp is not None : 
    4949            self.tmp.close() 
    50              
    51     def computeChecksum(self) :     
     50 
     51    def computeChecksum(self) : 
    5252        """Computes an MD5 checksum for the input file's content.""" 
    5353        checksum = md5.new() 
     
    6060            infile = sys.stdin 
    6161            istemp = True 
    62         else :     
     62        else : 
    6363            infile = open(self.inputfile, "rb") 
    64              
     64 
    6565        while True : 
    6666            data = infile.read(MEGABYTE) 
    6767            if not data : 
    6868                break 
    69             if istemp :     
     69            if istemp : 
    7070                self.tmp.write(data) 
    7171            checksum.update(data) 
    72              
    73         if istemp :     
    74             self.tmp.flush()     
     72 
     73        if istemp : 
     74            self.tmp.flush() 
    7575        else : 
    7676            infile.close() 
    77              
    78         return checksum.hexdigest()     
    79          
     77 
     78        return checksum.hexdigest() 
     79 
    8080    def getAvailableDevices(self) : 
    8181        """Returns a list of available GhostScript devices. 
    82          
     82 
    8383           The list is returned without any x11, bbox, nor ijs related device. 
    8484        """ 
     
    9393                                           and (not dev == "/nullpage") \ 
    9494                                           and (not dev == "/bbox") ] 
    95                 devices.sort()                            
     95                devices.sort() 
    9696                return devices 
    9797        return [] 
    98              
     98 
    9999    def getAvailableIJSPrintClasses(self) : 
    100100        """Returns a list of available IJS Print Classes. 
    101          
     101 
    102102           Currently the list is a static one and doesn't contain all the available print classes. 
    103103        """ 
    104         return [ "DJ3600", "DJ3320", "DJ9xx", "DJGenericVIP", "LJColor",  
     104        return [ "DJ3600", "DJ3320", "DJ9xx", "DJGenericVIP", "LJColor", 
    105105                 "DJ850", "DJ890", "DJ9xxVIP", "DJ8xx", "DJ540", "DJ660", 
    106106                 "DJ6xx", "DJ350", "DJ6xxPhoto", "DJ630", "DJ8x5", "DJ4100", 
     
    108108                 "Postscript", "LJJetReady", "LJMono", "LJFastRaster", 
    109109                 "LJZjsMono", ] 
    110              
     110 
    111111    def batchGeneration(self, infilename, devices, root, command) : 
    112112        """Loops over a set of devices calling a particular command.""" 
     
    121121            if os.path.exists(outfilename) and os.stat(outfilename).st_size : 
    122122                sys.stdout.write("Skipping %(outfilename)s : already exists.\n" % locals()) 
    123             else :     
     123            else : 
    124124                sys.stdout.write("Generating %(outfilename)s " % locals()) 
    125125                sys.stdout.flush() 
    126126                os.system(cmd) 
    127127                sys.stdout.write("\n") 
    128                  
     128 
    129129            if not os.path.exists(outfilename) : 
    130130                sys.stderr.write("ERROR : During the generation of %(outfilename)s\n" % locals()) 
    131             elif not os.stat(outfilename).st_size :     
     131            elif not os.stat(outfilename).st_size : 
    132132                sys.stderr.write("ERROR : Unsupported driver, impossible to generate %(outfilename)s\n" % locals()) 
    133133                os.remove(outfilename) 
    134             else :     
     134            else : 
    135135                self.results[outfilename] = { "command" : cmd, 
    136136                                              "device" : "%s" % (devprefix + device), 
     
    138138                                              "details" : None, 
    139139                                            } 
    140                  
     140 
    141141    def genTestSuite(self) : 
    142142        """Generate the testsuite.""" 
    143143        root = "testsuite.%s" % self.md5sum 
    144         self.batchGeneration(self.inputfile, self.getAvailableDevices(),  
    145                                         root,  
     144        self.batchGeneration(self.inputfile, self.getAvailableDevices(), 
     145                                        root, 
    146146                                        'gs -dQUIET -dBATCH -dNOPAUSE -dPARANOIDSAFER -sOutputFile="%(outfilename)s" -sDEVICE="%(device)s" "%(infilename)s"') 
    147                                      
    148         self.batchGeneration(self.inputfile, self.getAvailableIJSPrintClasses(),  
    149                                         "%(root)s.hpijs" % locals(),  
     147 
     148        self.batchGeneration(self.inputfile, self.getAvailableIJSPrintClasses(), 
     149                                        "%(root)s.hpijs" % locals(), 
    150150                                        'gs -dBATCH -dQUIET -dPARANOIDSAFER -dNOPAUSE -sDEVICE=ijs -sIjsServer=hpijs -dIjsUseOutputFD -sDeviceManufacturer="HEWLETT-PACKARD" -sDeviceModel="%(device)s" -sOutputFile="%(outfilename)s" "%(infilename)s"') 
    151                  
    152     def runPipe(self, cmd) :             
     151 
     152    def runPipe(self, cmd) : 
    153153        """Runs a command in a pipe, returns the command's output as a string.""" 
    154154        answerfd = os.popen(cmd, "r") 
    155155        try : 
    156156            return answerfd.read().strip() 
    157         finally :         
     157        finally : 
    158158            answerfd.close() 
    159          
    160     def computeSize(self, filename) :     
     159 
     160    def computeSize(self, filename) : 
    161161        """Computes the size in pages of a file in the testsuite.""" 
    162162        answer = self.runPipe('pkpgcounter "%(filename)s" 2>/dev/null' % locals()) 
    163163        try : 
    164164            return int(answer) 
    165         except (ValueError, TypeError) :     
     165        except (ValueError, TypeError) : 
    166166            return 0 
    167          
     167 
    168168    def runTests(self) : 
    169169        """Launches the page counting tests against the testsuite.""" 
     
    172172        if not mastersize : 
    173173            raise RuntimeError, "Unable to compute the size of the testsuite's master file %(masterfilename)s" % locals() 
    174         else :     
     174        else : 
    175175            sys.stdout.write("Master file's contains %(mastersize)i pages.\n" % locals()) 
    176176        testsuite = glob.glob("testsuite.*") 
     
    181181            if len(parts) > 3 : 
    182182                devname = ".".join(parts[2:]) 
    183             else :     
     183            else : 
    184184                devname = parts[-1] 
    185             result = self.results.setdefault(testfname, { "command" : "See above",  
    186                                                           "device" : devname,  
    187                                                           "result" : None,  
     185            result = self.results.setdefault(testfname, { "command" : "See above", 
     186                                                          "device" : devname, 
     187                                                          "result" : None, 
    188188                                                          "details" : None }) 
    189189            sys.stdout.write("Testing %(testfname)s ... " % locals()) 
     
    194194                    result["result"] = "UNSUPPORTED" 
    195195                    result["details"] = "Unsupported file format" 
    196                 else :     
     196                else : 
    197197                    result["result"] = "FAILED" 
    198198                    result["details"] = "Found %(size)i pages instead of %(mastersize)i\n" % locals() 
    199             else :     
     199            else : 
    200200                result["result"] = "SUPPORTED" 
    201201                result["details"] = None 
    202             sys.stdout.write("%s\n" % result["result"])     
     202            sys.stdout.write("%s\n" % result["result"]) 
    203203        self.supportedpct = 100.0 * len([True for r in self.results.values() if r["result"] == "SUPPORTED"]) / nbtests 
    204204        self.failedpct = 100.0 * len([True for r in self.results.values() if r["result"] == "FAILED"]) / nbtests 
    205205        self.unsupportedpct = 100.0 * len([True for r in self.results.values() if r["result"] == "UNSUPPORTED"]) / nbtests 
    206          
     206 
    207207    def genHTMLReport(self, filename) : 
    208208        """Generates an HTML report.""" 
     
    232232        for key in keys : 
    233233            value = self.results[key] 
    234             linecount += 1     
    235             if not (linecount % 2) :     
     234            linecount += 1 
     235            if not (linecount % 2) : 
    236236                linecolor = "#DEDEDE" 
    237             else :     
     237            else : 
    238238                linecolor = "#FFFFFF" 
    239             out.write('<tr bgcolor="%s">\n' % linecolor)     
     239            out.write('<tr bgcolor="%s">\n' % linecolor) 
    240240            if value["result"] == "SUPPORTED" : 
    241241                color = "#00FF00" 
    242             elif value["result"] == "UNSUPPORTED" :     
     242            elif value["result"] == "UNSUPPORTED" : 
    243243                color = "#FF0000" 
    244             else :     
     244            else : 
    245245                color = "orange" 
    246246            out.write('<td bgcolor="%s"><strong>%s</strong></td>\n' % (color, value["device"])) 
     
    250250        out.write("</table></body></html>\n") 
    251251        out.close() 
    252          
    253 def main() :         
     252 
     253def main() : 
    254254    """Main function.""" 
    255255    try : 
     
    259259            sys.stderr.write("usage : %s [inputfile.ps]\n" % sys.argv[0]) 
    260260            sys.exit(-1) 
    261         else :     
     261        else : 
    262262            testsuite = TestSuite(sys.argv[1]) 
    263263            testsuite.genTestSuite() 
    264264            testsuite.runTests() 
    265265            testsuite.genHTMLReport("%s.html" % testsuite.md5sum) 
    266     except KeyboardInterrupt :         
     266    except KeyboardInterrupt : 
    267267        sys.stderr.write("Interrupted at user's request !\n") 
    268          
     268 
    269269if __name__ == "__main__" : 
    270270    sys.exit(main()) 
    271          
     271 
  • pkpgcounter/trunk/tests/README

    r463 r3436  
    1919==================================================================== 
    2020 
    21 This directory contains a gzipped PostScript file, master.ps.gz,  
    22 obtained by printing to a file a part of the SlashDot.org website  
    23 from the Galeon web browser on July 2nd 2004.  
     21This directory contains a gzipped PostScript file, master.ps.gz, 
     22obtained by printing to a file a part of the SlashDot.org website 
     23from the Galeon web browser on July 2nd 2004. 
    2424 
    25 When uncompressed, this 16 pages file can be used to test the  
    26 accuracy of the generic Page Description Language analyzer included  
    27 in pkpgcounter for different conversion outputs of gs.  
     25When uncompressed, this 16 pages file can be used to test the 
     26accuracy of the generic Page Description Language analyzer included 
     27in pkpgcounter for different conversion outputs of gs. 
    2828 
    2929To see if it works, simply launch : 
    3030 
    3131        $ ./runtests.sh 
    32          
    33 It should report 16 pages for each document. If it doesn't then  
    34 there's a bug in the generic Page Description Language analyzer.  
     32 
     33It should report 16 pages for each document. If it doesn't then 
     34there's a bug in the generic Page Description Language analyzer. 
    3535Please report this to : alet@librelogiciel.com 
    3636 
    3737This script will also launch the test for the computation of 
    38 ink coverage. Look at the file colors.pdf to see what the  
     38ink coverage. Look at the file colors.pdf to see what the 
    3939results should look like. 
  • pkpgcounter/trunk/tests/runcolors.py

    r564 r3436  
    11#! /usr/bin/env python 
    2 # -*- coding: UTF-8 -*- 
     2# -*- coding: utf-8 -*- 
    33# 
    44# pkpgcounter : a generic Page Description Language parser 
     
    99# the Free Software Foundation, either version 3 of the License, or 
    1010# (at your option) any later version. 
    11 #  
     11# 
    1212# This program is distributed in the hope that it will be useful, 
    1313# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1414# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1515# GNU General Public License for more details. 
    16 #  
     16# 
    1717# You should have received a copy of the GNU General Public License 
    1818# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    5252        pkpgcounter --colorspace $cspace colors.pdf ; 
    5353        echo ; 
    54     done     
     54    done 
    5555 
    5656Please report any problem to : alet@librelogiciel.com 
     
    115115    from reportlab.lib.units import cm 
    116116    from reportlab.pdfgen import canvas 
    117 except ImportError :     
     117except ImportError : 
    118118    sys.stderr.write("Please download and install ReportLab\n\tfrom http://www.reportlab.org\n") 
    119119    sys.exit(-1) 
     
    124124    xbase = 2*cm 
    125125    ybase = height - 2*cm 
    126      
     126 
    127127    # First we output the explanations on the first page. 
    128128    canv.setFont("Courier", 14) 
     
    131131        ybase -= 18 
    132132    canv.showPage() 
    133      
     133 
    134134    # Then we output each page 
    135135    for color in (colors.Color(1, 0, 0),        # Red 
    136136                  colors.Color(0, 1, 0),        # Green 
    137137                  colors.Color(0, 0, 1)) :      # Blue 
    138         canv.setStrokeColorRGB(*color.rgb())           
    139         canv.setFillColorRGB(*color.rgb())           
     138        canv.setStrokeColorRGB(*color.rgb()) 
     139        canv.setFillColorRGB(*color.rgb()) 
    140140        canv.rect(0, 0, width, height, fill=1) 
    141141        canv.showPage() 
    142          
     142 
    143143    for color in (colors.CMYKColor(1, 0, 0, 0), # Cyan 
    144144                  colors.CMYKColor(0, 1, 0, 0), # Magenta 
     
    146146                  colors.CMYKColor(0, 0, 0, 1), # Black 
    147147                  colors.CMYKColor(0, 0, 0, 0)) : # White 
    148         canv.setStrokeColorCMYK(*color.cmyk())           
    149         canv.setFillColorCMYK(*color.cmyk())           
     148        canv.setStrokeColorCMYK(*color.cmyk()) 
     149        canv.setFillColorCMYK(*color.cmyk()) 
    150150        canv.rect(0, 0, width, height, fill=1) 
    151151        canv.showPage() 
    152          
     152 
    153153    # Finally outputs the expected results. 
    154154    canv.setFont("Helvetica-Bold", 16) 
     
    160160        ybase -= 14 
    161161    canv.showPage() 
    162          
    163     canv.save()         
     162 
     163    canv.save() 
  • pkpgcounter/trunk/tests/runtest.sh

    r564 r3436  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    1919echo "Analyzing colors..." 
    2020if ! [ -f "colors.pdf" ]  ; then 
    21    python ./runcolors.py ;  
     21   python ./runcolors.py ; 
    2222fi ; 
    23 echo  
     23echo 
    2424 
    2525for cspace in BW RGB CMY CMYK GC ; do 
     
    2727    pkpgcounter --colorspace $cspace colors.pdf ; 
    2828    echo ; 
    29 done     
     29done 
    3030 
    3131echo "Generating testsuite..."