Changeset 3295
- Timestamp:
- 01/21/08 21:00:58 (17 years ago)
- Location:
- pykota/trunk
- Files:
-
- 1 removed
- 23 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/autopykota
r3294 r3295 30 30 31 31 from pykota.errors import PyKotaToolError, PyKotaCommandLineError 32 from pykota.tool import PyKotaTool , crashed, N_32 from pykota.tool import PyKotaTool 33 33 34 34 __doc__ = N_("""autopykota v%(__version__)s (c) %(__years__)s %(__author__)s -
pykota/trunk/bin/cupspykota
r3294 r3295 48 48 49 49 from pykota.errors import PyKotaToolError 50 from pykota.tool import PyKotaTool , crashed50 from pykota.tool import PyKotaTool 51 51 from pykota.accounter import openAccounter 52 52 from pykota import cups -
pykota/trunk/bin/dumpykota
r3294 r3295 28 28 29 29 from pykota.errors import PyKotaCommandLineError 30 from pykota.tool import crashed, N_31 30 from pykota.dumper import DumPyKota 32 31 -
pykota/trunk/bin/edpykota
r3294 r3295 28 28 29 29 from pykota.errors import PyKotaCommandLineError 30 from pykota.tool import Percent, PyKotaTool , crashed, N_30 from pykota.tool import Percent, PyKotaTool 31 31 from pykota.storage import StorageUserPQuota, StorageGroupPQuota 32 32 -
pykota/trunk/bin/pkbanner
r3294 r3295 48 48 49 49 from pykota.errors import PyKotaToolError, PyKotaCommandLineError 50 from pykota.tool import Tool , crashed, N_50 from pykota.tool import Tool 51 51 52 52 __doc__ = N_("""pkbanner v%(__version__)s (c) %(__years__)s %(__author__)s -
pykota/trunk/bin/pkbcodes
r3294 r3295 30 30 31 31 from pykota.errors import PyKotaCommandLineError 32 from pykota.tool import Percent, PyKotaTool , crashed, N_32 from pykota.tool import Percent, PyKotaTool 33 33 from pykota.storage import StorageBillingCode 34 34 -
pykota/trunk/bin/pkinvoice
r3294 r3295 48 48 49 49 from pykota.errors import PyKotaToolError, PyKotaCommandLineError 50 from pykota.tool import Percent, PyKotaTool , crashed, N_50 from pykota.tool import Percent, PyKotaTool 51 51 52 52 __doc__ = N_("""pkinvoice v%(__version__)s (c) %(__years__)s %(__author__)s -
pykota/trunk/bin/pkmail
r3294 r3295 35 35 36 36 from pykota.errors import PyKotaCommandLineError 37 from pykota.tool import PyKotaTool , crashed, N_37 from pykota.tool import PyKotaTool 38 38 39 39 __doc__ = N_("""pkmail v%(__version__)s (c) %(__years__)s %(__author__)s -
pykota/trunk/bin/pknotify
r3294 r3295 39 39 40 40 from pykota.errors import PyKotaToolError, PyKotaCommandLineError 41 from pykota.tool import Tool , crashed, N_41 from pykota.tool import Tool 42 42 43 43 __doc__ = N_("""pknotify v%(__version__)s (c) %(__years__)s %(__author__)s -
pykota/trunk/bin/pkprinters
r3294 r3295 30 30 31 31 from pykota.errors import PyKotaCommandLineError 32 from pykota.tool import Percent, PyKotaTool , crashed, N_32 from pykota.tool import Percent, PyKotaTool 33 33 from pykota.storage import StoragePrinter 34 34 -
pykota/trunk/bin/pkrefund
r3294 r3295 48 48 49 49 from pykota.errors import PyKotaToolError, PyKotaCommandLineError 50 from pykota.tool import Percent, PyKotaTool , crashed, N_50 from pykota.tool import Percent, PyKotaTool 51 51 52 52 __doc__ = N_("""pkrefund v%(__version__)s (c) %(__years__)s %(__author__)s -
pykota/trunk/bin/pkturnkey
r3294 r3295 33 33 34 34 from pykota.errors import PyKotaToolError, PyKotaCommandLineError 35 from pykota.tool import Tool , crashed, N_35 from pykota.tool import Tool 36 36 37 37 __doc__ = N_("""pkturnkey v%(__version__)s (c) %(__years__)s %(__author__)s -
pykota/trunk/bin/pkusers
r3294 r3295 30 30 31 31 from pykota.errors import PyKotaCommandLineError 32 from pykota.tool import Percent, PyKotaTool , crashed, N_32 from pykota.tool import Percent, PyKotaTool 33 33 from pykota.storage import StorageUser, StorageGroup 34 34 -
pykota/trunk/bin/pykosd
r3294 r3295 37 37 38 38 from pykota.errors import PyKotaToolError, PyKotaCommandLineError 39 from pykota.tool import PyKotaTool , crashed, N_39 from pykota.tool import PyKotaTool 40 40 41 41 __doc__ = N_("""pykosd v%(__version__)s (c) %(__years__)s %(__author__)s -
pykota/trunk/bin/pykotme
r3294 r3295 30 30 31 31 from pykota.errors import PyKotaCommandLineError 32 from pykota.tool import PyKotaTool , crashed, N_32 from pykota.tool import PyKotaTool 33 33 from pykota.accounter import openAccounter 34 34 -
pykota/trunk/bin/repykota
r3294 r3295 32 32 33 33 from pykota.errors import PyKotaToolError, PyKotaCommandLineError 34 from pykota.tool import PyKotaTool , crashed, N_34 from pykota.tool import PyKotaTool 35 35 from pykota import reporter 36 36 -
pykota/trunk/bin/warnpykota
r3294 r3295 30 30 31 31 from pykota.errors import PyKotaCommandLineError 32 from pykota.tool import PyKotaTool , crashed, N_32 from pykota.tool import PyKotaTool 33 33 34 34 __doc__ = N_("""warnpykota v%(__version__)s (c) %(__years__)s %(__author__)s -
pykota/trunk/cgi-bin/dumpykota.cgi
r3275 r3295 29 29 import urllib 30 30 31 from pykota import version 32 from pykota .tool import PyKotaToolError31 import pykota.appinit 32 from pykota import version, utils 33 33 from pykota.dumper import DumPyKota 34 from pykota.cgifuncs import getLanguagePreference, getCharsetPreference35 34 36 35 header = """Content-type: text/html;charset=%s … … 68 67 </head> 69 68 <body> 70 <!-- %s %s -->71 69 <p> 72 70 <form action="dumpykota.cgi" method="GET" name="mainform" onsubmit="return checkvalues()"> … … 123 121 """Displays the dumper interface.""" 124 122 global header, footer 125 print header % (self.charset, _("PyKota Data Dumper"), \ 126 self.language, self.charset, \ 123 content = [ header % (self.charset, _("PyKota Data Dumper"), \ 127 124 self.config.getLogoLink(), \ 128 125 self.config.getLogoURL(), version.__version__, \ 129 126 self.config.getLogoLink(), \ 130 127 version.__version__, _("PyKota Data Dumper"), \ 131 _("Dump"), _("Please click on the above button")) 132 print self.htmlListDataTypes(self.options.get("data", "")) 133 print "<br />" 134 print self.htmlListFormats(self.options.get("format", "")) 135 print "<br />" 136 print self.htmlFilterInput(" ".join(self.arguments)) 137 print "<br />" 138 print self.htmlOrderbyInput(self.options.get("orderby", "")) 139 print "<br />" 140 print self.htmlSumCheckbox(self.options.get("sum", "")) 141 print footer % (_("Dump"), version.__doc__, version.__years__, version.__author__, version.__gplblurb__) 128 _("Dump"), _("Please click on the above button")) ] 129 content.append(self.htmlListDataTypes(self.options.get("data", ""))) 130 content.append(u"<br />") 131 content.append(self.htmlListFormats(self.options.get("format", ""))) 132 content.append(u"<br />") 133 content.append(self.htmlFilterInput(" ".join(self.arguments))) 134 content.append(u"<br />") 135 content.append(self.htmlOrderbyInput(self.options.get("orderby", ""))) 136 content.append(u"<br />") 137 content.append(self.htmlSumCheckbox(self.options.get("sum", ""))) 138 content.append(footer % (_("Dump"), version.__doc__, version.__years__, version.__author__, version.__gplblurb__)) 139 for c in content : 140 sys.stdout.write(c.encode(self.charset, "replace")) 141 sys.stdout.flush() 142 142 143 143 def htmlListDataTypes(self, selected="") : … … 236 236 237 237 if __name__ == "__main__" : 238 admin = PyKotaDumperGUI(lang=getLanguagePreference(), charset=getCharsetPreference()) 238 utils.reinitcgilocale() 239 admin = PyKotaDumperGUI() 239 240 admin.deferredInit() 240 241 admin.form = cgi.FieldStorage() -
pykota/trunk/cgi-bin/printquota.cgi
r3275 r3295 31 31 from mx import DateTime 32 32 33 from pykota import version 34 from pykota.tool import PyKotaTool, PyKotaToolError 35 from pykota.reporter import PyKotaReporterError, openReporter 36 from pykota.cgifuncs import getLanguagePreference, getCharsetPreference 33 import pykota.appinit 34 35 from pykota import version, utils 36 from pykota.tool import PyKotaTool 37 from pykota.errors import PyKotaToolError, PyKotaReporterError 38 from pykota.reporter import openReporter 37 39 38 40 header = """Content-type: text/html;charset=%s … … 44 46 </head> 45 47 <body> 46 <!-- %s %s -->47 48 <p> 48 49 <form action="printquota.cgi" method="POST"> … … 96 97 """Displays the administrative interface.""" 97 98 global header, footer 98 print header % (self.charset, _("PyKota Reports"), \ 99 self.language, self.charset, \ 100 self.config.getLogoLink(), \ 101 self.config.getLogoURL(), version.__version__, \ 102 self.config.getLogoLink(), \ 103 version.__version__, _("PyKota Reports"), \ 104 _("Report")) 105 print self.body 106 print footer % (_("Report"), version.__doc__, version.__years__, version.__author__, version.__gplblurb__) 99 content = [ header % (self.charset, _("PyKota Reports"), \ 100 self.config.getLogoLink(), \ 101 self.config.getLogoURL(), version.__version__, \ 102 self.config.getLogoLink(), \ 103 version.__version__, _("PyKota Reports"), \ 104 _("Report")) ] 105 content.append(self.body) 106 content.append(footer % (_("Report"), version.__doc__, version.__years__, version.__author__, version.__gplblurb__)) 107 for c in content : 108 sys.stdout.write(c.encode(self.charset, "replace")) 109 sys.stdout.flush() 107 110 108 111 def error(self, message) : … … 287 290 288 291 if __name__ == "__main__" : 289 admin = PyKotaReportGUI(lang=getLanguagePreference(), charset=getCharsetPreference()) 292 utils.reinitcgilocale() 293 admin = PyKotaReportGUI() 290 294 admin.deferredInit() 291 295 admin.form = cgi.FieldStorage() -
pykota/trunk/cgi-bin/pykotme.cgi
r3275 r3295 30 30 import cStringIO 31 31 32 from pykota import version 33 from pykota.tool import PyKotaTool, PyKotaToolError 34 from pykota.cgifuncs import getLanguagePreference, getCharsetPreference 32 import pykota.appinit 33 34 from pykota import version, utils 35 from pykota.tool import PyKotaTool 36 from pykota.errors import PyKotaToolError 37 35 38 from pkpgpdls import analyzer, pdlparser 36 39 … … 44 47 </head> 45 48 <body> 46 <!-- %s %s -->47 49 <p> 48 50 <form action="pykotme.cgi" method="POST" enctype="multipart/form-data"> … … 96 98 """Displays the administrative interface.""" 97 99 global header, footer 98 print header % (self.charset, _("PyKota Quotes"), \ 99 self.language, self.charset, \ 100 content = [ header % (self.charset, _("PyKota Quotes"), \ 100 101 self.config.getLogoLink(), \ 101 102 self.config.getLogoURL(), version.__version__, \ 102 103 self.config.getLogoLink(), \ 103 104 version.__version__, _("PyKota Quotes"), \ 104 _("Quote")) 105 print self.body 106 print footer % (_("Quote"), version.__doc__, version.__years__, version.__author__, version.__gplblurb__) 105 _("Quote")) ] 106 content.append(self.body) 107 content.append(footer % (_("Quote"), version.__doc__, version.__years__, version.__author__, version.__gplblurb__)) 108 for c in content : 109 sys.stdout.write(c.encode(self.charset, "replace")) 110 sys.stdout.flush() 107 111 108 112 def error(self, message) : … … 187 191 188 192 if __name__ == "__main__" : 189 admin = PyKotMeGUI(lang=getLanguagePreference(), charset=getCharsetPreference()) 193 utils.reinitcgilocale() 194 admin = PyKotMeGUI() 190 195 admin.deferredInit() 191 196 admin.form = cgi.FieldStorage() -
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