Show
Ignore:
Timestamp:
09/27/08 22:02:37 (16 years ago)
Author:
jerome
Message:

Removed unnecessary spaces at EOL.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkbanner

    r3411 r3413  
    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/>. 
     
    2222# 
    2323 
    24 """A banner generator for PyKota"""         
     24"""A banner generator for PyKota""" 
    2525 
    2626import sys 
     
    3434    import reportlab.lib 
    3535    from reportlab.lib.units import cm 
    36 except ImportError :     
     36except ImportError : 
    3737    hasRL = False 
    38 else :     
     38else : 
    3939    hasRL = True 
    40      
     40 
    4141try : 
    42     import PIL.Image  
    43 except ImportError :     
     42    import PIL.Image 
     43except ImportError : 
    4444    hasPIL = False 
    45 else :     
     45else : 
    4646    hasPIL = True 
    47      
     47 
    4848import pykota.appinit 
    4949from pykota.utils import run 
     
    5656from pykota import version 
    5757 
    58 class PyKotaBanner(Tool) :         
     58class PyKotaBanner(Tool) : 
    5959    """A class for pkbanner.""" 
    60     def getVar(self, varname) :             
     60    def getVar(self, varname) : 
    6161        """Extracts a variable from the environment and returns its value or 'Unknown' in the current locale.""" 
    6262        return os.environ.get(varname) or _("Unknown") 
    63          
     63 
    6464    def printVar(self, canvas, x, y, label, value, size, savetoner) : 
    6565        """Outputs a variable onto the PDF canvas. 
    66          
     66 
    6767           Returns the number of points to substract to current Y coordinate. 
    68         """    
     68        """ 
    6969        canvas.saveState() 
    7070        canvas.setFont("Helvetica-Bold", size) 
     
    7979        canvas.restoreState() 
    8080        return (size + 4) 
    81      
     81 
    8282    def genPDF(self, pagesize, logo, url, text, savetoner) : 
    8383        """Generates the banner in PDF format, return the PDF document as a string.""" 
    8484        document = cStringIO.StringIO() 
    8585        c = canvas.Canvas(document, pagesize=pagesize, pageCompression=1) 
    86          
     86 
    8787        c.setAuthor(self.effectiveUserName) 
    8888        c.setTitle(_("PyKota generated Banner")) 
    8989        c.setSubject(_("This is a print banner generated with PyKota")) 
    90          
     90 
    9191        xcenter = pagesize[0] / 2.0 
    9292        ycenter = pagesize[1] / 2.0 
    93                      
    94         ypos = pagesize[1] - (2 * cm)             
    95          
     93 
     94        ypos = pagesize[1] - (2 * cm) 
     95 
    9696        if logo : 
    97             try :     
     97            try : 
    9898                imglogo = PIL.Image.open(logo) 
    99             except :     
     99            except : 
    100100                self.printInfo("Unable to open image %s" % logo, "warn") 
    101101            else : 
    102102                (width, height) = imglogo.size 
    103                 multi = float(width) / (8 * cm)  
     103                multi = float(width) / (8 * cm) 
    104104                width = float(width) / multi 
    105105                height = float(height) / multi 
     
    107107                ypos -= height 
    108108                c.drawImage(logo, xpos, ypos, width, height) 
    109          
     109 
    110110        # New top 
    111111        xpos = pagesize[0] / 5.0 
    112112        ypos -= (1 * cm) + 20 
    113          
     113 
    114114        printername = self.getVar("PYKOTAPRINTERNAME") 
    115115        username = self.getVar("PYKOTAUSERNAME") 
    116116        accountbanner = self.config.getAccountBanner(printername) 
    117          
     117 
    118118        # Outputs the username 
    119         ypos -= self.printVar(c, xcenter, ypos, _("Username"), username, 20, savetoner)  
    120          
    121         # Text     
     119        ypos -= self.printVar(c, xcenter, ypos, _("Username"), username, 20, savetoner) 
     120 
     121        # Text 
    122122        if text : 
    123             ypos -= self.printVar(c, xcenter, ypos, _("More Info"), text, 20, savetoner)  
    124          
     123            ypos -= self.printVar(c, xcenter, ypos, _("More Info"), text, 20, savetoner) 
     124 
    125125        # Printer and Job Id 
    126126        job = "%s - %s" % (printername, self.getVar("PYKOTAJOBID")) 
    127         ypos -= self.printVar(c, xcenter, ypos, _("Job"), job, 14, savetoner)  
    128          
     127        ypos -= self.printVar(c, xcenter, ypos, _("Job"), job, 14, savetoner) 
     128 
    129129        # Current date (TODO : at the time the banner was printed ! Change this to job's submission date) 
    130130        datetime = time.strftime("%c", time.localtime()).decode(self.charset, "replace") 
    131         ypos -= self.printVar(c, xcenter, ypos, _("Date"), datetime, 14, savetoner)  
    132          
     131        ypos -= self.printVar(c, xcenter, ypos, _("Date"), datetime, 14, savetoner) 
     132 
    133133        # Result of the print job 
    134134        action = self.getVar("PYKOTAACTION") 
    135135        if action == "ALLOW" : 
    136136            action = _("Allowed") 
    137         elif action == "DENY" :     
     137        elif action == "DENY" : 
    138138            action = _("Denied") 
    139         elif action == "WARN" :     
     139        elif action == "WARN" : 
    140140            action = _("Allowed with Warning") 
    141         elif action == "PROBLEM" :     
     141        elif action == "PROBLEM" : 
    142142            # should never occur 
    143143            action = _("Problem") 
    144         elif action == "CANCEL" :     
     144        elif action == "CANCEL" : 
    145145            # should never occur 
    146146            action = _("Cancelled") 
    147         ypos -= self.printVar(c, xcenter, ypos, _("Result"), action, 14, savetoner)  
    148          
     147        ypos -= self.printVar(c, xcenter, ypos, _("Result"), action, 14, savetoner) 
     148 
    149149        # skip some space 
    150150        ypos -= 20 
    151          
     151 
    152152        # Outputs title and filename 
    153153        # We put them at x=0.25*pagewidth so that the line is long enough to hold them 
    154154        title = self.getVar("PYKOTATITLE") 
    155         ypos -= self.printVar(c, xcenter / 2.0, ypos, _("Title"), title, 10, savetoner)  
    156          
     155        ypos -= self.printVar(c, xcenter / 2.0, ypos, _("Title"), title, 10, savetoner) 
     156 
    157157        filename = self.getVar("PYKOTAFILENAME") 
    158         ypos -= self.printVar(c, xcenter / 2.0, ypos, _("Filename"), filename, 10, savetoner)  
    159          
     158        ypos -= self.printVar(c, xcenter / 2.0, ypos, _("Filename"), filename, 10, savetoner) 
     159 
    160160        # skip some space 
    161161        ypos -= 20 
    162          
     162 
    163163        # Now outputs the user's account balance or page counter 
    164         ypos -= self.printVar(c, xcenter, ypos, _("Pages printed so far on %s") % printername, self.getVar("PYKOTAPAGECOUNTER"), 14, savetoner)  
     164        ypos -= self.printVar(c, xcenter, ypos, _("Pages printed so far on %s") % printername, self.getVar("PYKOTAPAGECOUNTER"), 14, savetoner) 
    165165        limitby = self.getVar("PYKOTALIMITBY") 
    166         if limitby == "balance" :   
    167             ypos -= self.printVar(c, xcenter, ypos, _("Account balance"), self.getVar("PYKOTABALANCE"), 14, savetoner)  
     166        if limitby == "balance" : 
     167            ypos -= self.printVar(c, xcenter, ypos, _("Account balance"), self.getVar("PYKOTABALANCE"), 14, savetoner) 
    168168        elif limitby == "quota" : 
    169             ypos -= self.printVar(c, xcenter, ypos, _("Soft Limit"), self.getVar("PYKOTASOFTLIMIT"), 14, savetoner)  
    170             ypos -= self.printVar(c, xcenter, ypos, _("Hard Limit"), self.getVar("PYKOTAHARDLIMIT"), 14, savetoner)  
    171             ypos -= self.printVar(c, xcenter, ypos, _("Date Limit"), self.getVar("PYKOTADATELIMIT"), 14, savetoner)  
     169            ypos -= self.printVar(c, xcenter, ypos, _("Soft Limit"), self.getVar("PYKOTASOFTLIMIT"), 14, savetoner) 
     170            ypos -= self.printVar(c, xcenter, ypos, _("Hard Limit"), self.getVar("PYKOTAHARDLIMIT"), 14, savetoner) 
     171            ypos -= self.printVar(c, xcenter, ypos, _("Date Limit"), self.getVar("PYKOTADATELIMIT"), 14, savetoner) 
    172172        else : 
    173173            if limitby == "noquota" : 
    174174                msg = _("No Limit") 
    175             elif limitby == "nochange" :     
     175            elif limitby == "nochange" : 
    176176                msg = _("No Accounting") 
    177             elif limitby == "noprint" :     
     177            elif limitby == "noprint" : 
    178178                msg = _("Forbidden") 
    179             else :     
     179            else : 
    180180                msg = _("Unknown") 
    181181            ypos -= self.printVar(c, xcenter, ypos, _("Printing Mode"), msg, 14, savetoner) 
    182              
     182 
    183183        # URL 
    184184        if url : 
     
    189189            c.drawCentredString(xcenter, 2 * cm, url) 
    190190            c.restoreState() 
    191          
     191 
    192192        c.showPage() 
    193193        c.save() 
    194194        return document.getvalue() 
    195          
     195 
    196196    def main(self, arguments, options) : 
    197197        """Generates a banner.""" 
     
    200200        if not hasPIL : 
    201201            raise PyKotaToolError, "The Python Imaging Library is missing. Download it from http://www.pythonware.com/downloads" 
    202              
    203         self.logdebug("Generating the banner in PDF format...")     
     202 
     203        self.logdebug("Generating the banner in PDF format...") 
    204204        doc = self.genPDF(getPageSize(options.pagesize), 
    205                           options.logo.strip().encode(sys.getfilesystemencoding(), "replace"),  
    206                           options.url.strip(),  
    207                           " ".join(arguments).strip(),  
     205                          options.logo.strip().encode(sys.getfilesystemencoding(), "replace"), 
     206                          options.url.strip(), 
     207                          " ".join(arguments).strip(), 
    208208                          options.savetoner / 100.0) 
    209          
    210         self.logdebug("Converting the banner to PostScript...")     
     209 
     210        self.logdebug("Converting the banner to PostScript...") 
    211211        command = "gs -q -dNOPAUSE -dBATCH -dPARANOIDSAFER -sDEVICE=pswrite -sOutputFile=- -" 
    212212        subpr = subprocess.Popen(command, 
     
    215215                                 stdout=subprocess.PIPE, 
    216216                                 stderr=subprocess.PIPE) 
    217         try :                          
     217        try : 
    218218            (out, err) = subpr.communicate(doc) 
    219         except OSError, msg :     
     219        except OSError, msg : 
    220220            raise PyKotaToolError, _("Impossible to execute '%(command)s'") % locals() 
    221221        status = subpr.wait() 
     
    255255    parser.add_example('--logo="" --savetoner=75', 
    256256                       _("This would generate a banner in the default page size, with no logo, and text luminosity would be increased by 75%.")) 
    257                         
     257 
    258258    run(parser, PyKotaBanner)