Changeset 3294
- Timestamp:
- 01/18/08 23:39:41 (16 years ago)
- Location:
- pykota/trunk
- Files:
-
- 1 added
- 25 modified
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/autopykota
r3288 r3294 25 25 import sys 26 26 import os 27 28 import pykota.appinit 29 from pykota.utils import * 27 30 28 31 from pykota.errors import PyKotaToolError, PyKotaCommandLineError … … 140 143 retcode = automat.main(args, options) 141 144 except KeyboardInterrupt : 142 sys.stderr.write("\nInterrupted with Ctrl+C !\n")145 logerr("\nInterrupted with Ctrl+C !\n") 143 146 retcode = -3 144 147 except PyKotaCommandLineError, msg : 145 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))148 logerr("%s : %s\n" % (sys.argv[0], msg)) 146 149 retcode = -2 147 150 except SystemExit : -
pykota/trunk/bin/cupspykota
r3288 r3294 43 43 44 44 from mx import DateTime 45 46 import pykota.appinit 47 from pykota.utils import * 45 48 46 49 from pykota.errors import PyKotaToolError … … 1313 1316 sys.exit(0) 1314 1317 elif len(sys.argv) not in (6, 7) : 1315 sys.stderr.write("ERROR: %s job-id user title copies options [file]\n"\1318 logerr("ERROR: %s job-id user title copies options [file]\n"\ 1316 1319 % sys.argv[0]) 1317 1320 sys.exit(1) -
pykota/trunk/bin/dumpykota
r3288 r3294 23 23 24 24 import sys 25 26 import pykota.appinit 27 from pykota.utils import * 25 28 26 29 from pykota.errors import PyKotaCommandLineError … … 183 186 retcode = dumper.main(args, options) 184 187 except KeyboardInterrupt : 185 sys.stderr.write("\nInterrupted with Ctrl+C !\n")188 logerr("\nInterrupted with Ctrl+C !\n") 186 189 retcode = -3 187 190 except PyKotaCommandLineError, msg : 188 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))191 logerr("%s : %s\n" % (sys.argv[0], msg)) 189 192 retcode = -2 190 193 except SystemExit : -
pykota/trunk/bin/edpykota
r3288 r3294 23 23 24 24 import sys 25 26 import pykota.appinit 27 from pykota.utils import * 25 28 26 29 from pykota.errors import PyKotaCommandLineError … … 352 355 retcode = manager.main(args, options) 353 356 except KeyboardInterrupt : 354 sys.stderr.write("\nInterrupted with Ctrl+C !\n")357 logerr("\nInterrupted with Ctrl+C !\n") 355 358 retcode = -3 356 359 except PyKotaCommandLineError, msg : 357 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))360 logerr("%s : %s\n" % (sys.argv[0], msg)) 358 361 retcode = -2 359 362 except SystemExit : -
pykota/trunk/bin/pkbanner
r3288 r3294 44 44 hasPIL = True 45 45 46 import pykota.appinit 47 from pykota.utils import * 48 46 49 from pykota.errors import PyKotaToolError, PyKotaCommandLineError 47 50 from pykota.tool import Tool, crashed, N_ … … 325 328 retcode = banner.main(args, options) 326 329 except KeyboardInterrupt : 327 sys.stderr.write("\nInterrupted with Ctrl+C !\n")330 logerr("\nInterrupted with Ctrl+C !\n") 328 331 retcode = -3 329 332 except PyKotaCommandLineError, msg : 330 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))333 logerr("%s : %s\n" % (sys.argv[0], msg)) 331 334 retcode = -2 332 335 except SystemExit : -
pykota/trunk/bin/pkbcodes
r3288 r3294 25 25 import sys 26 26 import pwd 27 28 import pykota.appinit 29 from pykota.utils import * 27 30 28 31 from pykota.errors import PyKotaCommandLineError … … 199 202 retcode = manager.main(args, options) 200 203 except KeyboardInterrupt : 201 sys.stderr.write("\nInterrupted with Ctrl+C !\n")204 logerr("\nInterrupted with Ctrl+C !\n") 202 205 retcode = -3 203 206 except PyKotaCommandLineError, msg : 204 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))207 logerr("%s : %s\n" % (sys.argv[0], msg)) 205 208 retcode = -2 206 209 except SystemExit : -
pykota/trunk/bin/pkinvoice
r3288 r3294 43 43 else : 44 44 hasPIL = True 45 46 import pykota.appinit 47 from pykota.utils import * 45 48 46 49 from pykota.errors import PyKotaToolError, PyKotaCommandLineError … … 403 406 retcode = invoiceGenerator.main(args, options) 404 407 except KeyboardInterrupt : 405 sys.stderr.write("\nInterrupted with Ctrl+C !\n")408 logerr("\nInterrupted with Ctrl+C !\n") 406 409 retcode = -3 407 410 except PyKotaCommandLineError, msg : 408 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))411 logerr("%s : %s\n" % (sys.argv[0], msg)) 409 412 retcode = -2 410 413 except SystemExit : -
pykota/trunk/bin/pkmail
r3288 r3294 30 30 from email.Header import Header 31 31 import email.Utils 32 33 import pykota.appinit 34 from pykota.utils import * 32 35 33 36 from pykota.errors import PyKotaCommandLineError … … 164 167 retcode = mailparser.main(args, options) 165 168 except KeyboardInterrupt : 166 sys.stderr.write("\nInterrupted with Ctrl+C !\n")169 logerr("\nInterrupted with Ctrl+C !\n") 167 170 retcode = -3 168 171 except PyKotaCommandLineError, msg : 169 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))172 logerr("%s : %s\n" % (sys.argv[0], msg)) 170 173 retcode = -2 171 174 except SystemExit : -
pykota/trunk/bin/pknotify
r3288 r3294 34 34 else : 35 35 hasPAM = True 36 37 import pykota.appinit 38 from pykota.utils import * 36 39 37 40 from pykota.errors import PyKotaToolError, PyKotaCommandLineError … … 354 357 retcode = notifier.main(args, options) 355 358 except KeyboardInterrupt : 356 sys.stderr.write("\nInterrupted with Ctrl+C !\n")359 logerr("\nInterrupted with Ctrl+C !\n") 357 360 retcode = -3 358 361 except PyKotaCommandLineError, msg : 359 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))362 logerr("%s : %s\n" % (sys.argv[0], msg)) 360 363 print "CANCEL" # Forces the cancellation of the print job if a command line switch is incorrect 361 364 retcode = -2 -
pykota/trunk/bin/pkprinters
r3288 r3294 25 25 import sys 26 26 import pwd 27 28 import pykota.appinit 29 from pykota.utils import * 27 30 28 31 from pykota.errors import PyKotaCommandLineError … … 372 375 retcode = manager.main(args, options) 373 376 except KeyboardInterrupt : 374 sys.stderr.write("\nInterrupted with Ctrl+C !\n")377 logerr("\nInterrupted with Ctrl+C !\n") 375 378 retcode = -3 376 379 except PyKotaCommandLineError, msg : 377 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))380 logerr("%s : %s\n" % (sys.argv[0], msg)) 378 381 retcode = -2 379 382 except SystemExit : -
pykota/trunk/bin/pkrefund
r3288 r3294 43 43 else : 44 44 hasPIL = True 45 46 import pykota.appinit 47 from pykota.utils import * 45 48 46 49 from pykota.errors import PyKotaToolError, PyKotaCommandLineError … … 440 443 retcode = refundmanager.main(args, options) 441 444 except KeyboardInterrupt : 442 sys.stderr.write("\nInterrupted with Ctrl+C !\n")445 logerr("\nInterrupted with Ctrl+C !\n") 443 446 retcode = -3 444 447 except PyKotaCommandLineError, msg : 445 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))448 logerr("%s : %s\n" % (sys.argv[0], msg)) 446 449 retcode = -2 447 450 except SystemExit : -
pykota/trunk/bin/pksetup
r3290 r3294 408 408 homedirectory = self.addPyKotaUser() 409 409 if homedirectory is None : 410 sys.stderr.write("Installation can't proceed. You MUST create a system user named 'pykota'.\n")410 logerr("Installation can't proceed. You MUST create a system user named 'pykota'.\n") 411 411 else : 412 412 self.upgradeSystem() … … 465 465 installer = globals()[classname]() 466 466 except KeyError : 467 sys.stderr.write("There's currently no support for the %s distribution, sorry.\n" % sys.argv[1])467 logerr("There's currently no support for the %s distribution, sorry.\n" % sys.argv[1]) 468 468 retcode = -1 469 469 else : … … 471 471 retcode = installer.setup() 472 472 except KeyboardInterrupt : 473 sys.stderr.write("\n\n\nWARNING : Setup was aborted at user's request !\n\n")473 logerr("\n\n\nWARNING : Setup was aborted at user's request !\n\n") 474 474 retcode = -1 475 475 sys.exit(retcode) -
pykota/trunk/bin/pkturnkey
r3288 r3294 29 29 import signal 30 30 31 import pykota.appinit 32 from pykota.utils import * 33 31 34 from pykota.errors import PyKotaToolError, PyKotaCommandLineError 32 35 from pykota.tool import Tool, crashed, N_ … … 226 229 from pysnmp.proto.api import alpha 227 230 except ImportError : 228 sys.stderr.write("pysnmp doesn't seem to be installed. SNMP checks will be ignored !\n")231 logerr("pysnmp doesn't seem to be installed. SNMP checks will be ignored !\n") 229 232 return 0 230 233 else : … … 528 531 retcode = manager.main(args, options) 529 532 except KeyboardInterrupt : 530 sys.stderr.write("\nInterrupted with Ctrl+C !\n")533 logerr("\nInterrupted with Ctrl+C !\n") 531 534 retcode = -3 532 535 except PyKotaCommandLineError, msg : 533 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))536 logerr("%s : %s\n" % (sys.argv[0], msg)) 534 537 retcode = -2 535 538 except SystemExit : -
pykota/trunk/bin/pkusers
r3288 r3294 25 25 import pwd 26 26 import grp 27 28 import pykota.appinit 29 from pykota.utils import * 27 30 28 31 from pykota.errors import PyKotaCommandLineError … … 440 443 retcode = manager.main(args, options) 441 444 except KeyboardInterrupt : 442 sys.stderr.write("\nInterrupted with Ctrl+C !\n")445 logerr("\nInterrupted with Ctrl+C !\n") 443 446 retcode = -3 444 447 except PyKotaCommandLineError, msg : 445 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))448 logerr("%s : %s\n" % (sys.argv[0], msg)) 446 449 retcode = -2 447 450 except SystemExit : -
pykota/trunk/bin/pykosd
r3288 r3294 30 30 import pyosd 31 31 except ImportError : 32 sys.stderr.write("Sorry ! You need both xosd and the Python OSD library (pyosd) for this software to work.\n")32 logerr("Sorry ! You need both xosd and the Python OSD library (pyosd) for this software to work.\n") 33 33 sys.exit(-1) 34 35 import pykota.appinit 36 from pykota.utils import * 34 37 35 38 from pykota.errors import PyKotaToolError, PyKotaCommandLineError … … 192 195 retcode = 0 193 196 except KeyboardInterrupt : 194 sys.stderr.write("\nInterrupted with Ctrl+C !\n")197 logerr("\nInterrupted with Ctrl+C !\n") 195 198 retcode = -3 196 199 except PyKotaCommandLineError, msg : 197 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))200 logerr("%s : %s\n" % (sys.argv[0], msg)) 198 201 retcode = -2 199 202 except SystemExit : -
pykota/trunk/bin/pykotme
r3288 r3294 25 25 import os 26 26 import pwd 27 28 import pykota.appinit 29 from pykota.utils import * 27 30 28 31 from pykota.errors import PyKotaCommandLineError … … 156 159 retcode = sender.main(args, options) 157 160 except KeyboardInterrupt : 158 sys.stderr.write("\nInterrupted with Ctrl+C !\n")161 logerr("\nInterrupted with Ctrl+C !\n") 159 162 retcode = -3 160 163 except PyKotaCommandLineError, msg : 161 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))164 logerr("%s : %s\n" % (sys.argv[0], msg)) 162 165 retcode = -2 163 166 except SystemExit : -
pykota/trunk/bin/repykota
r3288 r3294 27 27 28 28 from mx import DateTime 29 30 import pykota.appinit 31 from pykota.utils import * 29 32 30 33 from pykota.errors import PyKotaToolError, PyKotaCommandLineError … … 157 160 retcode = reportTool.main(args, options) 158 161 except KeyboardInterrupt : 159 sys.stderr.write("\nInterrupted with Ctrl+C !\n")162 logerr("\nInterrupted with Ctrl+C !\n") 160 163 retcode = -3 161 164 except PyKotaCommandLineError, msg : 162 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))165 logerr("%s : %s\n" % (sys.argv[0], msg)) 163 166 retcode = -2 164 167 except SystemExit : -
pykota/trunk/bin/warnpykota
r3288 r3294 25 25 import os 26 26 import pwd 27 28 import pykota.appinit 29 from pykota.utils import * 27 30 28 31 from pykota.errors import PyKotaCommandLineError … … 156 159 retcode = sender.main(args, options) 157 160 except KeyboardInterrupt : 158 sys.stderr.write("\nInterrupted with Ctrl+C !\n")161 logerr("\nInterrupted with Ctrl+C !\n") 159 162 retcode = -3 160 163 except PyKotaCommandLineError, msg : 161 sys.stderr.write("%s : %s\n" % (sys.argv[0], msg))164 logerr("%s : %s\n" % (sys.argv[0], msg)) 162 165 retcode = -2 163 166 except SystemExit : -
pykota/trunk/pykota/storage.py
r3291 r3294 581 581 self.close() 582 582 583 def querydebug(self, qmsg) : 584 """Logs a database query, where all queries are already UTF-8 encoded.""" 585 self.tool.logdebug(qmsg.decode("UTF-8", "replace")) 586 583 587 def getFromCache(self, cachetype, key) : 584 588 """Tries to extract something from the cache.""" … … 728 732 return gpquotas 729 733 730 def databaseToUnicode(self, text) :731 """Converts from database format (UTF-8) to unicode."""732 if text is not None :733 return text.decode("UTF-8", "replace")734 else :735 return None736 737 def unicodeToDatabase(self, text) :738 """Converts from unicode to database format (UTF-8)."""739 if text is not None :740 return text.encode("UTF-8", "replace")741 else :742 return None743 744 734 def cleanDates(self, startdate, enddate) : 745 735 """Clean the dates to create a correct filter.""" -
pykota/trunk/pykota/storages/ldapstorage.py
r3291 r3294 42 42 StorageJob, StorageLastJob, StorageUserPQuota, \ 43 43 StorageGroupPQuota, StorageBillingCode 44 45 from pykota.utils import * 44 46 45 47 try : … … 160 162 result = [(base, entry)] 161 163 else : 162 self. tool.logdebug("QUERY : Filter : %s, BaseDN : %s, Scope : %s, Attributes : %s" % (key, base, scope, fields))164 self.querydebug("QUERY : Filter : %s, BaseDN : %s, Scope : %s, Attributes : %s" % (key, base, scope, fields)) 163 165 result = self.database.search_s(base, scope, key, fields) 164 166 except ldap.NO_SUCH_OBJECT, msg : … … 171 173 self.secondStageInit() 172 174 else : 173 self. tool.logdebug("QUERY : Result : %s" % result)175 self.querydebug("QUERY : Result : %s" % result) 174 176 result = [ (dn, cidict(attrs)) for (dn, attrs) in result ] 175 177 if self.useldapcache : 176 178 for (dn, attributes) in result : 177 self. tool.logdebug("LDAP cache store %s => %s" % (dn, attributes))179 self.querydebug("LDAP cache store %s => %s" % (dn, attributes)) 178 180 self.ldapcache[dn] = attributes 179 181 return result … … 186 188 for tryit in range(3) : 187 189 try : 188 self. tool.logdebug("QUERY : ADD(%s, %s)" % (dn, str(fields)))190 self.querydebug("QUERY : ADD(%s, %s)" % (dn, fields)) 189 191 entry = ldap.modlist.addModlist(fields) 190 self. tool.logdebug("%s" % entry)192 self.querydebug("%s" % entry) 191 193 self.database.add_s(dn, entry) 192 194 except ldap.ALREADY_EXISTS, msg : … … 200 202 else : 201 203 if self.useldapcache : 202 self. tool.logdebug("LDAP cache add %s => %s" % (dn, fields))204 self.querydebug("LDAP cache add %s => %s" % (dn, fields)) 203 205 self.ldapcache[dn] = fields 204 206 return dn … … 210 212 for tryit in range(3) : 211 213 try : 212 self. tool.logdebug("QUERY : Delete(%s)" % dn)214 self.querydebug("QUERY : Delete(%s)" % dn) 213 215 self.database.delete_s(dn) 214 216 except ldap.NO_SUCH_OBJECT : … … 223 225 if self.useldapcache : 224 226 try : 225 self. tool.logdebug("LDAP cache del %s" % dn)227 self.querydebug("LDAP cache del %s" % dn) 226 228 del self.ldapcache[dn] 227 229 except KeyError : … … 239 241 if self.ldapcache.has_key(dn) : 240 242 old = self.ldapcache[dn] 241 self. tool.logdebug("LDAP cache hit %s => %s" % (dn, old))243 self.querydebug("LDAP cache hit %s => %s" % (dn, old)) 242 244 oldentry = {} 243 245 for (k, v) in old.items() : … … 245 247 oldentry[k] = v 246 248 else : 247 self. tool.logdebug("LDAP cache miss %s" % dn)249 self.querydebug("LDAP cache miss %s" % dn) 248 250 oldentry = self.doSearch("objectClass=*", base=dn, scope=ldap.SCOPE_BASE)[0][1] 249 251 else : … … 254 256 oldvalue = v["convert"](oldentry.get(k, [0])[0]) 255 257 except ValueError : 256 self. tool.logdebug("Error converting %s with %s(%s)" % (oldentry.get(k), k, v))258 self.querydebug("Error converting %s with %s(%s)" % (oldentry.get(k), k, v)) 257 259 oldvalue = 0 258 260 if v["operator"] == '+' : … … 262 264 fields[k] = str(newvalue) 263 265 fields = self.normalizeFields(fields) 264 self. tool.logdebug("QUERY : Modify(%s, %s ==> %s)" % (dn, oldentry, fields))266 self.querydebug("QUERY : Modify(%s, %s ==> %s)" % (dn, oldentry, fields)) 265 267 entry = ldap.modlist.modifyModlist(oldentry, fields, ignore_oldexistent=ignoreold) 266 268 modentry = [] … … 268 270 if mtyp and (mtyp.lower() != "createtimestamp") : 269 271 modentry.append((mop, mtyp, mval)) 270 self. tool.logdebug("MODIFY : %s ==> %s ==> %s" % (fields, entry, modentry))272 self.querydebug("MODIFY : %s ==> %s ==> %s" % (fields, entry, modentry)) 271 273 if modentry : 272 274 self.database.modify_s(dn, modentry) … … 288 290 except KeyError : 289 291 pass 290 self. tool.logdebug("LDAP cache update %s => %s" % (dn, cachedentry))292 self.querydebug("LDAP cache update %s => %s" % (dn, cachedentry)) 291 293 return dn 292 294 raise PyKotaStorageError, message … … 303 305 self.tool.printInfo("Object %s has no %s attribute !" % (dn, attribute), "error") 304 306 else : 305 attrval = self.databaseToUnicode(attrval)307 attrval = databaseToUnicode(attrval) 306 308 if patterns : 307 309 if (not isinstance(patterns, type([]))) and (not isinstance(patterns, type(()))) : … … 318 320 result = self.doSearch(ldapfilter, ["pykotaBillingCode"], base=self.info["billingcodebase"]) 319 321 if result : 320 return [ self.databaseToUnicode(bc) for bc in self.filterNames(result, "pykotaBillingCode", billingcode)]322 return [databaseToUnicode(bc) for bc in self.filterNames(result, "pykotaBillingCode", billingcode)] 321 323 else : 322 324 return [] … … 351 353 def getUserNbJobsFromHistory(self, user) : 352 354 """Returns the number of jobs the user has in history.""" 353 result = self.doSearch("(&(pykotaUserName=%s)(objectClass=pykotaJob))" % self.unicodeToDatabase(user.Name), None, base=self.info["jobbase"])355 result = self.doSearch("(&(pykotaUserName=%s)(objectClass=pykotaJob))" % unicodeToDatabase(user.Name), None, base=self.info["jobbase"]) 354 356 return len(result) 355 357 … … 357 359 """Extracts user information given its name.""" 358 360 user = StorageUser(self, username) 359 username = self.unicodeToDatabase(username)361 username = unicodeToDatabase(username) 360 362 result = self.doSearch("(&(objectClass=pykotaAccount)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["userrdn"], username), ["pykotaUserName", "pykotaLimitBy", self.info["usermail"], "description"], base=self.info["userbase"]) 361 363 if result : 362 364 fields = result[0][1] 363 365 user.ident = result[0][0] 364 user.Description = self.databaseToUnicode(fields.get("description", [None])[0])366 user.Description = databaseToUnicode(fields.get("description", [None])[0]) 365 367 user.Email = fields.get(self.info["usermail"], [None])[0] 366 368 user.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] … … 395 397 description = "" 396 398 else : 397 description = self.databaseToUnicode(base64.decodestring(description))399 description = databaseToUnicode(base64.decodestring(description)) 398 400 if amount.endswith(" #") : 399 401 amount = amount[:-2] # TODO : should be catched earlier, the bug is above I think … … 405 407 """Extracts group information given its name.""" 406 408 group = StorageGroup(self, groupname) 407 groupname = self.unicodeToDatabase(groupname)409 groupname = unicodeToDatabase(groupname) 408 410 result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % (groupname, self.info["grouprdn"], groupname), ["pykotaGroupName", "pykotaLimitBy", "description"], base=self.info["groupbase"]) 409 411 if result : 410 412 fields = result[0][1] 411 413 group.ident = result[0][0] 412 group.Name = fields.get("pykotaGroupName", [ self.databaseToUnicode(groupname)])[0]413 group.Description = self.databaseToUnicode(fields.get("description", [None])[0])414 group.Name = fields.get("pykotaGroupName", [databaseToUnicode(groupname)])[0] 415 group.Description = databaseToUnicode(fields.get("description", [None])[0]) 414 416 group.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] 415 417 group.AccountBalance = 0.0 … … 425 427 """Extracts printer information given its name : returns first matching printer.""" 426 428 printer = StoragePrinter(self, printername) 427 printername = self.unicodeToDatabase(printername)429 printername = unicodeToDatabase(printername) 428 430 result = self.doSearch("(&(objectClass=pykotaPrinter)(|(pykotaPrinterName=%s)(%s=%s)))" \ 429 431 % (printername, self.info["printerrdn"], printername), \ … … 435 437 fields = result[0][1] # take only first matching printer, ignore the rest 436 438 printer.ident = result[0][0] 437 printer.Name = fields.get("pykotaPrinterName", [ self.databaseToUnicode(printername)])[0]439 printer.Name = fields.get("pykotaPrinterName", [databaseToUnicode(printername)])[0] 438 440 printer.PricePerJob = float(fields.get("pykotaPricePerJob", [0.0])[0]) 439 441 printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0]) … … 445 447 printer.PassThrough = 0 446 448 printer.uniqueMember = fields.get("uniqueMember", []) 447 printer.Description = self.databaseToUnicode(fields.get("description", [""])[0])449 printer.Description = databaseToUnicode(fields.get("description", [""])[0]) 448 450 printer.Exists = True 449 451 return printer … … 458 460 base = self.info["userquotabase"] 459 461 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s)(pykotaPrinterName=%s))" % \ 460 ( self.unicodeToDatabase(user.Name), self.unicodeToDatabase(printer.Name)), \462 (unicodeToDatabase(user.Name), unicodeToDatabase(printer.Name)), \ 461 463 ["pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount", "pykotaMaxJobSize"], \ 462 464 base=base) … … 503 505 base = self.info["groupquotabase"] 504 506 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaGroupName=%s)(pykotaPrinterName=%s))" % \ 505 ( self.unicodeToDatabase(group.Name), self.unicodeToDatabase(printer.Name)), \507 (unicodeToDatabase(group.Name), unicodeToDatabase(printer.Name)), \ 506 508 ["pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaMaxJobSize"], \ 507 509 base=base) … … 535 537 grouppquota.PageCounter = 0 536 538 grouppquota.LifePageCounter = 0 537 usernamesfilter = "".join(["(pykotaUserName=%s)" % self.unicodeToDatabase(member.Name) for member in self.getGroupMembers(group)])539 usernamesfilter = "".join(["(pykotaUserName=%s)" % unicodeToDatabase(member.Name) for member in self.getGroupMembers(group)]) 538 540 if usernamesfilter : 539 541 usernamesfilter = "(|%s)" % usernamesfilter … … 543 545 base = self.info["userquotabase"] 544 546 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)%s)" % \ 545 ( self.unicodeToDatabase(printer.Name), usernamesfilter), \547 (unicodeToDatabase(printer.Name), usernamesfilter), \ 546 548 ["pykotaPageCounter", "pykotaLifePageCounter"], base=base) 547 549 if result : … … 555 557 """Extracts a printer's last job information.""" 556 558 lastjob = StorageLastJob(self, printer) 557 pname = self.unicodeToDatabase(printer.Name)559 pname = unicodeToDatabase(printer.Name) 558 560 result = self.doSearch("(&(objectClass=pykotaLastjob)(|(pykotaPrinterName=%s)(%s=%s)))" % \ 559 561 (pname, self.info["printerrdn"], pname), \ … … 591 593 lastjob.ident = result[0][0] 592 594 lastjob.JobId = fields.get("pykotaJobId")[0] 593 lastjob.UserName = self.databaseToUnicode(fields.get("pykotaUserName")[0])595 lastjob.UserName = databaseToUnicode(fields.get("pykotaUserName")[0]) 594 596 lastjob.PrinterPageCounter = int(fields.get("pykotaPrinterPageCounter", [0])[0]) 595 597 try : … … 602 604 lastjob.JobPrice = None 603 605 lastjob.JobAction = fields.get("pykotaAction", [""])[0] 604 lastjob.JobFileName = self.databaseToUnicode(fields.get("pykotaFileName", [""])[0])605 lastjob.JobTitle = self.databaseToUnicode(fields.get("pykotaTitle", [""])[0])606 lastjob.JobFileName = databaseToUnicode(fields.get("pykotaFileName", [""])[0]) 607 lastjob.JobTitle = databaseToUnicode(fields.get("pykotaTitle", [""])[0]) 606 608 lastjob.JobCopies = int(fields.get("pykotaCopies", [0])[0]) 607 lastjob.JobOptions = self.databaseToUnicode(fields.get("pykotaOptions", [""])[0])609 lastjob.JobOptions = databaseToUnicode(fields.get("pykotaOptions", [""])[0]) 608 610 lastjob.JobHostName = fields.get("pykotaHostName", [""])[0] 609 611 lastjob.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] 610 lastjob.JobBillingCode = self.databaseToUnicode(fields.get("pykotaBillingCode", [None])[0])612 lastjob.JobBillingCode = databaseToUnicode(fields.get("pykotaBillingCode", [None])[0]) 611 613 lastjob.JobMD5Sum = fields.get("pykotaMD5Sum", [None])[0] 612 614 lastjob.JobPages = fields.get("pykotaPages", [""])[0] … … 630 632 """Returns the group's members list.""" 631 633 groupmembers = [] 632 gname = self.unicodeToDatabase(group.Name)634 gname = unicodeToDatabase(group.Name) 633 635 result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % \ 634 636 (gname, self.info["grouprdn"], gname), \ … … 637 639 if result : 638 640 for username in result[0][1].get(self.info["groupmembers"], []) : 639 groupmembers.append(self.getUser( self.databaseToUnicode(username)))641 groupmembers.append(self.getUser(databaseToUnicode(username))) 640 642 return groupmembers 641 643 … … 643 645 """Returns the user's groups list.""" 644 646 groups = [] 645 uname = self.unicodeToDatabase(user.Name)647 uname = unicodeToDatabase(user.Name) 646 648 result = self.doSearch("(&(objectClass=pykotaGroup)(%s=%s))" % \ 647 649 (self.info["groupmembers"], uname), \ … … 650 652 if result : 651 653 for (groupid, fields) in result : 652 groupname = self.databaseToUnicode((fields.get("pykotaGroupName", [None]) or fields.get(self.info["grouprdn"], [None]))[0])654 groupname = databaseToUnicode((fields.get("pykotaGroupName", [None]) or fields.get(self.info["grouprdn"], [None]))[0]) 653 655 group = self.getFromCache("GROUPS", groupname) 654 656 if group is None : … … 681 683 for (printerid, fields) in result : 682 684 if printerid != printer.ident : # In case of integrity violation. 683 parentprinter = self.getPrinter( self.databaseToUnicode(fields.get("pykotaPrinterName")[0]))685 parentprinter = self.getPrinter(databaseToUnicode(fields.get("pykotaPrinterName")[0])) 684 686 if parentprinter.Exists : 685 687 pgroups.append(parentprinter) … … 703 705 patdict[p] = None 704 706 for (printerid, fields) in result : 705 printername = self.databaseToUnicode(fields.get("pykotaPrinterName", [""])[0] or fields.get(self.info["printerrdn"], [""])[0])707 printername = databaseToUnicode(fields.get("pykotaPrinterName", [""])[0] or fields.get(self.info["printerrdn"], [""])[0]) 706 708 if patdict.has_key(printername) or self.tool.matchString(printername, patterns) : 707 709 printer = StoragePrinter(self, printername) … … 716 718 printer.PassThrough = 0 717 719 printer.uniqueMember = fields.get("uniqueMember", []) 718 printer.Description = self.databaseToUnicode(fields.get("description", [""])[0])720 printer.Description = databaseToUnicode(fields.get("description", [""])[0]) 719 721 printer.Exists = True 720 722 printers.append(printer) … … 739 741 patdict[p] = None 740 742 for (userid, fields) in result : 741 username = self.databaseToUnicode(fields.get("pykotaUserName", [""])[0] or fields.get(self.info["userrdn"], [""])[0])743 username = databaseToUnicode(fields.get("pykotaUserName", [""])[0] or fields.get(self.info["userrdn"], [""])[0]) 742 744 if patdict.has_key(username) or self.tool.matchString(username, patterns) : 743 745 user = StorageUser(self, username) … … 745 747 user.Email = fields.get(self.info["usermail"], [None])[0] 746 748 user.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] 747 user.Description = self.databaseToUnicode(fields.get("description", [""])[0])748 uname = self.unicodeToDatabase(username)749 user.Description = databaseToUnicode(fields.get("description", [""])[0]) 750 uname = unicodeToDatabase(username) 749 751 result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(%s=%s)))" % \ 750 752 (uname, self.info["balancerdn"], uname), \ … … 780 782 description = "" 781 783 else : 782 description = self.databaseToUnicode(base64.decodestring(description))784 description = databaseToUnicode(base64.decodestring(description)) 783 785 if amount.endswith(" #") : 784 786 amount = amount[:-2] # TODO : should be catched earlier, the bug is above I think … … 806 808 patdict[p] = None 807 809 for (groupid, fields) in result : 808 groupname = self.databaseToUnicode(fields.get("pykotaGroupName", [""])[0] or fields.get(self.info["grouprdn"], [""])[0])810 groupname = databaseToUnicode(fields.get("pykotaGroupName", [""])[0] or fields.get(self.info["grouprdn"], [""])[0]) 809 811 if patdict.has_key(groupname) or self.tool.matchString(groupname, patterns) : 810 812 group = StorageGroup(self, groupname) 811 813 group.ident = groupid 812 group.Name = fields.get("pykotaGroupName", [ self.databaseToUnicode(groupname)])[0]814 group.Name = fields.get("pykotaGroupName", [databaseToUnicode(groupname)])[0] 813 815 group.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] 814 group.Description = self.databaseToUnicode(fields.get("description", [""])[0])816 group.Description = databaseToUnicode(fields.get("description", [""])[0]) 815 817 group.AccountBalance = 0.0 816 818 group.LifeTimePaid = 0.0 … … 827 829 """Returns the list of users who uses a given printer, along with their quotas.""" 828 830 usersandquotas = [] 829 pname = self.unicodeToDatabase(printer.Name)830 names = [ self.unicodeToDatabase(n) for n in names]831 pname = unicodeToDatabase(printer.Name) 832 names = [unicodeToDatabase(n) for n in names] 831 833 if self.info["userquotabase"].lower() == "user" : 832 834 base = self.info["userbase"] … … 839 841 if result : 840 842 for (userquotaid, fields) in result : 841 user = self.getUser( self.databaseToUnicode(fields.get("pykotaUserName")[0]))843 user = self.getUser(databaseToUnicode(fields.get("pykotaUserName")[0])) 842 844 userpquota = StorageUserPQuota(self, user, printer) 843 845 userpquota.ident = userquotaid … … 872 874 """Returns the list of groups which uses a given printer, along with their quotas.""" 873 875 groupsandquotas = [] 874 pname = self.unicodeToDatabase(printer.Name)875 names = [ self.unicodeToDatabase(n) for n in names]876 pname = unicodeToDatabase(printer.Name) 877 names = [unicodeToDatabase(n) for n in names] 876 878 if self.info["groupquotabase"].lower() == "group" : 877 879 base = self.info["groupbase"] … … 884 886 if result : 885 887 for (groupquotaid, fields) in result : 886 group = self.getGroup( self.databaseToUnicode(fields.get("pykotaGroupName")[0]))888 group = self.getGroup(databaseToUnicode(fields.get("pykotaGroupName")[0])) 887 889 grouppquota = self.getGroupPQuota(group, printer) 888 890 groupsandquotas.append((group, grouppquota)) … … 895 897 if oldentry.Exists : 896 898 return oldentry # we return the existing entry 897 printername = self.unicodeToDatabase(printer.Name)899 printername = unicodeToDatabase(printer.Name) 898 900 fields = { self.info["printerrdn"] : printername, 899 901 "objectClass" : ["pykotaObject", "pykotaPrinter"], … … 902 904 "pykotaPassThrough" : (printer.PassThrough and "t") or "f", 903 905 "pykotaMaxJobSize" : str(printer.MaxJobSize or 0), 904 "description" : self.unicodeToDatabase(printer.Description or ""),906 "description" : unicodeToDatabase(printer.Description or ""), 905 907 "pykotaPricePerPage" : str(printer.PricePerPage or 0.0), 906 908 "pykotaPricePerJob" : str(printer.PricePerJob or 0.0), … … 916 918 if oldentry.Exists : 917 919 return oldentry # we return the existing entry 918 uname = self.unicodeToDatabase(user.Name)920 uname = unicodeToDatabase(user.Name) 919 921 newfields = { 920 922 "pykotaUserName" : uname, 921 923 "pykotaLimitBy" : (user.LimitBy or "quota"), 922 "description" : self.unicodeToDatabase(user.Description or ""),924 "description" : unicodeToDatabase(user.Description or ""), 923 925 self.info["usermail"] : user.Email or "", 924 926 } … … 991 993 if oldentry.Exists : 992 994 return oldentry # we return the existing entry 993 gname = self.unicodeToDatabase(group.Name)995 gname = unicodeToDatabase(group.Name) 994 996 newfields = { 995 997 "pykotaGroupName" : gname, 996 998 "pykotaLimitBy" : (group.LimitBy or "quota"), 997 "description" : self.unicodeToDatabase(group.Description or "")999 "description" : unicodeToDatabase(group.Description or "") 998 1000 } 999 1001 mustadd = 1 … … 1040 1042 if not fields.has_key(self.info["groupmembers"]) : 1041 1043 fields[self.info["groupmembers"]] = [] 1042 fields[self.info["groupmembers"]].append( self.unicodeToDatabase(user.Name))1044 fields[self.info["groupmembers"]].append(unicodeToDatabase(user.Name)) 1043 1045 self.doModify(group.ident, fields) 1044 1046 group.Members.append(user) … … 1053 1055 fields[self.info["groupmembers"]] = [] 1054 1056 try : 1055 fields[self.info["groupmembers"]].remove( self.unicodeToDatabase(user.Name))1057 fields[self.info["groupmembers"]].remove(unicodeToDatabase(user.Name)) 1056 1058 except ValueError : 1057 1059 pass # TODO : Strange, shouldn't it be there ? … … 1067 1069 return oldentry # we return the existing entry 1068 1070 uuid = self.genUUID() 1069 uname = self.unicodeToDatabase(upq.User.Name)1070 pname = self.unicodeToDatabase(upq.Printer.Name)1071 uname = unicodeToDatabase(upq.User.Name) 1072 pname = unicodeToDatabase(upq.Printer.Name) 1071 1073 fields = { "cn" : uuid, 1072 1074 "objectClass" : ["pykotaObject", "pykotaUserPQuota"], … … 1095 1097 return oldentry # we return the existing entry 1096 1098 uuid = self.genUUID() 1097 gname = self.unicodeToDatabase(gpq.Group.Name)1098 pname = self.unicodeToDatabase(gpq.Printer.Name)1099 gname = unicodeToDatabase(gpq.Group.Name) 1100 pname = unicodeToDatabase(gpq.Printer.Name) 1099 1101 fields = { "cn" : uuid, 1100 1102 "objectClass" : ["pykotaObject", "pykotaGroupPQuota"], … … 1116 1118 "pykotaPassThrough" : (printer.PassThrough and "t") or "f", 1117 1119 "pykotaMaxJobSize" : str(printer.MaxJobSize or 0), 1118 "description" : self.unicodeToDatabase(printer.Description or ""),1120 "description" : unicodeToDatabase(printer.Description or ""), 1119 1121 "pykotaPricePerPage" : str(printer.PricePerPage or 0.0), 1120 1122 "pykotaPricePerJob" : str(printer.PricePerJob or 0.0), … … 1126 1128 newfields = { 1127 1129 "pykotaLimitBy" : (user.LimitBy or "quota"), 1128 "description" : self.unicodeToDatabase(user.Description or ""),1130 "description" : unicodeToDatabase(user.Description or ""), 1129 1131 self.info["usermail"] : user.Email or "", 1130 1132 } … … 1141 1143 newfields = { 1142 1144 "pykotaLimitBy" : (group.LimitBy or "quota"), 1143 "description" : self.unicodeToDatabase(group.Description or ""),1145 "description" : unicodeToDatabase(group.Description or ""), 1144 1146 } 1145 1147 self.doModify(group.ident, newfields) … … 1178 1180 payments = [] 1179 1181 for payment in user.Payments : 1180 payments.append("%s # %s # %s" % (payment[0], str(payment[1]), base64.encodestring( self.unicodeToDatabase(payment[2])).strip()))1181 payments.append("%s # %s # %s" % (str(DateTime.now()), str(amount), base64.encodestring( self.unicodeToDatabase(comment)).strip()))1182 payments.append("%s # %s # %s" % (payment[0], str(payment[1]), base64.encodestring(unicodeToDatabase(payment[2])).strip())) 1183 payments.append("%s # %s # %s" % (str(DateTime.now()), str(amount), base64.encodestring(unicodeToDatabase(comment)).strip())) 1182 1184 fields = { 1183 1185 "pykotaPayments" : payments, … … 1195 1197 def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None, jobmd5sum=None, jobpages=None, jobbilling=None, precomputedsize=None, precomputedprice=None) : 1196 1198 """Adds a job in a printer's history.""" 1197 uname = self.unicodeToDatabase(user.Name)1198 pname = self.unicodeToDatabase(printer.Name)1199 uname = unicodeToDatabase(user.Name) 1200 pname = unicodeToDatabase(printer.Name) 1199 1201 if (not self.disablehistory) or (not printer.LastJob.Exists) : 1200 1202 uuid = self.genUUID() … … 1214 1216 "pykotaPrinterPageCounter" : str(pagecounter), 1215 1217 "pykotaAction" : action, 1216 "pykotaFileName" : ((filename is None) and "None") or self.unicodeToDatabase(filename),1217 "pykotaTitle" : ((title is None) and "None") or self.unicodeToDatabase(title),1218 "pykotaFileName" : ((filename is None) and "None") or unicodeToDatabase(filename), 1219 "pykotaTitle" : ((title is None) and "None") or unicodeToDatabase(title), 1218 1220 "pykotaCopies" : str(copies), 1219 "pykotaOptions" : ((options is None) and "None") or self.unicodeToDatabase(options),1221 "pykotaOptions" : ((options is None) and "None") or unicodeToDatabase(options), 1220 1222 "pykotaHostName" : str(clienthost), 1221 1223 "pykotaJobSizeBytes" : str(jobsizebytes), 1222 1224 "pykotaMD5Sum" : str(jobmd5sum), 1223 1225 "pykotaPages" : jobpages, # don't add this attribute if it is not set, so no string conversion 1224 "pykotaBillingCode" : self.unicodeToDatabase(jobbilling), # don't add this attribute if it is not set, so no string conversion1226 "pykotaBillingCode" : unicodeToDatabase(jobbilling), # don't add this attribute if it is not set, so no string conversion 1225 1227 "pykotaPrecomputedJobSize" : str(precomputedsize), 1226 1228 "pykotaPrecomputedJobPrice" : str(precomputedprice), … … 1314 1316 where = [] 1315 1317 if user is not None : 1316 where.append("(pykotaUserName=%s)" % self.unicodeToDatabase(user.Name))1318 where.append("(pykotaUserName=%s)" % unicodeToDatabase(user.Name)) 1317 1319 if printer is not None : 1318 where.append("(pykotaPrinterName=%s)" % self.unicodeToDatabase(printer.Name))1320 where.append("(pykotaPrinterName=%s)" % unicodeToDatabase(printer.Name)) 1319 1321 if hostname is not None : 1320 1322 where.append("(pykotaHostName=%s)" % hostname) 1321 1323 if billingcode is not None : 1322 where.append("(pykotaBillingCode=%s)" % self.unicodeToDatabase(billingcode))1324 where.append("(pykotaBillingCode=%s)" % unicodeToDatabase(billingcode)) 1323 1325 if jobid is not None : 1324 where.append("(pykotaJobId=%s)" % jobid) # TODO : jobid is text, so self.unicodeToDatabase(jobid) but do all of them as well.1326 where.append("(pykotaJobId=%s)" % jobid) # TODO : jobid is text, so unicodeToDatabase(jobid) but do all of them as well. 1325 1327 if where : 1326 1328 where = "(&%s)" % "".join([precond] + where) … … 1363 1365 job.JobPrice = None 1364 1366 job.JobAction = fields.get("pykotaAction", [""])[0] 1365 job.JobFileName = self.databaseToUnicode(fields.get("pykotaFileName", [""])[0])1366 job.JobTitle = self.databaseToUnicode(fields.get("pykotaTitle", [""])[0])1367 job.JobFileName = databaseToUnicode(fields.get("pykotaFileName", [""])[0]) 1368 job.JobTitle = databaseToUnicode(fields.get("pykotaTitle", [""])[0]) 1367 1369 job.JobCopies = int(fields.get("pykotaCopies", [0])[0]) 1368 job.JobOptions = self.databaseToUnicode(fields.get("pykotaOptions", [""])[0])1370 job.JobOptions = databaseToUnicode(fields.get("pykotaOptions", [""])[0]) 1369 1371 job.JobHostName = fields.get("pykotaHostName", [""])[0] 1370 1372 job.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] 1371 job.JobBillingCode = self.databaseToUnicode(fields.get("pykotaBillingCode", [None])[0])1373 job.JobBillingCode = databaseToUnicode(fields.get("pykotaBillingCode", [None])[0]) 1372 1374 job.JobMD5Sum = fields.get("pykotaMD5Sum", [None])[0] 1373 1375 job.JobPages = fields.get("pykotaPages", [""])[0] … … 1389 1391 ((end is None) and (job.JobDate >= start)) or \ 1390 1392 ((job.JobDate >= start) and (job.JobDate <= end)) : 1391 job.UserName = self.databaseToUnicode(fields.get("pykotaUserName")[0])1392 job.PrinterName = self.databaseToUnicode(fields.get("pykotaPrinterName")[0])1393 job.UserName = databaseToUnicode(fields.get("pykotaUserName")[0]) 1394 job.PrinterName = databaseToUnicode(fields.get("pykotaPrinterName")[0]) 1393 1395 job.Exists = True 1394 1396 jobs.append(job) … … 1400 1402 def deleteUser(self, user) : 1401 1403 """Completely deletes an user from the Quota Storage.""" 1402 uname = self.unicodeToDatabase(user.Name)1404 uname = unicodeToDatabase(user.Name) 1403 1405 todelete = [] 1404 1406 result = self.doSearch("(&(objectClass=pykotaJob)(pykotaUserName=%s))" % uname, base=self.info["jobbase"]) … … 1418 1420 # if last job of current printer was printed by the user 1419 1421 # to delete, we also need to delete the printer's last job entry. 1420 printer = self.getPrinter( self.databaseToUnicode(fields["pykotaPrinterName"][0]))1422 printer = self.getPrinter(databaseToUnicode(fields["pykotaPrinterName"][0])) 1421 1423 if printer.LastJob.UserName == user.Name : 1422 1424 todelete.append(printer.LastJob.lastjobident) … … 1453 1455 def deleteGroup(self, group) : 1454 1456 """Completely deletes a group from the Quota Storage.""" 1455 gname = self.unicodeToDatabase(group.Name)1457 gname = unicodeToDatabase(group.Name) 1456 1458 if self.info["groupquotabase"].lower() == "group" : 1457 1459 base = self.info["groupbase"] … … 1524 1526 def deleteUserPQuota(self, upquota) : 1525 1527 """Completely deletes an user print quota entry from the database.""" 1526 uname = self.unicodeToDatabase(upquota.User.Name)1527 pname = self.unicodeToDatabase(upquota.Printer.Name)1528 uname = unicodeToDatabase(upquota.User.Name) 1529 pname = unicodeToDatabase(upquota.Printer.Name) 1528 1530 result = self.doSearch("(&(objectClass=pykotaJob)(pykotaUserName=%s)(pykotaPrinterName=%s))" \ 1529 1531 % (uname, pname), \ … … 1541 1543 def deletePrinter(self, printer) : 1542 1544 """Completely deletes a printer from the Quota Storage.""" 1543 pname = self.unicodeToDatabase(printer.Name)1545 pname = unicodeToDatabase(printer.Name) 1544 1546 result = self.doSearch("(&(objectClass=pykotaLastJob)(pykotaPrinterName=%s))" % pname, base=self.info["lastjobbase"]) 1545 1547 for (ident, fields) in result : … … 1764 1766 """Extracts billing code information given its label : returns first matching billing code.""" 1765 1767 code = StorageBillingCode(self, label) 1766 ulabel = self.unicodeToDatabase(label)1768 ulabel = unicodeToDatabase(label) 1767 1769 result = self.doSearch("(&(objectClass=pykotaBilling)(pykotaBillingCode=%s))" % \ 1768 1770 ulabel, \ … … 1772 1774 fields = result[0][1] # take only first matching code, ignore the rest 1773 1775 code.ident = result[0][0] 1774 code.BillingCode = self.databaseToUnicode(fields.get("pykotaBillingCode", [ulabel])[0])1776 code.BillingCode = databaseToUnicode(fields.get("pykotaBillingCode", [ulabel])[0]) 1775 1777 code.PageCounter = int(fields.get("pykotaPageCounter", [0])[0]) 1776 1778 code.Balance = float(fields.get("pykotaBalance", [0.0])[0]) 1777 code.Description = self.databaseToUnicode(fields.get("description", [""])[0])1779 code.Description = databaseToUnicode(fields.get("description", [""])[0]) 1778 1780 code.Exists = True 1779 1781 return code … … 1788 1790 fields = { "objectClass" : ["pykotaObject", "pykotaBilling"], 1789 1791 "cn" : uuid, 1790 "pykotaBillingCode" : self.unicodeToDatabase(bcode.BillingCode),1792 "pykotaBillingCode" : unicodeToDatabase(bcode.BillingCode), 1791 1793 "pykotaPageCounter" : str(bcode.PageCounter or 0), 1792 1794 "pykotaBalance" : str(bcode.Balance or 0.0), 1793 "description" : self.unicodeToDatabase(bcode.Description or ""),1795 "description" : unicodeToDatabase(bcode.Description or ""), 1794 1796 } 1795 1797 self.doAdd(dn, fields) … … 1800 1802 """Sets the new description for a billing code.""" 1801 1803 fields = { 1802 "description" : self.unicodeToDatabase(bcode.Description or ""),1804 "description" : unicodeToDatabase(bcode.Description or ""), 1803 1805 "pykotaPageCounter" : str(bcode.PageCounter or 0), 1804 1806 "pykotaBalance" : str(bcode.Balance or 0.0), … … 1822 1824 patdict[p] = None 1823 1825 for (codeid, fields) in result : 1824 codename = self.databaseToUnicode(fields.get("pykotaBillingCode", [""])[0])1826 codename = databaseToUnicode(fields.get("pykotaBillingCode", [""])[0]) 1825 1827 if patdict.has_key(codename) or self.tool.matchString(codename, patterns) : 1826 1828 code = StorageBillingCode(self, codename) … … 1828 1830 code.PageCounter = int(fields.get("pykotaPageCounter", [0])[0]) 1829 1831 code.Balance = float(fields.get("pykotaBalance", [0.0])[0]) 1830 code.Description = self.databaseToUnicode(fields.get("description", [""])[0])1832 code.Description = databaseToUnicode(fields.get("description", [""])[0]) 1831 1833 code.Exists = True 1832 1834 codes.append(code) -
pykota/trunk/pykota/storages/mysqlstorage.py
r3288 r3294 98 98 try : 99 99 before = time.time() 100 self. tool.logdebug("QUERY : %s" % query)100 self.querydebug("QUERY : %s" % query) 101 101 self.cursor.execute(query) 102 102 except self.database.Error, msg : … … 137 137 try : 138 138 before = time.time() 139 self. tool.logdebug("QUERY : %s" % query)139 self.querydebug("QUERY : %s" % query) 140 140 self.cursor.execute(query) 141 141 except self.database.Error, msg : -
pykota/trunk/pykota/storages/pgstorage.py
r3291 r3294 29 29 from pykota.storage import BaseStorage 30 30 from pykota.storages.sql import SQLStorage 31 32 from pykota.utils import * 31 33 32 34 try : … … 99 101 try : 100 102 before = time.time() 101 self. tool.logdebug("QUERY : %s" % query)103 self.querydebug("QUERY : %s" % query) 102 104 result = self.database.query(query) 103 105 except PGError, msg : … … 121 123 try : 122 124 before = time.time() 123 self. tool.logdebug("QUERY : %s" % query)125 self.querydebug("QUERY : %s" % query) 124 126 result = self.database.query(query) 125 127 except PGError, msg : … … 154 156 field = fields[j] 155 157 if type(field) == StringType : 156 fields[j] = self.databaseToUnicode(field)158 fields[j] = databaseToUnicode(field) 157 159 entries[i] = tuple(fields) 158 160 return entries -
pykota/trunk/pykota/storages/sqlitestorage.py
r3288 r3294 35 35 # TODO : to translate or not to translate ? 36 36 raise PyKotaStorageError, "This python version (%s) doesn't seem to have the PySQLite module installed correctly." % sys.version.split()[0] 37 37 38 38 class Storage(BaseStorage, SQLStorage) : 39 39 def __init__(self, pykotatool, host, dbname, user, passwd) : … … 82 82 try : 83 83 before = time.time() 84 self. tool.logdebug("QUERY : %s" % query)84 self.querydebug("QUERY : %s" % query) 85 85 self.cursor.execute(query) 86 86 except self.database.Error, msg : … … 119 119 try : 120 120 before = time.time() 121 self. tool.logdebug("QUERY : %s" % query)121 self.querydebug("QUERY : %s" % query) 122 122 self.cursor.execute(query) 123 123 except self.database.Error, msg : -
pykota/trunk/pykota/storages/sql.py
r3293 r3294 26 26 StorageJob, StorageLastJob, StorageUserPQuota, \ 27 27 StorageGroupPQuota, StorageBillingCode 28 29 from pykota.utils import * 28 30 29 31 class SQLStorage : … … 36 38 user.LifeTimePaid = record.get("lifetimepaid") 37 39 user.Email = record.get("email") 38 user.Description = self.databaseToUnicode(record.get("description"))40 user.Description = databaseToUnicode(record.get("description")) 39 41 user.OverCharge = record.get("overcharge", 1.0) 40 42 user.Exists = True … … 48 50 group.AccountBalance = record.get("balance") 49 51 group.LifeTimePaid = record.get("lifetimepaid") 50 group.Description = self.databaseToUnicode(record.get("description"))52 group.Description = databaseToUnicode(record.get("description")) 51 53 group.Exists = True 52 54 return group … … 64 66 else : 65 67 printer.PassThrough = False 66 printer.Description = self.databaseToUnicode(record.get("description") or "") # TODO : is 'or ""' still needed ?68 printer.Description = databaseToUnicode(record.get("description") or "") # TODO : is 'or ""' still needed ? 67 69 printer.Exists = True 68 70 return printer … … 76 78 job.JobPrice = record.get("jobprice") 77 79 job.JobAction = record.get("action") 78 job.JobFileName = self.databaseToUnicode(record.get("filename") or "")79 job.JobTitle = self.databaseToUnicode(record.get("title") or "")80 job.JobFileName = databaseToUnicode(record.get("filename") or "") 81 job.JobTitle = databaseToUnicode(record.get("title") or "") 80 82 job.JobCopies = record.get("copies") 81 job.JobOptions = self.databaseToUnicode(record.get("options") or "")83 job.JobOptions = databaseToUnicode(record.get("options") or "") 82 84 job.JobDate = record.get("jobdate") 83 85 job.JobHostName = record.get("hostname") … … 85 87 job.JobMD5Sum = record.get("md5sum") 86 88 job.JobPages = record.get("pages") 87 job.JobBillingCode = self.databaseToUnicode(record.get("billingcode") or "")89 job.JobBillingCode = databaseToUnicode(record.get("billingcode") or "") 88 90 job.PrecomputedJobSize = record.get("precomputedjobsize") 89 91 job.PrecomputedJobPrice = record.get("precomputedjobprice") 90 job.UserName = self.databaseToUnicode(record.get("username"))91 job.PrinterName = self.databaseToUnicode(record.get("printername"))92 job.UserName = databaseToUnicode(record.get("username")) 93 job.PrinterName = databaseToUnicode(record.get("printername")) 92 94 if job.JobTitle == job.JobFileName == job.JobOptions == "hidden" : 93 95 (job.JobTitle, job.JobFileName, job.JobOptions) = (_("Hidden because of privacy concerns"),) * 3 … … 138 140 code = StorageBillingCode(self, billingcode) 139 141 code.ident = record.get("id") 140 code.Description = self.databaseToUnicode(record.get("description") or "") # TODO : is 'or ""' still needed ?142 code.Description = databaseToUnicode(record.get("description") or "") # TODO : is 'or ""' still needed ? 141 143 code.Balance = record.get("balance") or 0.0 142 144 code.PageCounter = record.get("pagecounter") or 0 … … 149 151 expressions = [] 150 152 for (k, v) in only.items() : 151 expressions.append("%s=%s" % (k, self.doQuote( self.unicodeToDatabase(v))))153 expressions.append("%s=%s" % (k, self.doQuote(unicodeToDatabase(v)))) 152 154 return " AND ".join(expressions) 153 155 return "" … … 299 301 self.tool.printInfo("Object %s has no %s attribute !" % (repr(record), attribute), "error") 300 302 else : 301 attrval = self.databaseToUnicode(attrval)303 attrval = databaseToUnicode(attrval) 302 304 if patterns : 303 305 if (not isinstance(patterns, type([]))) and (not isinstance(patterns, type(()))) : … … 351 353 """Extracts user information given its name.""" 352 354 result = self.doSearch("SELECT * FROM users WHERE username=%s"\ 353 % self.doQuote( self.unicodeToDatabase(username)))355 % self.doQuote(unicodeToDatabase(username))) 354 356 if result : 355 357 return self.storageUserFromRecord(username, result[0]) … … 360 362 """Extracts group information given its name.""" 361 363 result = self.doSearch("SELECT groups.*,COALESCE(SUM(balance), 0.0) AS balance, COALESCE(SUM(lifetimepaid), 0.0) AS lifetimepaid FROM groups LEFT OUTER JOIN users ON users.id IN (SELECT userid FROM groupsmembers WHERE groupid=groups.id) WHERE groupname=%s GROUP BY groups.id,groups.groupname,groups.limitby,groups.description" \ 362 % self.doQuote( self.unicodeToDatabase(groupname)))364 % self.doQuote(unicodeToDatabase(groupname))) 363 365 if result : 364 366 return self.storageGroupFromRecord(groupname, result[0]) … … 369 371 """Extracts printer information given its name.""" 370 372 result = self.doSearch("SELECT * FROM printers WHERE printername=%s" \ 371 % self.doQuote( self.unicodeToDatabase(printername)))373 % self.doQuote(unicodeToDatabase(printername))) 372 374 if result : 373 375 return self.storagePrinterFromRecord(printername, result[0]) … … 378 380 """Extracts a billing code information given its name.""" 379 381 result = self.doSearch("SELECT * FROM billingcodes WHERE billingcode=%s" \ 380 % self.doQuote( self.unicodeToDatabase(label)))382 % self.doQuote(unicodeToDatabase(label))) 381 383 if result : 382 384 return self.storageBillingCodeFromRecord(label, result[0]) … … 416 418 if result : 417 419 for record in result : 418 user = self.storageUserFromRecord( self.databaseToUnicode(record.get("username")), \420 user = self.storageUserFromRecord(databaseToUnicode(record.get("username")), \ 419 421 record) 420 422 groupmembers.append(user) … … 428 430 if result : 429 431 for record in result : 430 groups.append(self.getGroup( self.databaseToUnicode(record.get("groupname"))))432 groups.append(self.getGroup(databaseToUnicode(record.get("groupname")))) 431 433 return groups 432 434 … … 438 440 for record in result : 439 441 if record["groupid"] != printer.ident : # in case of integrity violation 440 parentprinter = self.getPrinter( self.databaseToUnicode(record.get("printername")))442 parentprinter = self.getPrinter(databaseToUnicode(record.get("printername"))) 441 443 if parentprinter.Exists : 442 444 pgroups.append(parentprinter) … … 460 462 patdict[p] = None 461 463 for record in result : 462 pname = self.databaseToUnicode(record["printername"])464 pname = databaseToUnicode(record["printername"]) 463 465 if patdict.has_key(pname) or self.tool.matchString(pname, patterns) : 464 466 printer = self.storagePrinterFromRecord(pname, record) … … 484 486 patdict[p] = None 485 487 for record in result : 486 uname = self.databaseToUnicode(record["username"])488 uname = databaseToUnicode(record["username"]) 487 489 if patdict.has_key(uname) or self.tool.matchString(uname, patterns) : 488 490 user = self.storageUserFromRecord(uname, record) … … 508 510 patdict[p] = None 509 511 for record in result : 510 gname = self.databaseToUnicode(record["groupname"])512 gname = databaseToUnicode(record["groupname"]) 511 513 if patdict.has_key(gname) or self.tool.matchString(gname, patterns) : 512 514 group = self.storageGroupFromRecord(gname, record) … … 529 531 patdict[p] = None 530 532 for record in result : 531 codename = self.databaseToUnicode(record["billingcode"])533 codename = databaseToUnicode(record["billingcode"]) 532 534 if patdict.has_key(codename) or self.tool.matchString(codename, patterns) : 533 535 code = self.storageBillingCodeFromRecord(codename, record) … … 542 544 if result : 543 545 for record in result : 544 uname = self.databaseToUnicode(record.get("username"))546 uname = databaseToUnicode(record.get("username")) 545 547 if self.tool.matchString(uname, names) : 546 548 user = self.storageUserFromRecord(uname, record) … … 557 559 if result : 558 560 for record in result : 559 gname = self.databaseToUnicode(record.get("groupname"))561 gname = databaseToUnicode(record.get("groupname")) 560 562 if self.tool.matchString(gname, names) : 561 563 group = self.getGroup(gname) … … 570 572 return oldentry 571 573 self.doModify("INSERT INTO printers (printername, passthrough, maxjobsize, description, priceperpage, priceperjob) VALUES (%s, %s, %s, %s, %s, %s)" \ 572 % (self.doQuote( self.unicodeToDatabase(printer.Name)), \574 % (self.doQuote(unicodeToDatabase(printer.Name)), \ 573 575 self.doQuote((printer.PassThrough and "t") or "f"), \ 574 576 self.doQuote(printer.MaxJobSize or 0), \ 575 self.doQuote( self.unicodeToDatabase(printer.Description)), \577 self.doQuote(unicodeToDatabase(printer.Description)), \ 576 578 self.doQuote(printer.PricePerPage or 0.0), \ 577 579 self.doQuote(printer.PricePerJob or 0.0))) … … 585 587 return oldentry 586 588 self.doModify("INSERT INTO billingcodes (billingcode, balance, pagecounter, description) VALUES (%s, %s, %s, %s)" \ 587 % (self.doQuote( self.unicodeToDatabase(bcode.BillingCode)),589 % (self.doQuote(unicodeToDatabase(bcode.BillingCode)), 588 590 self.doQuote(bcode.Balance or 0.0), \ 589 591 self.doQuote(bcode.PageCounter or 0), \ 590 self.doQuote( self.unicodeToDatabase(bcode.Description))))592 self.doQuote(unicodeToDatabase(bcode.Description)))) 591 593 bcode.isDirty = False 592 594 return None # the entry created doesn't need further modification … … 598 600 return oldentry 599 601 self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge, description) VALUES (%s, %s, %s, %s, %s, %s, %s)" % \ 600 (self.doQuote( self.unicodeToDatabase(user.Name)), \602 (self.doQuote(unicodeToDatabase(user.Name)), \ 601 603 self.doQuote(user.LimitBy or 'quota'), \ 602 604 self.doQuote(user.AccountBalance or 0.0), \ … … 604 606 self.doQuote(user.Email), \ 605 607 self.doQuote(user.OverCharge), \ 606 self.doQuote( self.unicodeToDatabase(user.Description))))608 self.doQuote(unicodeToDatabase(user.Description)))) 607 609 if user.PaymentsBacklog : 608 610 for (value, comment) in user.PaymentsBacklog : … … 618 620 return oldentry 619 621 self.doModify("INSERT INTO groups (groupname, limitby, description) VALUES (%s, %s, %s)" % \ 620 (self.doQuote( self.unicodeToDatabase(group.Name)), \622 (self.doQuote(unicodeToDatabase(group.Name)), \ 621 623 self.doQuote(group.LimitBy or "quota"), \ 622 self.doQuote( self.unicodeToDatabase(group.Description))))624 self.doQuote(unicodeToDatabase(group.Description)))) 623 625 group.isDirty = False 624 626 return None # the entry created doesn't need further modification … … 677 679 % (self.doQuote((printer.PassThrough and "t") or "f"), \ 678 680 self.doQuote(printer.MaxJobSize or 0), \ 679 self.doQuote( self.unicodeToDatabase(printer.Description)), \681 self.doQuote(unicodeToDatabase(printer.Description)), \ 680 682 self.doQuote(printer.PricePerPage or 0.0), \ 681 683 self.doQuote(printer.PricePerJob or 0.0), \ … … 690 692 self.doQuote(user.Email), \ 691 693 self.doQuote(user.OverCharge), \ 692 self.doQuote( self.unicodeToDatabase(user.Description)), \694 self.doQuote(unicodeToDatabase(user.Description)), \ 693 695 self.doQuote(user.ident))) 694 696 … … 697 699 self.doModify("UPDATE groups SET limitby=%s, description=%s WHERE id=%s" \ 698 700 % (self.doQuote(group.LimitBy or 'quota'), \ 699 self.doQuote( self.unicodeToDatabase(group.Description)), \701 self.doQuote(unicodeToDatabase(group.Description)), \ 700 702 self.doQuote(group.ident))) 701 703 … … 717 719 % (self.doQuote(bcode.Balance or 0.0), \ 718 720 self.doQuote(bcode.PageCounter or 0), \ 719 self.doQuote( self.unicodeToDatabase(bcode.Description)), \721 self.doQuote(unicodeToDatabase(bcode.Description)), \ 720 722 self.doQuote(bcode.ident))) 721 723 … … 735 737 """Adds a new payment to the payments history.""" 736 738 if user.ident is not None : 737 self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote( self.unicodeToDatabase(comment))))739 self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote(unicodeToDatabase(comment)))) 738 740 else : 739 self.doModify("INSERT INTO payments (userid, amount, description) VALUES ((SELECT id FROM users WHERE username=%s), %s, %s)" % (self.doQuote( self.unicodeToDatabase(user.Name)), self.doQuote(amount), self.doQuote(self.unicodeToDatabase(comment))))741 self.doModify("INSERT INTO payments (userid, amount, description) VALUES ((SELECT id FROM users WHERE username=%s), %s, %s)" % (self.doQuote(unicodeToDatabase(user.Name)), self.doQuote(amount), self.doQuote(unicodeToDatabase(comment)))) 740 742 741 743 def writeLastJobSize(self, lastjob, jobsize, jobprice) : … … 748 750 # For legal reasons, we want to hide the title, filename and options 749 751 title = filename = options = "hidden" 750 filename = self.unicodeToDatabase(filename)751 title = self.unicodeToDatabase(title)752 options = self.unicodeToDatabase(options)753 jobbilling = self.unicodeToDatabase(jobbilling)752 filename = unicodeToDatabase(filename) 753 title = unicodeToDatabase(title) 754 options = unicodeToDatabase(options) 755 jobbilling = unicodeToDatabase(jobbilling) 754 756 if (not self.disablehistory) or (not printer.LastJob.Exists) : 755 757 if jobsize is not None : … … 814 816 where.append("hostname=%s" % self.doQuote(hostname)) 815 817 if billingcode is not None : 816 where.append("billingcode=%s" % self.doQuote( self.unicodeToDatabase(billingcode)))818 where.append("billingcode=%s" % self.doQuote(unicodeToDatabase(billingcode))) 817 819 if jobid is not None : 818 where.append("jobid=%s" % self.doQuote(jobid)) # TODO : jobid is text, so self.unicodeToDatabase(jobid) but do all of them as well.820 where.append("jobid=%s" % self.doQuote(jobid)) # TODO : jobid is text, so unicodeToDatabase(jobid) but do all of them as well. 819 821 if start is not None : 820 822 where.append("jobdate>=%s" % self.doQuote(start)) -
pykota/trunk/pykota/tool.py
r3288 r3294 29 29 import getopt 30 30 import smtplib 31 import gettext32 31 import locale 33 32 import socket … … 109 108 self.logger = logger.openLogger("stderr") 110 109 111 # locale stuff 112 try : 113 locale.setlocale(locale.LC_ALL, (lang, charset)) 114 except (locale.Error, IOError) : 115 locale.setlocale(locale.LC_ALL, None) 110 # Saves a copy of the locale settings 116 111 (self.language, self.charset) = locale.getlocale() 117 self.language = self.language or "C" 118 try : 119 self.charset = self.charset or locale.getpreferredencoding() 120 except locale.Error : 121 self.charset = sys.stdout.encoding or sys.getfilesystemencoding() 122 123 # Dirty hack : if the charset is ASCII, we can safely use UTF-8 instead 124 # This has the advantage of allowing transparent support for recent 125 # versions of CUPS which (en-)force charset to UTF-8 when printing. 126 # This should be needed only when printing, but is probably (?) safe 127 # to do when using interactive commands. 128 if self.charset.upper() in ('ASCII', 'ANSI_X3.4-1968') : 129 self.charset = "UTF-8" 130 131 # translation stuff 132 try : 133 try : 134 trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)], codeset=self.charset) 135 except TypeError : # Python <2.4 136 trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)]) 137 trans.install(unicode=True) 138 except : 139 gettext.NullTranslations().install(unicode=True) 140 112 141 113 # pykota specific stuff 142 114 self.documentation = doc … … 362 334 # and reset the list of arguments to the lines read from 363 335 # the file. 364 argsfile = open(parsed["arguments"] or parsed["A"], "r") 336 argsfile = open(parsed["arguments"] or parsed["A"], "r") # TODO : charset decoding 365 337 argv = [ l.strip() for l in argsfile.readlines() ] 366 338 argsfile.close() -
pykota/trunk/pykota/utils.py
r3275 r3294 19 19 # $Id$ 20 20 # 21 22 """This module defines some utility functions which make no sense as methods.""" 23 24 import sys 25 import locale 26 import gettext 27 28 def initlocale(lang="", cset=None) : 29 """Initializes the locale stuff.""" 30 try : 31 locale.setlocale(locale.LC_ALL, (lang, cset)) 32 except (locale.Error, IOError) : 33 locale.setlocale(locale.LC_ALL, None) 34 (language, charset) = locale.getlocale() 35 language = language or "C" 36 try : 37 charset = charset or locale.getpreferredencoding() 38 except locale.Error : 39 charset = sys.stdout.encoding or sys.getfilesystemencoding() 40 41 # Dirty hack : if the charset is ASCII, we can safely use UTF-8 instead 42 # This has the advantage of allowing transparent support for recent 43 # versions of CUPS which (en-)force charset to UTF-8 when printing. 44 # This should be needed only when printing, but is probably (?) safe 45 # to do when using interactive commands. 46 if charset.upper() in ('ASCII', 'ANSI_X3.4-1968') : 47 charset = "UTF-8" 48 return (language, charset) 49 50 def initgettext(lang, cset) : 51 """Initializes gettext translations for PyKota.""" 52 try : 53 try : 54 trans = gettext.translation("pykota", \ 55 languages=["%s.%s" % (lang, 56 cset)], 57 codeset=cset) 58 except TypeError : # Python <2.4 59 trans = gettext.translation("pykota", 60 languages=["%s.%s" % (lang, 61 cset)]) 62 trans.install(unicode=True) 63 except : 64 gettext.NullTranslations().install(unicode=True) 65 66 def databaseToUnicode(text) : 67 """Converts from database format (UTF-8) to unicode.""" 68 if text is not None : 69 return text.decode("UTF-8", "replace") 70 else : 71 return None 72 73 def unicodeToDatabase(text) : 74 """Converts from unicode to database format (UTF-8).""" 75 if text is not None : 76 return text.encode("UTF-8", "replace") 77 else : 78 return None 79 80 def logerr(text) : 81 """Logs an unicode text to stderr.""" 82 sys.stderr.write(text.encode(sys.stdout.encoding, "replace")) 83