From: FUJITA Tomonori <[email protected]>

from fujita-san on ryu-devel.
Message-Id: <20130828.144534.1568838937885789095.fujita.tomon...@lab.ntt.co.jp>

Signed-off-by: YAMAMOTO Takashi <[email protected]>
---
 ryu/utils.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/ryu/utils.py b/ryu/utils.py
index dd22084..ed53238 100644
--- a/ryu/utils.py
+++ b/ryu/utils.py
@@ -35,6 +35,7 @@ import logging
 import os
 import sys
 import re
+from oslo.config import cfg
 
 LOG = logging.getLogger('ryu.utils')
 
@@ -47,7 +48,17 @@ def import_module(modname):
         name = os.path.basename(modname)
         if name.endswith('.py'):
             name = name[:-3]
-        __import__(name)
+        try:
+            __import__(name)
+        except cfg.ArgsAlreadyParsedError:
+        # ryu-manager needs to import modules calling
+        # register_cli_opts. Thus, passing a imported file as a
+        # command line option for ryu-manager results in double import
+        # (e.g. ryu.topology.switches). The following code is not
+        # perfect but better than nothing.
+            for key in sys.modules.keys():
+                if key.endswith(name):
+                    return sys.modules[key]
         return sys.modules[name]
     return sys.modules[modname]
 
-- 
1.8.3.1


------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to