This patch introduces "--user-flags" option which enable to add user
original CLI or config file options for their own Ryu applications.

Usage Example)
  $ cat user_flags.py
  from ryu import cfg

  CONF = cfg.CONF
  CONF.register_cli_opts([
      cfg.StrOpt(
          'user-cli-opt', default=None,
          help='user original CLI option'),
  ])

  $ ryu-manager --user-flags user_flags.py user_app.py

Signed-off-by: IWASE Yusuke <iwase.yusu...@gmail.com>
---
 ryu/cmd/manager.py | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/ryu/cmd/manager.py b/ryu/cmd/manager.py
index dc7aca8..797d8d5 100755
--- a/ryu/cmd/manager.py
+++ b/ryu/cmd/manager.py
@@ -16,6 +16,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import os
+import sys
+
 from ryu.lib import hub
 hub.patch(thread=False)
 
@@ -43,10 +46,28 @@ CONF.register_cli_opts([
     cfg.BoolOpt('enable-debugger', default=False,
                 help='don\'t overwrite Python standard threading library'
                 '(use only for debugging)'),
+    cfg.StrOpt('user-flags', default=None,
+               help='Additional flags file for user applications'),
 ])
 
 
+def _parse_user_flags():
+    """
+    Parses user-flags file and loads it to register user defined options.
+    """
+    try:
+        idx = list(sys.argv).index('--user-flags')
+        user_flags_file = sys.argv[idx + 1]
+    except (ValueError, IndexError):
+        user_flags_file = ''
+
+    if user_flags_file and os.path.isfile(user_flags_file):
+        from ryu.utils import _import_module_file
+        _import_module_file(user_flags_file)
+
+
 def main(args=None, prog=None):
+    _parse_user_flags()
     try:
         CONF(args=args, prog=prog,
              project='ryu', version='ryu-manager %s' % version,
@@ -65,7 +86,6 @@ def main(args=None, prog=None):
         hub.patch(thread=True)
 
     if CONF.pid_file:
-        import os
         with open(CONF.pid_file, 'w') as pid_file:
             pid_file.write(str(os.getpid()))
 
-- 
2.7.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to