Changeset 1923
- Timestamp:
- 11/15/04 23:01:34 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 7 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r1918 r1923 24 24 # 25 25 # $Log$ 26 # Revision 1.79 2004/11/15 22:01:34 jalet 27 # Improved banner handling. 28 # Fix for raw printing and banners. 29 # 26 30 # Revision 1.78 2004/11/15 19:59:34 jalet 27 31 # PyKota banners now basically work ! … … 526 530 self.printMoreInfo(user, printer, _("Job accounting ends.")) 527 531 528 # handle ending banner pages after accounting ends529 if accountbanner in ["STARTING", "NONE"] :530 banner = self.endingBanner(printer.Name)531 if banner :532 self.logdebug("Printing ending banner after accounting ends.")533 self.handleData(banner)534 535 532 # retrieve the job size 536 533 if action == "DENY" : … … 555 552 # then re-export user information with new value 556 553 self.exportUserInfo(userpquota) 554 555 # handle ending banner pages after accounting ends 556 if accountbanner in ["STARTING", "NONE"] : 557 banner = self.endingBanner(printer.Name) 558 if banner : 559 self.logdebug("Printing ending banner after accounting ends.") 560 self.handleData(banner) 557 561 558 562 # Launches the post hook … … 595 599 596 600 # And launch it 597 self.logdebug("Starting real backend %s with args %s" % (realbackend, " ".join(['"%s"' % a for a in ([os.environ["DEVICE_URI"]] + sys.argv[1:])]))) 598 subprocess = PyKotaPopen4([realbackend] + sys.argv[1:], bufsize=0, arg0=os.environ["DEVICE_URI"]) 601 if filehandle is None : 602 arguments = sys.argv 603 else : 604 # Here we absolutely WANT to remove any filename from the command line ! 605 arguments = [ "Fake this because we are printing a banner" ] + sys.argv[1:6] 606 self.logdebug("Starting real backend %s with args %s" % (realbackend, " ".join(['"%s"' % a for a in ([os.environ["DEVICE_URI"]] + arguments)]))) 607 subprocess = PyKotaPopen4([realbackend] + arguments, bufsize=0, arg0=os.environ["DEVICE_URI"]) 599 608 600 609 # Save file descriptors, we will need them later. -
pykota/trunk/bin/pkbanner
r1918 r1923 24 24 # 25 25 # $Log$ 26 # Revision 1.5 2004/11/15 22:01:34 jalet 27 # Improved banner handling. 28 # Fix for raw printing and banners. 29 # 26 30 # Revision 1.4 2004/11/15 19:59:34 jalet 27 31 # PyKota banners now basically work ! … … 41 45 import sys 42 46 import os 47 import time 43 48 import cStringIO 44 49 import popen2 … … 75 80 -h | --help Prints this message then exits. 76 81 77 ... TODO... 82 -d | --darkness d Sets the darkness to d%%. This can be used to 83 save toner. The default value is 100. 84 NOT IMPLEMENTED YET. 85 86 -p | --pagesize sz Sets sz as the page size. Most well known 87 page sizes are recognized, like 'A4' or 'Letter' 88 to name a few. 89 90 -l | --logo img Use the image as the banner's logo. The logo will 91 be drawn at the top center of the page. The default 92 logo is /usr/share/pykota/logos/pykota.jpeg 93 94 -u | --url u Uses u as an url to be written at the bottom of 95 the banner page. The default url is : 96 http://www.librelogiciel.com/software/ 78 97 79 98 examples : 80 99 81 ... TODO... 100 Using pkbanner directly from the command line is not recommended, 101 excepted for testing purposes. You should use pkbanner in the 102 'startingbanner' or 'endingbanner' directives in pykota.conf 103 104 For this reason, there's no example. 82 105 83 106 This program is free software; you can redistribute it and/or modify … … 101 124 primaryfields = [ 102 125 ("PRINTERNAME", N_("Printer")), 103 ("USERNAME", N_("User")),104 126 ("JOBID", N_("JobId")), 105 127 ("JOBORIGINATINGHOSTNAME", N_("Client host")), … … 135 157 pass 136 158 137 def genPDF(self, pagesize, logo, url) : 159 def getVar(self, varname) : 160 """Extracts a variable from the environment and returns its value or 'Unknown' in the current locale.""" 161 return os.environ.get(varname) or _("Unknown") 162 163 def printVar(self, canvas, x, y, label, value, size, darkness) : 164 """Outputs a variable onto the PDF canvas. 165 166 Returns the number of points to substract to current Y coordinate. 167 """ 168 canvas.saveState() 169 canvas.setFont("Helvetica-Bold", size) 170 (r, g, b) = (0, 0, 0) # Black : TODO : darkness 171 canvas.setFillColorRGB(r, g, b) 172 message = "%s :" % _(label).title() 173 canvas.drawRightString(x, y, message) 174 canvas.setFont("Courier-Bold", size) 175 (r, g, b) = (1, 0, 0) # Red : TODO : darkness 176 canvas.setFillColorRGB(r, g, b) 177 canvas.drawString(x + 0.5*cm, y, value) 178 canvas.restoreState() 179 return (size + 4) 180 181 def genPDF(self, pagesize, logo, url, darkness) : 138 182 """Generates the banner in PDF format, return the PDF document as a string.""" 183 139 184 document = cStringIO.StringIO() 140 185 c = canvas.Canvas(document, pagesize=pagesize, pageCompression=1) … … 148 193 149 194 ypos = pagesize[1] - (2 * cm) 150 try : 151 imglogo = PIL.Image.open(logo) 152 except : 153 self.printInfo("Unable to open image %s" % logo, "warn") 154 else : 155 (width, height) = imglogo.size 156 multi = float(width) / (8 * cm) 157 width = float(width) / multi 158 height = float(height) / multi 159 xpos = xcenter - (width / 2.0) 160 ypos -= height 161 c.drawImage(logo, xpos, ypos, width, height) 195 196 if logo : 197 try : 198 imglogo = PIL.Image.open(logo) 199 except : 200 self.printInfo("Unable to open image %s" % logo, "warn") 201 else : 202 (width, height) = imglogo.size 203 multi = float(width) / (8 * cm) 204 width = float(width) / multi 205 height = float(height) / multi 206 xpos = xcenter - (width / 2.0) 207 ypos -= height 208 c.drawImage(logo, xpos, ypos, width, height) 162 209 163 210 # New top … … 165 212 ypos -= (1 * cm) + 20 166 213 167 for fieldsgroup in [ self.primaryfields, self.secondaryfields, self.tertiaryfields] : 214 printername = self.getVar("PYKOTAPRINTERNAME") 215 username = self.getVar("PYKOTAUSERNAME") 216 accountbanner = self.config.getAccountBanner(printername) 217 218 # Outputs the username 219 ypos -= self.printVar(c, xcenter, ypos, _("Username"), username, 20, darkness) 220 221 # Printer and Job Id 222 job = "%s - %s" % (printername, self.getVar("PYKOTAJOBID")) 223 ypos -= self.printVar(c, xcenter, ypos, _("Job"), job, 14, darkness) 224 225 # Current date (TODO : at the time the banner was printed ! Change this to job's submission date) 226 datetime = time.strftime("%c", time.localtime()) 227 ypos -= self.printVar(c, xcenter, ypos, _("Date"), datetime, 14, darkness) 228 229 # Result of the print job 230 action = self.getVar("PYKOTAACTION") 231 if action == "ALLOW" : 232 action = _("Allowed") 233 elif action == "DENY" : 234 action = _("Denied") 235 elif action == "WARN" : 236 action = _("Allowed with Warning") 237 ypos -= self.printVar(c, xcenter, ypos, _("Result"), action, 14, darkness) 238 239 # skip some space 240 ypos -= 20 241 242 # Outputs title and filename 243 title = self.getVar("PYKOTATITLE") 244 ypos -= self.printVar(c, xcenter, ypos, _("Title"), title, 10, darkness) 245 246 filename = self.getVar("PYKOTAFILENAME") 247 ypos -= self.printVar(c, xcenter, ypos, _("Filename"), filename, 10, darkness) 248 249 # skip some space 250 ypos -= 20 251 252 # Now outputs the user's account balance or page counter 253 ypos -= self.printVar(c, xcenter, ypos, _("Pages printed on %s") % printername, self.getVar("PYKOTAPAGECOUNTER"), 14, darkness) 254 limitby = self.getVar("PYKOTALIMITBY") 255 if limitby == "balance" : 256 ypos -= self.printVar(c, xcenter, ypos, _("Account balance"), self.getVar("PYKOTABALANCE"), 14, darkness) 257 else : 258 ypos -= self.printVar(c, xcenter, ypos, _("Soft Limit"), self.getVar("PYKOTASOFTLIMIT"), 14, darkness) 259 ypos -= self.printVar(c, xcenter, ypos, _("Hard Limit"), self.getVar("PYKOTAHARDLIMIT"), 14, darkness) 260 ypos -= self.printVar(c, xcenter, ypos, _("Date Limit"), self.getVar("PYKOTADATELIMIT"), 14, darkness) 261 262 # URL 263 if url : 168 264 c.saveState() 169 for (varname, label) in fieldsgroup : 170 c.setFont("Helvetica-Bold", 14) 171 c.setFillColorRGB(0, 0, 0) 172 message = "%s :" % _(label).title() 173 c.drawRightString(xcenter, ypos, message) 174 c.setFont("Courier-Bold", 14) 175 c.setFillColorRGB(1, 0, 0) 176 c.drawString(xcenter + 0.5*cm, ypos, os.environ.get("PYKOTA%s" % varname, _("Unknown"))) 177 ypos -= 18 # next line 265 c.setFont("Courier-Bold", 16) 266 (r, g, b) = (0, 0, 1) # Blue : TODO : darkness 267 c.setFillColorRGB(r, g, b) 268 c.drawCentredString(xcenter, 2 * cm, url) 178 269 c.restoreState() 179 ypos -= 18 # skip an additionnal line180 181 # URL182 c.saveState()183 c.setFont("Courier-Bold", 16)184 c.setFillColorRGB(0, 0, 1)185 c.drawCentredString(xcenter, 2 * cm, url)186 c.restoreState()187 270 188 271 c.showPage() 189 272 c.save() 190 273 return document.getvalue() 191 274 192 275 def main(self, files, options) : 193 276 """Generates a banner.""" … … 197 280 raise PyKotaToolError, "The Python Imaging Library is missing. Download it from http://www.pythonware.com/downloads" 198 281 282 try : 283 darkness = int(options["darkness"]) 284 if (darkness <= 0) or (darkness > 100) : 285 raise ValueError, "Allowed range is (1..100)" 286 darkness /= 100.0 287 except (TypeError, ValueError), msg : 288 self.printInfo("Invalid darkness value %s : %s" % (options["darkness"], msg), "warn") 289 darkness = 1.0 290 199 291 pagesize = self.getPageSize(options["pagesize"]) 200 292 if pagesize is None : … … 203 295 204 296 self.logdebug("Generating the banner in PDF format...") 205 doc = self.genPDF(pagesize, options["logo"] , options["url"].strip())297 doc = self.genPDF(pagesize, options["logo"].strip(), options["url"].strip(), darkness) 206 298 207 299 self.logdebug("Converting the banner to PostScript...") … … 229 321 try : 230 322 defaults = { \ 323 "darkness" : "100", \ 231 324 "pagesize" : "a4", \ 232 325 "logo" : "/usr/share/pykota/logos/pykota.jpeg", 233 326 "url" : "http://www.librelogiciel.com/software/", 234 327 } 235 short_options = "vh l:p:u:"236 long_options = ["help", "version", " pagesize=", "logo=", "url="]328 short_options = "vhd:l:p:u:" 329 long_options = ["help", "version", "darkness=", "pagesize=", "logo=", "url="] 237 330 238 331 # Initializes the command line tool … … 245 338 options["help"] = options["h"] or options["help"] 246 339 options["version"] = options["v"] or options["version"] 340 options["darkness"] = options["d"] or options["darkness"] or defaults["darkness"] 247 341 options["pagesize"] = options["p"] or options["pagesize"] or defaults["pagesize"] 248 342 options["logo"] = options["l"] or options["logo"] or defaults["logo"] -
pykota/trunk/conf/pykota.conf.sample
r1915 r1923 638 638 # this command in a pipe through GhostScript if your printer doesn't 639 639 # accept PostScript as an input format. 640 # 641 # startingbanner: /usr/share/pykota/banner-page.sh 640 # NB : pkbanner's default page size is A4 641 # 642 # startingbanner: /usr/bin/pkbanner --pagesize=A4 --logo="/home/joe/mylogo.jpeg" --url="http://tech.example.com" 643 # startingbanner: /usr/bin/pkbanner 642 644 643 645 # EndingBanner : if defined will print a banner before the rest of the job … … 655 657 # this command in a pipe through GhostScript if your printer doesn't 656 658 # accept PostScript as an input format. 657 # 658 # endingbanner: /usr/share/pykota/banner-page.sh 659 # NB : pkbanner's default page size is A4 660 # 661 # endingbanner: /usr/bin/pkbanner --pagesize=A4 --logo="/home/joe/mylogo.jpeg" --url="http://tech.example.com" 662 # endingbanner: /usr/bin/pkbanner 659 663 660 664 # How should enforcement be done for this printer ? -
pykota/trunk/CREDITS
r1888 r1923 143 143 - Beda Szukics - Kantonsschule Obwalden - German translation 144 144 - Klaus Ade Johnstad - SkoleLinux - Norwegian Bokm�translation 145 - Matt Hyclak - Wrote the banner handling stuff. 145 146 146 147 ============================================================== -
pykota/trunk/NEWS
r1913 r1923 22 22 PyKota NEWS : 23 23 24 - 1.21alpha3 : 25 26 - PyKota can now generate its own banners, and either account 27 for them or not, depending on newly introduced directives 28 in pykota.conf 29 Thanks to Matt Hyclak for the patch. 30 24 31 - 1.21alpha2 : 25 32 -
pykota/trunk/pykota/tool.py
r1918 r1923 22 22 # 23 23 # $Log$ 24 # Revision 1.141 2004/11/15 22:01:34 jalet 25 # Improved banner handling. 26 # Fix for raw printing and banners. 27 # 24 28 # Revision 1.140 2004/11/15 19:59:34 jalet 25 29 # PyKota banners now basically work ! … … 626 630 def display_version_and_quit(self) : 627 631 """Displays version number, then exists successfully.""" 628 self.clean() 632 try : 633 self.clean() 634 except AttributeError : 635 pass 629 636 print version.__version__ 630 637 sys.exit(0) … … 632 639 def display_usage_and_quit(self) : 633 640 """Displays command line usage, then exists successfully.""" 634 self.clean() 641 try : 642 self.clean() 643 except AttributeError : 644 pass 635 645 print _(self.documentation) % (version.__version__, version.__author__) 636 646 sys.exit(0) -
pykota/trunk/pykota/version.py
r1905 r1923 22 22 # 23 23 24 __version__ = "1.21alpha 2_unofficial"24 __version__ = "1.21alpha3_unofficial" 25 25 26 26 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""