Changeset 3298 for pykota/trunk/pykota

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/pykota
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • 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."