diff options
author | Kat <katerinab@gmail.com> | 2013-04-05 21:34:52 +0200 |
---|---|---|
committer | Kat <katerinab@gmail.com> | 2013-04-05 21:34:52 +0200 |
commit | 0270be43b9a24c039f518c684b788f0a52aa50a0 (patch) | |
tree | cd6f2cb18ca39f89a95b274ee2176bacdca16873 | |
parent | 0248d3b6685e333b2829ade6904e354b18cc8fe5 (diff) |
Minor refactoring of importing osmoappdesc
-rw-r--r-- | osmopy/osmotestconfig.py | 8 | ||||
-rw-r--r--[-rwxr-xr-x] | osmopy/osmotestvty.py | 9 | ||||
-rwxr-xr-x | osmopy/osmoutil.py | 16 |
3 files changed, 15 insertions, 18 deletions
diff --git a/osmopy/osmotestconfig.py b/osmopy/osmotestconfig.py index 8a18f84..f9ebde0 100644 --- a/osmopy/osmotestconfig.py +++ b/osmopy/osmotestconfig.py @@ -190,12 +190,8 @@ if __name__ == '__main__': if args.w: workdir = args.w - osmoappdesc = None - try: - osmoappdesc = osmoutil.importappconf(confpath, "osmoappdesc") - except ImportError as e: - print >> sys.stderr, "osmoappdesc not found, set searchpath with -p" - sys.exit(1) + osmoappdesc = osmoutil.importappconf_or_quit(confpath, "osmoappdesc", + args.p) apps = osmoappdesc.apps configs = osmoappdesc.app_configs diff --git a/osmopy/osmotestvty.py b/osmopy/osmotestvty.py index f02c610..8d9f3c4 100755..100644 --- a/osmopy/osmotestvty.py +++ b/osmopy/osmotestvty.py @@ -27,6 +27,7 @@ confpath = '.' class TestVTY(unittest.TestCase): + def setUp(self): osmo_vty_cmd = osmoappdesc.vty_command[:] config_index = osmo_vty_cmd.index('-c') @@ -90,12 +91,8 @@ if __name__ == '__main__': if args.p: confpath = args.p - osmoappdesc = None - try: - osmoappdesc = osmoutil.importappconf(confpath, "osmoappdesc") - except ImportError as e: - print >> sys.stderr, "osmoappdesc not found, set searchpath with -p" - sys.exit(1) + osmoappdesc = osmoutil.importappconf_or_quit(confpath, "osmoappdesc", + args.p) print "confpath %s, workdir %s" % (confpath, workdir) os.chdir(workdir) diff --git a/osmopy/osmoutil.py b/osmopy/osmoutil.py index 791506d..78465d9 100755 --- a/osmopy/osmoutil.py +++ b/osmopy/osmoutil.py @@ -39,12 +39,16 @@ def end_proc(proc): proc.wait() -"""Add a directory to sys.path, try to import a config file. +"""Add a directory to sys.path, try to import a config file.""" -This may throw ImportError if the config file is not found.""" - - -def importappconf(dirname, confname): +def importappconf_or_quit(dirname, confname, p_set): if dirname not in sys.path: sys.path.append(dirname) - return importlib.import_module(confname) + try: + return importlib.import_module(confname) + except ImportError as e: + if p_set: + print >> sys.stderr, "osmoappdesc not found in %s" % dirname + else: + print >> sys.stderr, "set osmoappdesc location with -p <dir>" + sys.exit(1) |