- Timestamp:
- 11/17/04 14:12:04 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pkbanner
r1926 r1934 24 24 # 25 25 # $Log$ 26 # Revision 1.8 2004/11/17 13:12:04 jalet 27 # Implemented the --savetoner command line option 28 # 26 29 # Revision 1.7 2004/11/15 22:29:01 jalet 27 30 # Moved title and filename to the left to free some space. … … 86 89 -h | --help Prints this message then exits. 87 90 88 -d | --darkness d Sets the darkness to d%%. This can be used to89 save toner. The default value is 100.90 NOT IMPLEMENTED YET.91 92 -p | --pagesize sz Sets sz as the page size. Most well known93 page sizes are recognized, like 'A4' or 'Letter'94 to name a few.95 96 91 -l | --logo img Use the image as the banner's logo. The logo will 97 92 be drawn at the top center of the page. The default 98 93 logo is /usr/share/pykota/logos/pykota.jpeg 99 94 95 -p | --pagesize sz Sets sz as the page size. Most well known 96 page sizes are recognized, like 'A4' or 'Letter' 97 to name a few. The default size is A4. 98 99 -s | --savetoner s Sets the text luminosity factor to d%%. This can be 100 used to save toner. The default value is 0, which 101 means that no toner saving will be done. 102 100 103 -u | --url u Uses u as an url to be written at the bottom of 101 104 the banner page. The default url is : … … 142 145 return os.environ.get(varname) or _("Unknown") 143 146 144 def printVar(self, canvas, x, y, label, value, size, darkness) :147 def printVar(self, canvas, x, y, label, value, size, savetoner) : 145 148 """Outputs a variable onto the PDF canvas. 146 149 … … 149 152 canvas.saveState() 150 153 canvas.setFont("Helvetica-Bold", size) 151 (r, g, b) = (0, 0, 0) # Black : TODO : darkness154 (r, g, b) = [ color + (savetoner * (1.0 - color)) for color in (0, 0, 0) ] # Black * savetoner 152 155 canvas.setFillColorRGB(r, g, b) 153 156 message = "%s :" % _(label) 154 157 canvas.drawRightString(x, y, message) 155 158 canvas.setFont("Courier-Bold", size) 156 (r, g, b) = (1, 0, 0) # Red : TODO : darkness159 (r, g, b) = [ color + (savetoner * (1.0 - color)) for color in (1, 0, 0) ] # Red * savetoner 157 160 canvas.setFillColorRGB(r, g, b) 158 161 canvas.drawString(x + 0.5*cm, y, value) … … 160 163 return (size + 4) 161 164 162 def genPDF(self, pagesize, logo, url, darkness) :165 def genPDF(self, pagesize, logo, url, savetoner) : 163 166 """Generates the banner in PDF format, return the PDF document as a string.""" 164 167 … … 198 201 199 202 # Outputs the username 200 ypos -= self.printVar(c, xcenter, ypos, _("Username"), username, 20, darkness)203 ypos -= self.printVar(c, xcenter, ypos, _("Username"), username, 20, savetoner) 201 204 202 205 # Printer and Job Id 203 206 job = "%s - %s" % (printername, self.getVar("PYKOTAJOBID")) 204 ypos -= self.printVar(c, xcenter, ypos, _("Job"), job, 14, darkness)207 ypos -= self.printVar(c, xcenter, ypos, _("Job"), job, 14, savetoner) 205 208 206 209 # Current date (TODO : at the time the banner was printed ! Change this to job's submission date) 207 210 datetime = time.strftime("%c", time.localtime()) 208 ypos -= self.printVar(c, xcenter, ypos, _("Date"), datetime, 14, darkness)211 ypos -= self.printVar(c, xcenter, ypos, _("Date"), datetime, 14, savetoner) 209 212 210 213 # Result of the print job … … 216 219 elif action == "WARN" : 217 220 action = _("Allowed with Warning") 218 ypos -= self.printVar(c, xcenter, ypos, _("Result"), action, 14, darkness)221 ypos -= self.printVar(c, xcenter, ypos, _("Result"), action, 14, savetoner) 219 222 220 223 # skip some space … … 224 227 # We put them at x=0.25*pagewidth so that the line is long enough to hold them 225 228 title = self.getVar("PYKOTATITLE") 226 ypos -= self.printVar(c, xcenter / 2.0, ypos, _("Title"), title, 10, darkness)229 ypos -= self.printVar(c, xcenter / 2.0, ypos, _("Title"), title, 10, savetoner) 227 230 228 231 filename = self.getVar("PYKOTAFILENAME") 229 ypos -= self.printVar(c, xcenter / 2.0, ypos, _("Filename"), filename, 10, darkness)232 ypos -= self.printVar(c, xcenter / 2.0, ypos, _("Filename"), filename, 10, savetoner) 230 233 231 234 # skip some space … … 233 236 234 237 # Now outputs the user's account balance or page counter 235 ypos -= self.printVar(c, xcenter, ypos, _("Pages printed so far on %s") % printername, self.getVar("PYKOTAPAGECOUNTER"), 14, darkness)238 ypos -= self.printVar(c, xcenter, ypos, _("Pages printed so far on %s") % printername, self.getVar("PYKOTAPAGECOUNTER"), 14, savetoner) 236 239 limitby = self.getVar("PYKOTALIMITBY") 237 240 if limitby == "balance" : 238 ypos -= self.printVar(c, xcenter, ypos, _("Account balance"), self.getVar("PYKOTABALANCE"), 14, darkness)241 ypos -= self.printVar(c, xcenter, ypos, _("Account balance"), self.getVar("PYKOTABALANCE"), 14, savetoner) 239 242 else : 240 ypos -= self.printVar(c, xcenter, ypos, _("Soft Limit"), self.getVar("PYKOTASOFTLIMIT"), 14, darkness)241 ypos -= self.printVar(c, xcenter, ypos, _("Hard Limit"), self.getVar("PYKOTAHARDLIMIT"), 14, darkness)242 ypos -= self.printVar(c, xcenter, ypos, _("Date Limit"), self.getVar("PYKOTADATELIMIT"), 14, darkness)243 ypos -= self.printVar(c, xcenter, ypos, _("Soft Limit"), self.getVar("PYKOTASOFTLIMIT"), 14, savetoner) 244 ypos -= self.printVar(c, xcenter, ypos, _("Hard Limit"), self.getVar("PYKOTAHARDLIMIT"), 14, savetoner) 245 ypos -= self.printVar(c, xcenter, ypos, _("Date Limit"), self.getVar("PYKOTADATELIMIT"), 14, savetoner) 243 246 244 247 # URL … … 246 249 c.saveState() 247 250 c.setFont("Courier-Bold", 16) 248 (r, g, b) = (0, 0, 1) # Blue : TODO : darkness251 (r, g, b) = [ color + (savetoner * (1.0 - color)) for color in (0, 0, 1) ] # Blue * savetoner 249 252 c.setFillColorRGB(r, g, b) 250 253 c.drawCentredString(xcenter, 2 * cm, url) … … 263 266 264 267 try : 265 darkness = int(options["darkness"])266 if ( darkness <= 0) or (darkness > 100) :267 raise ValueError, "Allowed range is (1..100)"268 darkness/= 100.0268 savetoner = int(options["savetoner"]) 269 if (savetoner < 0) or (savetoner > 99) : 270 raise ValueError, _("Allowed range is (0..99)") 271 savetoner /= 100.0 269 272 except (TypeError, ValueError), msg : 270 self.printInfo( "Invalid darkness value %s : %s" % (options["darkness"], msg), "warn")271 darkness = 1.0273 self.printInfo(_("Invalid 'savetoner' option %s : %s") % (options["savetoner"], msg), "warn") 274 savetoner = 0.0 272 275 273 276 pagesize = self.getPageSize(options["pagesize"]) 274 277 if pagesize is None : 275 278 pagesize = self.getPageSize("a4") 276 self.printInfo( "Unknown page size %s, defaulting to A4."% options["pagesize"], "warn")279 self.printInfo(_("Invalid 'pagesize' option %s, defaulting to A4.") % options["pagesize"], "warn") 277 280 278 281 self.logdebug("Generating the banner in PDF format...") 279 doc = self.genPDF(pagesize, options["logo"].strip(), options["url"].strip(), darkness)282 doc = self.genPDF(pagesize, options["logo"].strip(), options["url"].strip(), savetoner) 280 283 281 284 self.logdebug("Converting the banner to PostScript...") … … 294 297 return status 295 298 296 def getInfo(name) :297 """Extracts some information from the environment."""298 return os.environ.get(name, _("Unknown"))299 300 299 if __name__ == "__main__" : 301 300 # TODO : --papertray : to print banners on a different paper (colored for example) … … 303 302 try : 304 303 defaults = { \ 305 " darkness" : "100", \304 "savetoner" : "100", \ 306 305 "pagesize" : "a4", \ 307 306 "logo" : "/usr/share/pykota/logos/pykota.jpeg", 308 307 "url" : "http://www.librelogiciel.com/software/", 309 308 } 310 short_options = "vh d:l:p:u:"311 long_options = ["help", "version", " darkness=", "pagesize=", "logo=", "url="]309 short_options = "vhs:l:p:u:" 310 long_options = ["help", "version", "savetoner=", "pagesize=", "logo=", "url="] 312 311 313 312 # Initializes the command line tool … … 320 319 options["help"] = options["h"] or options["help"] 321 320 options["version"] = options["v"] or options["version"] 322 options[" darkness"] = options["d"] or options["darkness"] or defaults["darkness"]321 options["savetoner"] = options["s"] or options["savetoner"] or defaults["savetoner"] 323 322 options["pagesize"] = options["p"] or options["pagesize"] or defaults["pagesize"] 324 options["logo"] = options["l"] or options["logo"] or defaults["logo"]325 323 options["url"] = options["u"] or options["url"] or defaults["url"] 324 325 options["logo"] = options["l"] or options["logo"] 326 if options["logo"] is None : # Allows --logo="" to disable the logo entirely 327 options["logo"] = defaults["logo"] 326 328 327 329 if options["help"] :