summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Kölker <jason@koelker.net>2012-03-09 17:29:41 -0600
committerJason Kölker <jason@koelker.net>2012-03-09 17:57:25 -0600
commite8a5ae2e5aab6b649b57d03f8a03af689d7e6b6e (patch)
treeae2b159622db93c21ba87ed7634fe6d25e76e8ea
parent96e8e38ed9c8ed03b5c0e95055b39d5759ed6b9d (diff)
downloadoslo-e8a5ae2e5aab6b649b57d03f8a03af689d7e6b6e.tar.gz
oslo-e8a5ae2e5aab6b649b57d03f8a03af689d7e6b6e.tar.xz
oslo-e8a5ae2e5aab6b649b57d03f8a03af689d7e6b6e.zip
Import cfg module directly if not in path
If openstack.common is not installed, but another module has declared the openstack namespace an ImportError is thrown since the common doesnt exist in the openstack namespace. This falls back to importing cfg directly from ./openstack/common/cfg.py. Also ensures that openstack/__init__.py exists in the destination * Fixes LP951197 Change-Id: I88c26fb7cc1aed97e66b068e4f0562b1f00b2b29
-rw-r--r--update.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/update.py b/update.py
index f5e6669..50da7e1 100644
--- a/update.py
+++ b/update.py
@@ -55,14 +55,24 @@ the modules to copy and the base destination module
Obviously, the first way is the easiest!
"""
+import imp
import os
import os.path
import re
import shutil
import sys
-from openstack.common import cfg
-
+try:
+ from openstack import common
+ cfg = common.cfg
+except AttributeError:
+ # NOTE(jkoelker) Workaround for LP951197
+ try:
+ f, path, description = imp.find_module('openstack/common/cfg')
+ cfg = imp.load_module('cfg', f, path, description)
+ finally:
+ if f is not None:
+ f.close()
opts = [
cfg.ListOpt('modules',
@@ -91,11 +101,12 @@ def _parse_args(argv):
config_file = None
if os.path.isfile(argv[i]):
config_file = argv[i]
- elif os.path.isdir(argv[i]) and os.path.isfile(def_config_file(argv[i])):
+ elif (os.path.isdir(argv[i])
+ and os.path.isfile(def_config_file(argv[i]))):
config_file = def_config_file(argv[i])
if config_file:
- argv[i:i+1] = ['--config-file', config_file]
+ argv[i:i + 1] = ['--config-file', config_file]
args = conf(argv)
if args:
@@ -122,9 +133,15 @@ def _replace(path, pattern, replacement):
f.write(re.sub(pattern, replacement, line))
+def _make_dirs(path):
+ if not os.path.isdir(os.path.dirname(path)):
+ os.makedirs(os.path.dirname(path))
+
+
def _copy_file(path, base, dest_dir):
dest = _dest_path(path, base, dest_dir)
+ _make_dirs(dest)
if not os.path.isdir(os.path.dirname(dest)):
os.makedirs(os.path.dirname(dest))
@@ -167,6 +184,12 @@ def main(argv):
print >> sys.stderr, "A destination base module is required"
sys.exit(1)
+ init_path = os.path.join(_dest_path('openstack', conf.base, dest_dir),
+ '__init__.py')
+ if not os.path.exists(init_path):
+ _make_dirs(init_path)
+ open(init_path, 'w').close()
+
for mod in conf.modules:
_copy_module(mod, conf.base, dest_dir)