Mercurial > libervia-web
diff src/twisted/plugins/libervia_server.py @ 470:34ce41e014c4
server side: options managing improvments:
- cleaned a bit the code / comments
- i18n
- added Libervia.OPT_PARAMETERS_CFG and moved Libervia.OPT_PARAMETERS to Libervia.OPT_PARAMETERS_BOTH, to allow options to be only in sat.conf
- use of new constant ASCII_APP_NAME for tap name
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 10 Jun 2014 15:38:47 +0200 |
parents | 01880aa8ea2d |
children | 6700386291f1 |
line wrap: on
line diff
--- a/src/twisted/plugins/libervia_server.py Mon Jun 09 20:37:42 2014 +0200 +++ b/src/twisted/plugins/libervia_server.py Tue Jun 10 15:38:47 2014 +0200 @@ -32,6 +32,10 @@ from libervia.server.constants import Const as C from sat.core import log_config log_config.satConfigure(C.LOG_BACKEND_TWISTED, C) + + + +from sat.core.i18n import _ from sat.tools.config import getConfig from zope.interface import implements @@ -43,10 +47,12 @@ from ConfigParser import SafeConfigParser, NoSectionError, NoOptionError try: from libervia.server.server import Libervia - opt_params = Libervia.OPT_PARAMETERS + opt_params = Libervia.OPT_PARAMETERS_BOTH + cfg_params = Libervia.OPT_PARAMETERS_CFG except (ImportError, SystemExit): # avoid raising an error when you call twisted and sat is not launched opt_params = [] + cfg_params = [] class Options(usage.Options): @@ -55,22 +61,27 @@ optParameters = opt_params def __init__(self): - """You want to read SàT configuration file now in order to overwrite the hard-coded default values. - This is because the priority for the usage of the values is (from lowest to highest): - - hard-coded default values - - values from SàT configuration files - - values passed on the command line - If you do it later: after the command line options have been parsed, there's no good way to know - if the options values are the hard-coded ones or if they have been passed on the command line. + """Read SàT configuration file in order to overwrite the hard-coded default values. + + Priority for the usage of the values is (from lowest to highest): + - hard-coded default values + - values from SàT configuration files + - values passed on the command line """ + # If we do it the reading later: after the command line options have been parsed, there's no good way to know + # if the options values are the hard-coded ones or if they have been passed on the command line. + + # FIXME: must be refactored + code can be factorised with backend config = SafeConfigParser() config.read(C.CONFIG_FILES) - for index, param in list(enumerate(self.optParameters)): - # index is only used to not modify the loop variable "param" + for param in self.optParameters + cfg_params: name = param[0] try: value = getConfig(config, 'libervia', name) - self.optParameters[index][2] = param[4](value) + try: + param[2] = param[4](value) + except IndexError: # the coerce method is optional + param[2] = value except (NoSectionError, NoOptionError): pass usage.Options.__init__(self) @@ -79,9 +90,8 @@ class LiberviaMaker(object): implements(IServiceMaker, IPlugin) - tapname = 'libervia' - # FIXME: twistd bugs when printing 'à' on "Unknown command" error (works on normal command listing) - description = u'The web frontend of Salut a Toi' + tapname = C.ASCII_APP_NAME + description = _(u'The web frontend of Salut à Toi') options = Options def makeService(self, options):