Changeset 3296
- Timestamp:
- 01/21/08 22:43:54 (16 years ago)
- Location:
- pykota/trunk
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/conf/pykota.conf.sample
r3285 r3296 50 50 [global] 51 51 52 52 # This directive configures the charset to use when reading PyKota's 53 # configuration files. All directives values will be decoded and 54 # interpreted using the character set defined here. 55 # This value can only be present in the [global] section. 56 # 57 # When not set, the default value 'UTF-8' is used. 58 config_charset : UTF-8 53 59 54 60 #################################################################### -
pykota/trunk/pykota/config.py
r3288 r3296 45 45 self.config = ConfigParser.ConfigParser() 46 46 self.config.read([self.filename]) 47 try : 48 self.config_charset = self.config.get("global", \ 49 "config_charset", \ 50 raw=1) 51 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : 52 self.config_charset = "UTF-8" 47 53 48 54 def isTrue(self, option) : … … 64 70 return [pname for pname in self.config.sections() if pname != "global"] 65 71 66 def getGlobalOption(self, option, ignore= 0) :72 def getGlobalOption(self, option, ignore=False) : 67 73 """Returns an option from the global section, or raises a PyKotaConfigError if ignore is not set, else returns None.""" 68 74 try : 69 return self.config.get("global", option, raw=1) 75 return self.config.get("global", option, raw=1).decode(self.config_charset) 70 76 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : 71 77 if ignore : … … 76 82 def getPrinterOption(self, printername, option) : 77 83 """Returns an option from the printer section, or the global section, or raises a PyKotaConfigError.""" 78 globaloption = self.getGlobalOption(option, ignore= 1)79 try : 80 return self.config.get(printername, option, raw=1) 84 globaloption = self.getGlobalOption(option, ignore=True) 85 try : 86 return self.config.get(printername, option, raw=1).decode(self.config_charset) 81 87 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : 82 88 if globaloption is not None : … … 99 105 for option in ["storageserver", "storagename", "storageuser"] : 100 106 backendinfo[option] = self.getGlobalOption(option) 101 backendinfo["storageuserpw"] = self.getGlobalOption("storageuserpw", ignore= 1) # password is optional107 backendinfo["storageuserpw"] = self.getGlobalOption("storageuserpw", ignore=True) # password is optional 102 108 103 109 backendinfo["storageadmin"] = None … … 108 114 if adminconf.sections() : # were we able to read the file ? 109 115 try : 110 backendinfo["storageadmin"] = adminconf.get("global", "storageadmin", raw=1) 116 backendinfo["storageadmin"] = adminconf.get("global", "storageadmin", raw=1).decode(self.config_charset) 111 117 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : 112 118 if not issqlite : 113 119 raise PyKotaConfigError, _("Option %s not found in section global of %s") % ("storageadmin", self.adminfilename) 114 120 try : 115 backendinfo["storageadminpw"] = adminconf.get("global", "storageadminpw", raw=1) 121 backendinfo["storageadminpw"] = adminconf.get("global", "storageadminpw", raw=1).decode(self.config_charset) 116 122 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : 117 123 pass # Password is optional … … 120 126 # server directly and users to use the replicas transparently. 121 127 try : 122 backendinfo["storagebackend"] = adminconf.get("global", "storagebackend", raw=1) 128 backendinfo["storagebackend"] = adminconf.get("global", "storagebackend", raw=1).decode(self.config_charset) 123 129 except ConfigParser.NoOptionError : 124 130 pass 125 131 try : 126 backendinfo["storageserver"] = adminconf.get("global", "storageserver", raw=1) 132 backendinfo["storageserver"] = adminconf.get("global", "storageserver", raw=1).decode(self.config_charset) 127 133 except ConfigParser.NoOptionError : 128 134 pass 129 135 try : 130 backendinfo["storagename"] = adminconf.get("global", "storagename", raw=1) 136 backendinfo["storagename"] = adminconf.get("global", "storagename", raw=1).decode(self.config_charset) 131 137 except ConfigParser.NoOptionError : 132 138 pass … … 151 157 152 158 # should we use TLS, by default (if unset) value is NO 153 ldapinfo["ldaptls"] = self.isTrue(self.getGlobalOption("ldaptls", ignore= 1))154 ldapinfo["cacert"] = self.getGlobalOption("cacert", ignore= 1)159 ldapinfo["ldaptls"] = self.isTrue(self.getGlobalOption("ldaptls", ignore=True)) 160 ldapinfo["cacert"] = self.getGlobalOption("cacert", ignore=True) 155 161 if ldapinfo["cacert"] : 156 162 ldapinfo["cacert"] = ldapinfo["cacert"].strip() … … 173 179 def getLogoURL(self) : 174 180 """Returns the URL to use for the logo in the CGI scripts.""" 175 url = self.getGlobalOption("logourl", ignore= 1) or \181 url = self.getGlobalOption("logourl", ignore=True) or \ 176 182 "http://www.pykota.com/pykota.png" 177 183 return url.strip() … … 179 185 def getLogoLink(self) : 180 186 """Returns the URL to go to when the user clicks on the logo in the CGI scripts.""" 181 url = self.getGlobalOption("logolink", ignore= 1) or \187 url = self.getGlobalOption("logolink", ignore=True) or \ 182 188 "http://www.pykota.com/" 183 189 return url.strip() … … 496 502 def getPrivacy(self) : 497 503 """Returns True if privacy is activated, else False.""" 498 return self.isTrue(self.getGlobalOption("privacy", ignore= 1))504 return self.isTrue(self.getGlobalOption("privacy", ignore=True)) 499 505 500 506 def getDebug(self) : 501 507 """Returns True if debugging is activated, else False.""" 502 return self.isTrue(self.getGlobalOption("debug", ignore= 1))508 return self.isTrue(self.getGlobalOption("debug", ignore=True)) 503 509 504 510 def getCaching(self) : 505 511 """Returns True if database caching is enabled, else False.""" 506 return self.isTrue(self.getGlobalOption("storagecaching", ignore= 1))512 return self.isTrue(self.getGlobalOption("storagecaching", ignore=True)) 507 513 508 514 def getLDAPCache(self) : 509 515 """Returns True if low-level LDAP caching is enabled, else False.""" 510 return self.isTrue(self.getGlobalOption("ldapcache", ignore= 1))516 return self.isTrue(self.getGlobalOption("ldapcache", ignore=True)) 511 517 512 518 def getDisableHistory(self) : 513 519 """Returns True if we want to disable history, else False.""" 514 return self.isTrue(self.getGlobalOption("disablehistory", ignore= 1))520 return self.isTrue(self.getGlobalOption("disablehistory", ignore=True)) 515 521 516 522 def getUserNameToLower(self) : 517 523 """Deprecated.""" 518 return self.getGlobalOption("utolower", ignore= 1)524 return self.getGlobalOption("utolower", ignore=True) 519 525 520 526 def getUserNameCase(self) : … … 522 528 validvalues = [ "upper", "lower", "native" ] 523 529 try : 524 value = self.getGlobalOption("usernamecase", ignore= 1).strip().lower()530 value = self.getGlobalOption("usernamecase", ignore=True).strip().lower() 525 531 except AttributeError : 526 532 value = "native" … … 531 537 def getRejectUnknown(self) : 532 538 """Returns True if we want to reject the creation of unknown users or groups, else False.""" 533 return self.isTrue(self.getGlobalOption("reject_unknown", ignore= 1))539 return self.isTrue(self.getGlobalOption("reject_unknown", ignore=True)) 534 540 535 541 def getPrinterKeepFiles(self, printername) : … … 645 651 def getWinbindSeparator(self) : 646 652 """Returns the winbind separator's value if it is set, else None.""" 647 return self.getGlobalOption("winbind_separator", ignore= 1)653 return self.getGlobalOption("winbind_separator", ignore=True) 648 654 649 655 def getAccountBanner(self, printername) : … … 721 727 branchbasename = "coefficient_" 722 728 try : 723 globalbranches = [ (k, self.config.get("global", k) ) for k in self.config.options("global") if k.startswith(branchbasename) ]729 globalbranches = [ (k, self.config.get("global", k).decode(self.config_charset)) for k in self.config.options("global") if k.startswith(branchbasename) ] 724 730 except ConfigParser.NoSectionError, msg : 725 731 raise PyKotaConfigError, "Invalid configuration file : %s" % msg 726 732 try : 727 sectionbranches = [ (k, self.config.get(printername, k) ) for k in self.config.options(printername) if k.startswith(branchbasename) ]733 sectionbranches = [ (k, self.config.get(printername, k).decode(self.config_charset)) for k in self.config.options(printername) if k.startswith(branchbasename) ] 728 734 except ConfigParser.NoSectionError, msg : 729 735 sectionbranches = []