Changeset 3298 for pykota/trunk
- Timestamp:
- 01/24/08 10:12:48 (16 years ago)
- Location:
- pykota/trunk
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r3295 r3298 435 435 self.Action = action 436 436 self.Reason = (reason or _("Print job cancelled.")) 437 os.environ["PYKOTASTATUS"] = "CANCELLED"437 setenv("PYKOTASTATUS", "CANCELLED", self.charset) 438 438 else : 439 439 # don't overwrite anything unless job authorized … … 530 530 """Exports the actual job's attributes to the environment.""" 531 531 self.logdebug("Exporting job information to the environment...") 532 os.environ["DEVICE_URI"] = self.DeviceURI # WARNING ! 533 os.environ["PYKOTAPRINTERNAME"] = self.PrinterName 534 os.environ["PYKOTADIRECTORY"] = self.Directory 535 os.environ["PYKOTADATAFILE"] = self.DataFile 536 os.environ["PYKOTAJOBSIZEBYTES"] = str(self.JobSizeBytes) 537 os.environ["PYKOTAMD5SUM"] = self.JobMD5Sum 538 os.environ["PYKOTAJOBORIGINATINGHOSTNAME"] = self.Ticket.OriginatingHostName or "" 539 os.environ["PYKOTAJOBID"] = self.Ticket.JobId 540 os.environ["PYKOTAUSERNAME"] = self.UserName 541 os.environ["PYKOTAORIGINALUSERNAME"] = self.Ticket.OriginalUserName 542 os.environ["PYKOTATITLE"] = self.Ticket.Title 543 os.environ["PYKOTACOPIES"] = str(self.Ticket.Copies) 544 os.environ["PYKOTAOPTIONS"] = self.Ticket.Options 545 os.environ["PYKOTAFILENAME"] = self.Ticket.FileName or "" 546 os.environ["PYKOTAJOBBILLING"] = self.Ticket.BillingCode or "" 547 os.environ["PYKOTAORIGINALJOBBILLING"] = self.OriginalJobBillingCode or "" 548 os.environ["PYKOTAPRINTERHOSTNAME"] = self.PrinterHostName 549 os.environ["PYKOTAPRECOMPUTEDJOBSIZE"] = str(self.softwareJobSize) 532 setenv("DEVICE_URI", self.DeviceURI, self.charset) # WARNING ! 533 setenv("PYKOTACHARSET", self.charset, self.charset) 534 setenv("PYKOTALANG", self.language, self.charset) 535 setenv("PYKOTAPRINTERNAME", self.PrinterName, self.charset) 536 setenv("PYKOTADIRECTORY", self.Directory, self.charset) 537 setenv("PYKOTADATAFILE", self.DataFile, self.charset) 538 setenv("PYKOTAJOBSIZEBYTES", str(self.JobSizeBytes), self.charset) 539 setenv("PYKOTAMD5SUM", self.JobMD5Sum, self.charset) 540 setenv("PYKOTAJOBORIGINATINGHOSTNAME", self.Ticket.OriginatingHostName or "", self.charset) 541 setenv("PYKOTAJOBID", self.Ticket.JobId, self.charset) 542 setenv("PYKOTAUSERNAME", self.UserName, self.charset) 543 setenv("PYKOTAORIGINALUSERNAME", self.Ticket.OriginalUserName, self.charset) 544 setenv("PYKOTATITLE", self.Ticket.Title, self.charset) 545 setenv("PYKOTACOPIES", str(self.Ticket.Copies), self.charset) 546 setenv("PYKOTAOPTIONS", self.Ticket.Options, self.charset) 547 setenv("PYKOTAFILENAME", self.Ticket.FileName or "", self.charset) 548 setenv("PYKOTAJOBBILLING", self.Ticket.BillingCode or "", self.charset) 549 setenv("PYKOTAORIGINALJOBBILLING", self.OriginalJobBillingCode or "", self.charset) 550 setenv("PYKOTAPRINTERHOSTNAME", self.PrinterHostName, self.charset) 551 setenv("PYKOTAPRECOMPUTEDJOBSIZE", str(self.softwareJobSize), self.charset) 550 552 self.logdebug("Environment updated.") 551 553 … … 553 555 """Exports user information to the environment.""" 554 556 self.logdebug("Exporting user information to the environment...") 555 os.environ["PYKOTAOVERCHARGE"] = str(self.User.OverCharge)556 os.environ["PYKOTALIMITBY"] = str(self.User.LimitBy)557 os.environ["PYKOTABALANCE"] = str(self.User.AccountBalance or 0.0)558 os.environ["PYKOTALIFETIMEPAID"] = str(self.User.LifeTimePaid or 0.0)559 os.environ["PYKOTAUSERDESCRIPTION"] = str(self.User.Description or "")560 561 os.environ["PYKOTAPAGECOUNTER"] = str(self.UserPQuota.PageCounter or 0)562 os.environ["PYKOTALIFEPAGECOUNTER"] = str(self.UserPQuota.LifePageCounter or 0)563 os.environ["PYKOTASOFTLIMIT"] = str(self.UserPQuota.SoftLimit)564 os.environ["PYKOTAHARDLIMIT"] = str(self.UserPQuota.HardLimit)565 os.environ["PYKOTADATELIMIT"] = str(self.UserPQuota.DateLimit)566 os.environ["PYKOTAWARNCOUNT"] = str(self.UserPQuota.WarnCount)557 setenv("PYKOTAOVERCHARGE", str(self.User.OverCharge), self.charset) 558 setenv("PYKOTALIMITBY", str(self.User.LimitBy), self.charset) 559 setenv("PYKOTABALANCE", str(self.User.AccountBalance or 0.0), self.charset) 560 setenv("PYKOTALIFETIMEPAID", str(self.User.LifeTimePaid or 0.0), self.charset) 561 setenv("PYKOTAUSERDESCRIPTION", str(self.User.Description or ""), self.charset) 562 563 setenv("PYKOTAPAGECOUNTER", str(self.UserPQuota.PageCounter or 0), self.charset) 564 setenv("PYKOTALIFEPAGECOUNTER", str(self.UserPQuota.LifePageCounter or 0), self.charset) 565 setenv("PYKOTASOFTLIMIT", str(self.UserPQuota.SoftLimit), self.charset) 566 setenv("PYKOTAHARDLIMIT", str(self.UserPQuota.HardLimit), self.charset) 567 setenv("PYKOTADATELIMIT", str(self.UserPQuota.DateLimit), self.charset) 568 setenv("PYKOTAWARNCOUNT", str(self.UserPQuota.WarnCount), self.charset) 567 569 568 570 # TODO : move this elsewhere once software accounting is done only once. 569 os.environ["PYKOTAPRECOMPUTEDJOBPRICE"] = str(self.softwareJobPrice)571 setenv("PYKOTAPRECOMPUTEDJOBPRICE", str(self.softwareJobPrice), self.charset) 570 572 571 573 self.logdebug("Environment updated.") … … 576 578 # exports the list of printers groups the current 577 579 # printer is a member of 578 os.environ["PYKOTAPGROUPS"] = ",".join([p.Name for p in self.storage.getParentPrinters(self.Printer)])579 os.environ["PYKOTAPRINTERDESCRIPTION"] = str(self.Printer.Description or "")580 os.environ["PYKOTAPRINTERMAXJOBSIZE"] = str(self.Printer.MaxJobSize or _("Unlimited"))581 os.environ["PYKOTAPRINTERPASSTHROUGHMODE"] = (self.Printer.PassThrough and _("ON")) or _("OFF")582 os.environ["PYKOTAPRICEPERPAGE"] = str(self.Printer.PricePerPage or 0)583 os.environ["PYKOTAPRICEPERJOB"] = str(self.Printer.PricePerJob or 0)580 setenv("PYKOTAPGROUPS", ",".join([p.Name for p in self.storage.getParentPrinters(self.Printer)]), self.charset) 581 setenv("PYKOTAPRINTERDESCRIPTION", str(self.Printer.Description or ""), self.charset) 582 setenv("PYKOTAPRINTERMAXJOBSIZE", str(self.Printer.MaxJobSize or _("Unlimited")), self.charset) 583 setenv("PYKOTAPRINTERPASSTHROUGHMODE", (self.Printer.PassThrough and _("ON")) or _("OFF"), self.charset) 584 setenv("PYKOTAPRICEPERPAGE", str(self.Printer.PricePerPage or 0), self.charset) 585 setenv("PYKOTAPRICEPERJOB", str(self.Printer.PricePerJob or 0), self.charset) 584 586 self.logdebug("Environment updated.") 585 587 … … 587 589 """Exports phase information to the environment.""" 588 590 self.logdebug("Exporting phase information [%s] to the environment..." % phase) 589 os.environ["PYKOTAPHASE"] = phase591 setenv("PYKOTAPHASE", phase, self.charset) 590 592 self.logdebug("Environment updated.") 591 593 … … 593 595 """Exports job's size and price information to the environment.""" 594 596 self.logdebug("Exporting job's size and price information to the environment...") 595 os.environ["PYKOTAJOBSIZE"] = str(self.JobSize)596 os.environ["PYKOTAJOBPRICE"] = str(self.JobPrice)597 setenv("PYKOTAJOBSIZE", str(self.JobSize), self.charset) 598 setenv("PYKOTAJOBPRICE", str(self.JobPrice), self.charset) 597 599 self.logdebug("Environment updated.") 598 600 … … 600 602 """Exports the job's action status and optional reason.""" 601 603 self.logdebug("Exporting job's action status...") 602 os.environ["PYKOTAACTION"] = str(self.Action)604 setenv("PYKOTAACTION", str(self.Action), self.charset) 603 605 if self.Reason : 604 os.environ["PYKOTAREASON"] = str(self.Reason)606 setenv("PYKOTAREASON", str(self.Reason), self.charset) 605 607 self.logdebug("Environment updated.") 606 608 … … 1078 1080 self.Action = "CANCEL" 1079 1081 self.Reason = _("Print job cancelled.") 1080 os.environ["PYKOTASTATUS"] = "CANCELLED"1082 setenv("PYKOTASTATUS", "CANCELLED", self.charset) 1081 1083 1082 1084 # exports some new environment variables … … 1253 1255 originalbackend = os.path.join(os.path.split(sys.argv[0])[0], self.RealBackend) 1254 1256 if not isBanner : 1255 arguments = [os.environ["DEVICE_URI"]] + sys.argv[1:]1257 arguments = [os.environ["DEVICE_URI"]] + [a.encode("UTF-8") for a in sys.argv[1:]] 1256 1258 else : 1257 1259 # For banners, we absolutely WANT 1258 1260 # to remove any filename from the command line ! 1259 1261 self.logdebug("It looks like we try to print a banner.") 1260 arguments = [os.environ["DEVICE_URI"]] + sys.argv[1:6]1262 arguments = [os.environ["DEVICE_URI"]] + [a.encode("UTF-8") for a in sys.argv[1:6]] 1261 1263 arguments[2] = self.UserName # in case it was overwritten by external script 1262 1264 # TODO : do something about job-billing option, in case it was overwritten as well... … … 1264 1266 # TODO : uses the job's title to name an output file (cups-pdf:// for example), we're stuck ! 1265 1267 1266 self.logdebug("Starting original backend %s with args %s" % (originalbackend, " ".join(['"%s"' % a for a in arguments])))1268 self.logdebug("Starting original backend %s with args %s" % (originalbackend, " ".join(['"%s"' % a.decode("UTF-8") for a in arguments]))) 1267 1269 pid = os.fork() 1268 1270 self.logdebug("Forked !") -
pykota/trunk/pykota/appinit.py
r3294 r3298 23 23 24 24 import sys 25 import os 25 26 import locale 26 27 import gettext … … 28 29 from pykota.utils import * 29 30 30 (lang, charset) = initlocale() 31 (lang, charset) = initlocale(os.environ.get("PYKOTALANG", ""), 32 os.environ.get("PYKOTACHARSET")) 31 33 initgettext(lang, charset) 32 34 -
pykota/trunk/pykota/tool.py
r3295 r3298 96 96 # Saves a copy of the locale settings 97 97 (self.language, self.charset) = locale.getlocale() 98 if not self.language : 99 self.language = "C" 98 100 if not self.charset : 99 101 self.charset = "UTF-8" … … 165 167 """Display a message but only if stdout is a tty.""" 166 168 if sys.stdout.isatty() : 167 sys.stdout.write(message.encode(s ys.stdout.encoding or "UTF-8", \169 sys.stdout.write(message.encode(self.charset, \ 168 170 "replace")) 169 171 sys.stdout.flush() … … 172 174 """Logs something to debug output if debug is enabled.""" 173 175 if self.debug : 174 self.logger.log_message(message.encode(sys.stdout.encoding \ 175 or "UTF-8", \ 176 self.logger.log_message(message.encode(self.charset, \ 176 177 "replace"), \ 177 178 "debug") … … 180 181 """Sends a message to standard error.""" 181 182 sys.stderr.write("%s: %s\n" % (level.upper(), \ 182 message.encode(sys.stdout.encoding \ 183 or "UTF-8", \ 183 message.encode(self.charset, \ 184 184 "replace"))) 185 185 sys.stderr.flush() -
pykota/trunk/pykota/utils.py
r3295 r3298 40 40 charset = sys.stdout.encoding or sys.getfilesystemencoding() 41 41 42 # Dirty hack : if the charset is ASCII, we can safely use UTF-8 instead 43 # This has the advantage of allowing transparent support for recent 44 # versions of CUPS which (en-)force charset to UTF-8 when printing. 45 # This should be needed only when printing, but is probably (?) safe 46 # to do when using interactive commands. 47 if charset.upper() in ('ASCII', 'ANSI_X3.4-1968') : 42 if (not charset) or charset in ("ASCII", "ANSI_X3.4-1968") : 48 43 charset = "UTF-8" 44 49 45 return (language, charset) 50 46 47 def setenv(varname, value, charset) : 48 """Sets an environment variable.""" 49 if value is None : 50 value = "None" 51 os.environ[varname] = value.encode(charset, "replace") 52 51 53 def initgettext(lang, cset) : 52 54 """Initializes gettext translations for PyKota.""" … … 86 88 87 89 def databaseToUnicode(text) : 88 """Converts from database format (UTF-8) to unicode.""" 90 """Converts from database format (UTF-8) to unicode. 91 92 We use "replace" to accomodate legacy datas which may not 93 have been recorded correctly. 94 """ 89 95 if text is not None : 90 96 return text.decode("UTF-8", "replace") … … 95 101 """Converts from unicode to database format (UTF-8).""" 96 102 if text is not None : 97 return text.encode("UTF-8" , "replace")103 return text.encode("UTF-8") 98 104 else : 99 105 return None … … 101 107 def logerr(text) : 102 108 """Logs an unicode text to stderr.""" 103 sys.stderr.write(text.encode(sys.stdout.encoding or locale.getlocale()[1], \ 109 sys.stderr.write(text.encode(sys.stdout.encoding \ 110 or locale.getlocale()[1] \ 111 or "ANSI_X3.4-1968", \ 104 112 "replace")) 105 113 sys.stderr.flush() -
pykota/trunk/pykota/version.py
r3275 r3298 22 22 """This module defines some application level constants.""" 23 23 24 __version__ = "1.27alpha 3_BROKEN_unofficial"24 __version__ = "1.27alpha4_unofficial" 25 25 26 26 __doc__ = "PyKota : a complete Printing Quota Solution for CUPS."