Changeset 3298

Show
Ignore:
Timestamp:
01/24/08 10:12:48 (16 years ago)
Author:
jerome
Message:

It seems that the lead developer can eat his own food again...
More testing needs to be done but printing should now work again at
least with the PostgreSQL backend.

Location:
pykota/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r3295 r3298  
    435435                self.Action = action 
    436436                self.Reason = (reason or _("Print job cancelled.")) 
    437                 os.environ["PYKOTASTATUS"] = "CANCELLED" 
     437                setenv("PYKOTASTATUS", "CANCELLED", self.charset) 
    438438            else : 
    439439                # don't overwrite anything unless job authorized 
     
    530530        """Exports the actual job's attributes to the environment.""" 
    531531        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) 
    550552        self.logdebug("Environment updated.") 
    551553         
     
    553555        """Exports user information to the environment.""" 
    554556        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) 
    567569         
    568570        # 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) 
    570572         
    571573        self.logdebug("Environment updated.") 
     
    576578        # exports the list of printers groups the current 
    577579        # 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) 
    584586        self.logdebug("Environment updated.") 
    585587         
     
    587589        """Exports phase information to the environment.""" 
    588590        self.logdebug("Exporting phase information [%s] to the environment..." % phase) 
    589         os.environ["PYKOTAPHASE"] = phase 
     591        setenv("PYKOTAPHASE", phase, self.charset) 
    590592        self.logdebug("Environment updated.") 
    591593         
     
    593595        """Exports job's size and price information to the environment.""" 
    594596        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) 
    597599        self.logdebug("Environment updated.") 
    598600         
     
    600602        """Exports the job's action status and optional reason.""" 
    601603        self.logdebug("Exporting job's action status...") 
    602         os.environ["PYKOTAACTION"] = str(self.Action) 
     604        setenv("PYKOTAACTION", str(self.Action), self.charset) 
    603605        if self.Reason : 
    604             os.environ["PYKOTAREASON"] = str(self.Reason) 
     606            setenv("PYKOTAREASON", str(self.Reason), self.charset) 
    605607        self.logdebug("Environment updated.") 
    606608         
     
    10781080                self.Action = "CANCEL" 
    10791081                self.Reason = _("Print job cancelled.") 
    1080                 os.environ["PYKOTASTATUS"] = "CANCELLED" 
     1082                setenv("PYKOTASTATUS", "CANCELLED", self.charset) 
    10811083                 
    10821084        # exports some new environment variables 
     
    12531255        originalbackend = os.path.join(os.path.split(sys.argv[0])[0], self.RealBackend) 
    12541256        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:]] 
    12561258        else :     
    12571259            # For banners, we absolutely WANT 
    12581260            # to remove any filename from the command line ! 
    12591261            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]] 
    12611263        arguments[2] = self.UserName # in case it was overwritten by external script 
    12621264        # TODO : do something about job-billing option, in case it was overwritten as well... 
     
    12641266        # TODO : uses the job's title to name an output file (cups-pdf:// for example), we're stuck ! 
    12651267         
    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]))) 
    12671269        pid = os.fork() 
    12681270        self.logdebug("Forked !") 
  • pykota/trunk/pykota/appinit.py

    r3294 r3298  
    2323 
    2424import sys 
     25import os 
    2526import locale 
    2627import gettext 
     
    2829from pykota.utils import * 
    2930 
    30 (lang, charset) = initlocale() 
     31(lang, charset) = initlocale(os.environ.get("PYKOTALANG", ""), 
     32                             os.environ.get("PYKOTACHARSET")) 
    3133initgettext(lang, charset) 
    3234 
  • pykota/trunk/pykota/tool.py

    r3295 r3298  
    9696        # Saves a copy of the locale settings 
    9797        (self.language, self.charset) = locale.getlocale() 
     98        if not self.language : 
     99            self.language = "C" 
    98100        if not self.charset : 
    99101            self.charset = "UTF-8" 
     
    165167        """Display a message but only if stdout is a tty.""" 
    166168        if sys.stdout.isatty() : 
    167             sys.stdout.write(message.encode(sys.stdout.encoding or "UTF-8", \ 
     169            sys.stdout.write(message.encode(self.charset, \ 
    168170                                            "replace")) 
    169171            sys.stdout.flush() 
     
    172174        """Logs something to debug output if debug is enabled.""" 
    173175        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, \ 
    176177                                                   "replace"), \ 
    177178                                    "debug") 
     
    180181        """Sends a message to standard error.""" 
    181182        sys.stderr.write("%s: %s\n" % (level.upper(), \ 
    182                                        message.encode(sys.stdout.encoding \ 
    183                                                           or "UTF-8", \ 
     183                                       message.encode(self.charset, \ 
    184184                                                      "replace"))) 
    185185        sys.stderr.flush() 
  • pykota/trunk/pykota/utils.py

    r3295 r3298  
    4040        charset = sys.stdout.encoding or sys.getfilesystemencoding() 
    4141 
    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") : 
    4843        charset = "UTF-8" 
     44         
    4945    return (language, charset) 
    5046 
     47def 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     
    5153def initgettext(lang, cset) : 
    5254    """Initializes gettext translations for PyKota.""" 
     
    8688 
    8789def 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    """ 
    8995    if text is not None : 
    9096        return text.decode("UTF-8", "replace") 
     
    95101    """Converts from unicode to database format (UTF-8).""" 
    96102    if text is not None :  
    97         return text.encode("UTF-8", "replace") 
     103        return text.encode("UTF-8") 
    98104    else :     
    99105        return None 
     
    101107def logerr(text) : 
    102108    """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", \ 
    104112                                 "replace")) 
    105113    sys.stderr.flush() 
  • pykota/trunk/pykota/version.py

    r3275 r3298  
    2222"""This module defines some application level constants.""" 
    2323 
    24 __version__ = "1.27alpha3_BROKEN_unofficial" 
     24__version__ = "1.27alpha4_unofficial" 
    2525 
    2626__doc__ = "PyKota : a complete Printing Quota Solution for CUPS."