Changeset 3287
- Timestamp:
- 01/10/08 23:01:47 (17 years ago)
- Location:
- pykota/trunk
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pksetup
r3275 r3287 190 190 "python-imaging", 191 191 "python-pysnmp4", 192 "python-chardet",193 192 "python-pam" ] 194 193 -
pykota/trunk/checkdeps.py
r3275 r3287 81 81 ("Python-PAM", "PAM", "Python-PAM is recommended if you plan to use pknotify+PyKotIcon.\nGrab it from http://www.pangalactic.org/PyPAM/"), 82 82 ("Python-pkipplib", "pkipplib", "Python-pkipplib is now mandatory.\nGrab it from http://www.pykota.com/software/pkipplib/"), 83 ("Python-chardet", "chardet", "Python-chardet is recommended.\nGrab it from http://chardet.feedparser.org/"),84 83 ] 85 84 commandstocheck = [ ("GhostScript", "gs", "Depending on your configuration, GhostScript may be needed in different parts of PyKota."), -
pykota/trunk/debian/control
r3259 r3287 11 11 Architecture: all 12 12 Depends: python, python-egenix-mxdatetime, cupsys, python-pygresql | python-ldap | python-pysqlite2 | python-mysqldb, jaxml | python-jaxml, python-osd, python-reportlab, python-pysnmp4, python-imaging 13 Recommends: qa-assistant, snmp, netatalk, python-psyco, npadmin, python-pam , python-chardet13 Recommends: qa-assistant, snmp, netatalk, python-psyco, npadmin, python-pam 14 14 Description: Print Quota/Accounting system for CUPS 15 15 PyKota is a full featured, internationalized, centralized and extensible -
pykota/trunk/pykota/tool.py
r3286 r3287 39 39 from mx import DateTime 40 40 41 try :42 import chardet43 except ImportError :44 def detectCharset(text) :45 """Fakes a charset detection if the chardet module is not installed."""46 return "ISO-8859-15"47 else :48 def detectCharset(text) :49 """Uses the chardet module to workaround CUPS lying to us."""50 return chardet.detect(text)["encoding"] or "UTF-8"51 52 41 from pykota import config, storage, logger 53 42 from pykota.version import __version__, __author__, __years__, __gplblurb__ … … 63 52 Exception.__init__(self, message) 64 53 def __repr__(self): 65 return self.message 54 return self.message.encode(sys.stdout.encoding or "UTF-8", "replace") 66 55 __str__ = __repr__ 67 56 … … 142 131 self.charset = self.charset or locale.getpreferredencoding() 143 132 except locale.Error : 144 self.charset = sys. getfilesystemencoding()133 self.charset = sys.stdout.encoding or sys.getfilesystemencoding() 145 134 146 135 # Dirty hack : if the charset is ASCII, we can safely use UTF-8 instead … … 158 147 except TypeError : # Python <2.4 159 148 trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)]) 160 trans.install( )149 trans.install(unicode=True) 161 150 except : 162 gettext.NullTranslations().install( )151 gettext.NullTranslations().install(unicode=True) 163 152 164 153 # pykota specific stuff … … 215 204 if text is None : 216 205 return None 217 try : 218 return text.decode("UTF-8").encode(self.charset, "replace") 219 except (UnicodeError, AttributeError) : 220 try : 221 # Maybe already in Unicode ? 222 return text.encode(self.charset, "replace") 223 except (UnicodeError, AttributeError) : 224 # Try to autodetect the charset 225 return text.decode(detectCharset(text), "replace").encode(self.charset, "replace") 206 else : 207 return text.decode("UTF-8", "replace").encode(self.charset, "replace") 226 208 227 209 def userCharsetToUTF8(self, text) : … … 229 211 if text is None : 230 212 return None 231 try : 232 # We don't necessarily trust the default charset, because 233 # xprint sends us titles in UTF-8 but CUPS gives us an ISO-8859-1 charset ! 234 # So we first try to see if the text is already in UTF-8 or not, and 235 # if it is, we delete characters which can't be converted to the user's charset, 236 # then convert back to UTF-8. PostgreSQL 7.3.x used to reject some unicode characters, 237 # this is fixed by the ugly line below : 238 return text.decode("UTF-8").encode(self.charset, "replace").decode(self.charset).encode("UTF-8", "replace") 239 except (UnicodeError, AttributeError) : 240 try : 241 return text.decode(self.charset).encode("UTF-8", "replace") 242 except (UnicodeError, AttributeError) : 243 try : 244 # Maybe already in Unicode ? 245 return text.encode("UTF-8", "replace") 246 except (UnicodeError, AttributeError) : 247 # Try to autodetect the charset 248 return text.decode(detectCharset(text), "replace").encode("UTF-8", "replace") 249 return newtext 213 else : 214 return text.decode(self.charset, "replace").encode("UTF-8", "replace") 250 215 251 216 def display(self, message) : 252 217 """Display a message but only if stdout is a tty.""" 253 218 if sys.stdout.isatty() : 254 sys.stdout.write(message) 219 sys.stdout.write(message.encode(sys.stdout.encoding or "UTF-8", \ 220 "replace")) 255 221 sys.stdout.flush() 256 222 … … 258 224 """Logs something to debug output if debug is enabled.""" 259 225 if self.debug : 260 self.logger.log_message(message, "debug") 226 self.logger.log_message(message.encode(sys.stdout.encoding \ 227 or "UTF-8", \ 228 "replace"), \ 229 "debug") 261 230 262 231 def printInfo(self, message, level="info") : 263 232 """Sends a message to standard error.""" 264 sys.stderr.write("%s: %s\n" % (level.upper(), message)) 233 sys.stderr.write("%s: %s\n" % (level.upper(), \ 234 message.encode(sys.stdout.encoding \ 235 or "UTF-8", \ 236 "replace"))) 265 237 sys.stderr.flush() 266 238 -
pykota/trunk/qa-assistant/pykota.xml
r3212 r3287 172 172 </description> 173 173 </entry> 174 <entry name="python-chardet" display="true">175 <states>176 <state name="Pass">python-chardet is installed</state>177 <state name="Fail">python-chardet is not installed</state>178 <state name="Non-Blocker">Our system is correctly configured and up-to-date so PyKota won't need this module</state>179 </states>180 <description>181 python-chardet allows PyKota to automatically detect the character set used in a print job's textual information (like its title)182 in the case your system and/or installed release of CUPS doesn't produce UTF-8.183 It can also be useful when dumping incorrectly encoded database contents (because of the problem mentioned184 above).185 You can install it with 'apt-get install python-chardet'186 </description>187 </entry>188 174 <entry name="python-pam" display="true"> 189 175 <states> -
pykota/trunk/README
r3282 r3287 154 154 - The Python-OSD module to use the graphical print quota reminder. 155 155 (http://repose.cx/pyosd/) 156 - The Python-chardet module to autodetect user's character set when157 printing. (http://chardet.feedparser.org)158 156 - SNMP tools (specifically the snmpget command) if you prefer to 159 use your own script to request query printers. 157 use your own script to request query printers instead of PyKota's 158 internal SNMP handling facilities, which is not recommanded... 160 159 (http://www.net-snmp.org) 161 160 - Netatalk (specifically the pap command) if you plan to