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
# Admin node
[admin]
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]
......
......@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
from optparse import OptionParser
from ConfigParser import SafeConfigParser, NoOptionError
from . import util
......@@ -44,14 +45,18 @@ class ConfigurationManager(object):
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.argument_list = argument_list
self.parser = None
if config_file is not None:
config_file = options.pop('file', None)
if config_file:
self.parser = SafeConfigParser(defaults)
self.parser.read(config_file)
self.section = section
else:
self.parser = None
self.section = options.pop('section', section)
def __get(self, key, optional=False):
value = self.argument_list.get(key)
......@@ -67,6 +72,14 @@ class ConfigurationManager(object):
raise RuntimeError("Option '%s' is undefined'" % (key, ))
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):
""" Get the master node list except itself """
masters = self.__get('masters')
......
......@@ -32,22 +32,10 @@ defaults = dict(
def main(args=None):
# build configuration dict from command line options
(options, args) = parser.parse_args(args=args)
arguments = dict(
uuid = options.uuid,
cluster = options.cluster,
masters = options.masters,
bind = options.bind,
)
config = ConfigurationManager(
defaults,
options.file,
options.section or 'admin',
arguments,
)
config = ConfigurationManager(defaults, options, 'admin')
# setup custom logging
logging.setup(options.logfile)
logging.setup(config.getLogfile())
# and then, load and run the application
from neo.admin.app import Application
......
......@@ -43,26 +43,10 @@ defaults = dict(
def main(args=None):
# build configuration dict from command line options
(options, args) = parser.parse_args(args=args)
arguments = dict(
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,
)
config = ConfigurationManager(defaults, options, 'master')
# setup custom logging
logging.setup(options.logfile)
logging.setup(config.getLogfile())
# and then, load and run the application
from neo.master.app import Application
......
......@@ -45,26 +45,10 @@ def main(args=None):
# letting it slip through in a long option list.
# We should drop support configation files to make such check useful.
(options, args) = parser.parse_args(args=args)
arguments = dict(
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,
)
config = ConfigurationManager(defaults, options, 'storage')
# setup custom logging
logging.setup(options.logfile)
logging.setup(config.getLogfile())
# and then, load and run the 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