Commits

Anonymous committed 2fc66cd Draft

specify configuration file on command line

Comments (0)

Files changed (3)

 
 *araldo* provides a simple, extensible communication relay (based on `gevent <http://www.gevent.org/>`_ and `WebSockets <http://en.wikipedia.org/wiki/WebSocket>`_) between multiple endpoints
 
+Resources:
+
+- `Repository and issue tracker: <http://bitbucket.org/ganymed/araldo>`_
+- `Documentation of in-development version <https://araldo.readthedocs.org/en/latest/>`_
+
 Use cases
 *********
 
     redis_1:
       - redis_2
       - redis_3
+
+Platform & System Requirements
+******************************
+
+- *araldo* has been tested under Python 2.6 and 2.7. Python 3.x is not 
+  supported because not all libraries it depends on currently support 3.x.
+- *araldo* was tested exclusively under Linux.
 """ Launches WSGI server process hosting WebSocketApp
 """
 from __future__ import print_function
+from optparse import OptionParser, OptionError
+import os.path
 import logging
 import signal
 import sys
     return plugin_manager
 
 
+def parse_args(args):
+    """ Get parser for command line parameters
+    """
+    parser = OptionParser()
+    conf_file_opt = parser.add_option(
+        "-c", "--config", action="store",
+        dest="config",
+        default="araldo.yaml",
+        help="Configuration path")
+    options, args = parser.parse_args(args)
+
+    if not os.path.exists(options.config):
+        raise OptionError(
+            "Configuration file %s not found\n" % options.config,
+            conf_file_opt
+        )
+    return options, args
+
+
 def main():
     """ Server main method
     """
-    config = Config.create("araldo.yaml")
+    try:
+        options, args = parse_args(sys.argv[1:])
+    except OptionError as error:
+        sys.stderr.write(str(error))
+        sys.exit(1)
+
+    config = Config.create(options.config)
     logger = setup_logging(config)
 
     setup_signals()

test/server_test.py

 """
 
 import pytest
-from mock import Mock, patch
+from optparse import OptionError
+from mock import Mock, patch, call
 from araldo.server import (
     start_server, setup_logging, setup_sending,
     setup_signals, sig_handler, setup_plugins)
     with patch.object(server.sys, "exit") as ex:
         sig_handler(None, None)
         assert ex.called
+
+
+def test_parse_args_explicit_conf_long_option():
+    with patch.object(server.os.path, "exists") as ex:
+        ex.return_value = True
+        options, args = server.parse_args(["--config", "myconf.yaml"])
+        assert options.config == "myconf.yaml"
+
+
+def test_parse_args_explicit_conf():
+    with patch.object(server.os.path, "exists") as ex:
+        ex.return_value = True
+        options, args = server.parse_args(["-c", "myconf.yaml"])
+        assert options.config == "myconf.yaml"
+
+
+def test_parse_args_implicit_conf():
+    options, args = server.parse_args([])
+    assert options.config == "araldo.yaml"
+
+
+def test_nonexistant_config_file():
+    options, args = server.parse_args([])
+    with pytest.raises(OptionError):
+        with patch.object(server.os.path, "exists") as ex:
+            ex.return_value = False
+            server.parse_args(["-c", "nonexistant.yaml"])
+            assert ex.call_args == call("nonexistant.yaml")