Commit 518c7588 authored by Julien Muchembled's avatar Julien Muchembled

Allow to specify log file in configuration file, and expand ~(user) construction

parent 32b2d173
...@@ -53,6 +53,9 @@ partitions: 12 ...@@ -53,6 +53,9 @@ partitions: 12
# Admin node # Admin node
[admin] [admin]
bind: 127.0.0.1:9999 bind: 127.0.0.1:9999
# Paths to log files can be specified here, but be careful not to do it in a
# common section. ~ and ~user constructions are expanded.
;logfile: ~/log/admin.log
# Master nodes # Master nodes
[master] [master]
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
from optparse import OptionParser from optparse import OptionParser
from ConfigParser import SafeConfigParser, NoOptionError from ConfigParser import SafeConfigParser, NoOptionError
from . import util from . import util
...@@ -44,14 +45,18 @@ class ConfigurationManager(object): ...@@ -44,14 +45,18 @@ class ConfigurationManager(object):
command line arguments command line arguments
""" """
def __init__(self, defaults, config_file, section, argument_list): def __init__(self, defaults, options, section):
self.argument_list = options = {k: v
for k, v in options.__dict__.iteritems()
if v is not None}
self.defaults = defaults self.defaults = defaults
self.argument_list = argument_list config_file = options.pop('file', None)
self.parser = None if config_file:
if config_file is not None:
self.parser = SafeConfigParser(defaults) self.parser = SafeConfigParser(defaults)
self.parser.read(config_file) self.parser.read(config_file)
self.section = section else:
self.parser = None
self.section = options.pop('section', section)
def __get(self, key, optional=False): def __get(self, key, optional=False):
value = self.argument_list.get(key) value = self.argument_list.get(key)
...@@ -67,6 +72,14 @@ class ConfigurationManager(object): ...@@ -67,6 +72,14 @@ class ConfigurationManager(object):
raise RuntimeError("Option '%s' is undefined'" % (key, )) raise RuntimeError("Option '%s' is undefined'" % (key, ))
return value return value
def __getPath(self, *args, **kw):
path = self.__get(*args, **kw)
if path:
return os.path.expanduser(path)
def getLogfile(self):
return self.__getPath('logfile', True)
def getMasters(self): def getMasters(self):
""" Get the master node list except itself """ """ Get the master node list except itself """
masters = self.__get('masters') masters = self.__get('masters')
......
...@@ -32,22 +32,10 @@ defaults = dict( ...@@ -32,22 +32,10 @@ defaults = dict(
def main(args=None): def main(args=None):
# build configuration dict from command line options # build configuration dict from command line options
(options, args) = parser.parse_args(args=args) (options, args) = parser.parse_args(args=args)
arguments = dict( config = ConfigurationManager(defaults, options, 'admin')
uuid = options.uuid,
cluster = options.cluster,
masters = options.masters,
bind = options.bind,
)
config = ConfigurationManager(
defaults,
options.file,
options.section or 'admin',
arguments,
)
# setup custom logging # setup custom logging
logging.setup(options.logfile) logging.setup(config.getLogfile())
# and then, load and run the application # and then, load and run the application
from neo.admin.app import Application from neo.admin.app import Application
......
...@@ -43,26 +43,10 @@ defaults = dict( ...@@ -43,26 +43,10 @@ defaults = dict(
def main(args=None): def main(args=None):
# build configuration dict from command line options # build configuration dict from command line options
(options, args) = parser.parse_args(args=args) (options, args) = parser.parse_args(args=args)
arguments = dict( config = ConfigurationManager(defaults, options, 'master')
uuid = options.uuid or None,
bind = options.bind,
cluster = options.cluster,
masters = options.masters,
replicas = options.replicas,
partitions = options.partitions,
autostart = options.autostart,
upstream_cluster = options.upstream_cluster,
upstream_masters = options.upstream_masters,
)
config = ConfigurationManager(
defaults,
options.file,
options.section or 'master',
arguments,
)
# setup custom logging # setup custom logging
logging.setup(options.logfile) logging.setup(config.getLogfile())
# and then, load and run the application # and then, load and run the application
from neo.master.app import Application from neo.master.app import Application
......
...@@ -45,26 +45,10 @@ def main(args=None): ...@@ -45,26 +45,10 @@ def main(args=None):
# letting it slip through in a long option list. # letting it slip through in a long option list.
# We should drop support configation files to make such check useful. # We should drop support configation files to make such check useful.
(options, args) = parser.parse_args(args=args) (options, args) = parser.parse_args(args=args)
arguments = dict( config = ConfigurationManager(defaults, options, 'storage')
uuid = options.uuid,
bind = options.bind,
cluster = options.cluster,
masters = options.masters,
database = options.database,
engine = options.engine,
reset = options.reset,
adapter = options.adapter,
wait = options.wait,
)
config = ConfigurationManager(
defaults,
options.file,
options.section or 'storage',
arguments,
)
# setup custom logging # setup custom logging
logging.setup(options.logfile) logging.setup(config.getLogfile())
# and then, load and run the application # and then, load and run the application
from neo.storage.app import Application from neo.storage.app import Application
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment