From 7563c63c90df05ec9e97d1a48735e5b725eb0f84 Mon Sep 17 00:00:00 2001 From: Flaper Fesp Date: Fri, 5 Apr 2013 10:15:24 +0200 Subject: [PATCH] Implemented marconi-server entry point This patch adds the first console_script for marconi server. In order to use it it's enough to run setup.py either using develop or install. Side changes: The config now uses sys.argv[1:] if no custom cli args have been set. Implements blueprint transport-base Change-Id: I15732129d66b32fca2b818e9105b17f541094983 --- etc/marconi.conf-sample | 3 ++- marconi/bin/__init__.py | 0 marconi/bin/server.py | 33 +++++++++++++++++++++++++++++++++ marconi/common/config.py | 11 +++++++---- marconi/tests/util/base.py | 2 ++ setup.py | 4 ++++ 6 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 marconi/bin/__init__.py create mode 100644 marconi/bin/server.py diff --git a/etc/marconi.conf-sample b/etc/marconi.conf-sample index e29db1712..4e9be411a 100644 --- a/etc/marconi.conf-sample +++ b/etc/marconi.conf-sample @@ -11,4 +11,5 @@ port = 8888 ;port = 9999 [drivers:storage:mongodb] -uri = mongodb://db1.example.net,db2.example.net:2500/?replicaSet=test&ssl=true&w=majority \ No newline at end of file +uri = mongodb://db1.example.net,db2.example.net:2500/?replicaSet=test&ssl=true&w=majority +database = marconi diff --git a/marconi/bin/__init__.py b/marconi/bin/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/marconi/bin/server.py b/marconi/bin/server.py new file mode 100644 index 000000000..d1e82597e --- /dev/null +++ b/marconi/bin/server.py @@ -0,0 +1,33 @@ +# Copyright (c) 2013 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys + +from marconi import bootstrap + + +def fail(returncode, e): + sys.stderr.write("ERROR: %s\n" % e) + sys.exit(returncode) + + +def run(): + try: + server = bootstrap.Bootstrap() + server.run() + except KeyboardInterrupt: + fail(1, '... terminating marconi') + except RuntimeError as e: + fail(1, e) diff --git a/marconi/common/config.py b/marconi/common/config.py index 95858e073..56427334d 100644 --- a/marconi/common/config.py +++ b/marconi/common/config.py @@ -52,12 +52,15 @@ A call to `.load` without an argument looks up for the default ones: ~/.marconi/marconi.conf /etc/marconi/marconi.conf -The global config variables, if any, can also be read from the command -line arguments by saving them before a `.load` call: +Global config variables, if any, will be read from the command line using +sys.argv[:1]. If needed, this can be overwritten by calling `set_cli` +before calling `.load` - cfg_handle.set_cli(sys.argv[1:]) + cfg_handle.set_cli([]) """ +import sys + from oslo.config import cfg @@ -73,7 +76,7 @@ def _init(): __setattr__ = dict.__setitem__ conf = cfg.ConfigOpts() - my = Obj(args=[]) + my = Obj(args=sys.argv[1:]) def namespace(name, title=None): """ diff --git a/marconi/tests/util/base.py b/marconi/tests/util/base.py index dd832d40a..eb8430900 100644 --- a/marconi/tests/util/base.py +++ b/marconi/tests/util/base.py @@ -51,6 +51,8 @@ class TestBase(testtools.TestCase): :returns: Project's config object. """ + # Reset CLI + cfg.set_cli([]) cfg.load(self.conf_path(filename)) return cfg diff --git a/setup.py b/setup.py index 9cd611948..573c4176b 100755 --- a/setup.py +++ b/setup.py @@ -38,4 +38,8 @@ setuptools.setup( install_requires=requires, dependency_links=dependency_links, cmdclass=common_setup.get_cmdclass(), + entry_points={ + 'console_scripts': + ['marconi-server = marconi.bin.server:run'] + } )