Changeset 3295 for pykota/trunk/pykota
- Timestamp:
- 01/21/08 21:00:58 (16 years ago)
- Location:
- pykota/trunk/pykota
- Files:
-
- 1 removed
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/dumper.py
r3291 r3295 39 39 hasJAXML = True 40 40 41 from pykota.utils import * 42 41 43 from pykota import version 42 from pykota.tool import PyKotaTool , N_44 from pykota.tool import PyKotaTool 43 45 from pykota.errors import PyKotaToolError, PyKotaCommandLineError 44 46 -
pykota/trunk/pykota/tool.py
r3294 r3295 38 38 from mx import DateTime 39 39 40 from pykota import utils 40 41 from pykota.errors import PyKotaCommandLineError 41 42 from pykota import config, storage, logger 42 43 from pykota.version import __version__, __author__, __years__, __gplblurb__ 43 44 def N_(message) :45 """Fake translation marker for translatable strings extraction."""46 return message47 48 def crashed(message="Bug in PyKota") :49 """Minimal crash method."""50 import traceback51 lines = []52 for line in traceback.format_exception(*sys.exc_info()) :53 lines.extend([l for l in line.split("\n") if l])54 msg = "ERROR: ".join(["%s\n" % l for l in (["ERROR: PyKota v%s" % __version__, message] + lines)])55 sys.stderr.write(msg)56 sys.stderr.flush()57 return msg58 44 59 45 class Percent : … … 103 89 class Tool : 104 90 """Base class for tools with no database access.""" 105 def __init__(self, lang="", charset=None,doc="PyKota v%(__version__)s (c) %(__years__)s %(__author__)s") :91 def __init__(self, doc="PyKota v%(__version__)s (c) %(__years__)s %(__author__)s") : 106 92 """Initializes the command line tool.""" 107 93 self.debug = True # in case of early failure … … 110 96 # Saves a copy of the locale settings 111 97 (self.language, self.charset) = locale.getlocale() 98 if not self.charset : 99 self.charset = "UTF-8" 112 100 113 101 # pykota specific stuff … … 247 235 def crashed(self, message="Bug in PyKota") : 248 236 """Outputs a crash message, and optionally sends it to software author.""" 249 msg = crashed(message)237 msg = utils.crashed(message) 250 238 fullmessage = "========== Traceback :\n\n%s\n\n========== sys.argv :\n\n%s\n\n========== Environment :\n\n%s\n" % \ 251 239 (msg, \ … … 347 335 class PyKotaTool(Tool) : 348 336 """Base class for all PyKota command line tools.""" 349 def __init__(self, lang="", charset=None, doc="PyKota v%(__version__)s (c) %(__years__)s %(__author__)s") :350 """Initializes the command line tool and opens the database."""351 Tool.__init__(self, lang, charset, doc)352 353 337 def deferredInit(self) : 354 338 """Deferred initialization.""" -
pykota/trunk/pykota/utils.py
r3294 r3295 23 23 24 24 import sys 25 import os 25 26 import locale 26 27 import gettext … … 63 64 except : 64 65 gettext.NullTranslations().install(unicode=True) 66 67 def getpreferredlanguage() : 68 """Returns the preferred language.""" 69 languages = os.environ.get("HTTP_ACCEPT_LANGUAGE", "") 70 langs = [l.strip().split(';')[0] for l in languages.split(",")] 71 return langs[0].replace("-", "_") 72 73 def getpreferredcharset() : 74 """Returns the preferred charset.""" 75 charsets = os.environ.get("HTTP_ACCEPT_CHARSET", "UTF-8") 76 charsets = [l.strip().split(';')[0] for l in charsets.split(",")] 77 return charsets[0] 78 79 def reinitcgilocale() : 80 """Reinitializes the locale and gettext translations for CGI scripts, according to browser's preferences.""" 81 initgettext(*initlocale(getpreferredlanguage(), getpreferredcharset())) 82 83 def N_(message) : 84 """Fake translation marker for translatable strings extraction.""" 85 return message 65 86 66 87 def databaseToUnicode(text) : … … 80 101 def logerr(text) : 81 102 """Logs an unicode text to stderr.""" 82 sys.stderr.write(text.encode(sys.stdout.encoding, "replace")) 103 sys.stderr.write(text.encode(sys.stdout.encoding or locale.getlocale()[1], \ 104 "replace")) 105 sys.stderr.flush() 83 106 107 def crashed(message="Bug in PyKota") : 108 """Minimal crash method.""" 109 import traceback 110 from pykota.version import __version__ 111 lines = [] 112 for line in traceback.format_exception(*sys.exc_info()) : 113 lines.extend([l for l in line.split("\n") if l]) 114 msg = "ERROR: ".join(["%s\n" % l for l in (["ERROR: PyKota v%s" % __version__, message] + lines)]) 115 logerr(msg) 116 return msg