better handling for installing config file in virtualenv
authorGui Chen <gui.chen@intel.com>
Thu, 12 Sep 2013 09:42:23 +0000 (05:42 -0400)
committerGui Chen <gui.chen@intel.com>
Mon, 16 Sep 2013 02:06:35 +0000 (22:06 -0400)
in this handling, mic will check 'real_prefix' which is
not existed in real python env but in virtualenv to
determine the config file location

Change-Id: Iaa67ba1d78395470bc20dd7682c29ec4c933fd56
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/conf.py
setup.cfg [deleted file]
setup.py

index e29bd3b..45485d8 100644 (file)
@@ -27,13 +27,10 @@ DEFAULT_GSITECONF = '/etc/mic/mic.conf'
 
 
 def get_siteconf():
-    mic_path = os.path.dirname(__file__)
-
-    m = re.match(r"(?P<prefix>.*)\/lib(64)?\/.*", mic_path)
-    if m and m.group('prefix') != "/usr":
-        return os.path.join(m.group('prefix'), "etc/mic/mic.conf")
-
-    return DEFAULT_GSITECONF
+    if hasattr(sys, 'real_prefix'):
+        return os.path.join(sys.prefix, "etc/mic/mic.conf")
+    else:
+        return DEFAULT_GSITECONF
 
 class ConfigMgr(object):
     prefer_backends = ["zypp", "yum"]
diff --git a/setup.cfg b/setup.cfg
deleted file mode 100644 (file)
index fe98c34..0000000
--- a/setup.cfg
+++ /dev/null
@@ -1,2 +0,0 @@
-[install]
-prefix=$PREFIX
index d4db893..c5c2a74 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -3,11 +3,6 @@
 import os, sys
 import glob
 from distutils.core import setup
-try:
-    import setuptools
-    # enable "setup.py develop", optional
-except ImportError:
-    pass
 
 MOD_NAME = 'mic'
 
@@ -45,53 +40,28 @@ PACKAGES = [MOD_NAME,
 IMAGER_PLUGINS = glob.glob(os.path.join("plugins", "imager", "*.py"))
 BACKEND_PLUGINS = glob.glob(os.path.join("plugins", "backend", "*.py"))
 
-# the following code to do a simple parse for '--prefix' opts
 prefix = sys.prefix
-is_next = False
-for arg in sys.argv:
-    if is_next:
-        prefix = arg
-        break
-    if '--prefix=' in arg:
-        prefix = arg[9:]
-        break
-    elif '--prefix' == arg:
-        is_next = True
-
-# get the installation path of mic.conf
-prefix = os.path.abspath(os.path.expanduser(prefix)).rstrip('/')
-if prefix.lstrip('/') == 'usr':
-    etc_prefix = '/etc'
-else:
-    etc_prefix = os.path.join(prefix, 'etc')
+# if real_prefix, it must be in virtualenv, use prefix as root
+root = sys.prefix if hasattr(sys, 'real_prefix') else ''
 
 conffile = 'etc/mic.conf'
-if os.path.isfile('%s/mic/mic.conf' % etc_prefix):
-    conffile += '.new'
-
 # apply prefix to mic.conf.in to generate actual mic.conf
 conf_str = file('etc/mic.conf.in').read()
 conf_str = conf_str.replace('@PREFIX@', prefix)
 with file(conffile, 'w') as wf:
     wf.write(conf_str)
 
-try:
-    os.environ['PREFIX'] = prefix
-    setup(name=MOD_NAME,
-          version = version,
-          description = 'Image Creator for Linux Distributions',
-          author='Jian-feng Ding, Qiang Zhang, Gui Chen',
-          author_email='jian-feng.ding@intel.com, qiang.z.zhang@intel.com, gui.chen@intel.com',
-          url='https://github.com/jfding/mic',
-          scripts=[
-              'tools/mic',
-              ],
-          packages = PACKAGES,
-          data_files = [("%s/lib/mic/plugins/imager" % prefix, IMAGER_PLUGINS),
-                        ("%s/lib/mic/plugins/backend" % prefix, BACKEND_PLUGINS),
-                        ("%s/mic" % etc_prefix, [conffile])]
-    )
-finally:
-    # remove dynamic file distfiles/mic.conf
-    os.unlink(conffile)
-
+setup(name=MOD_NAME,
+  version = version,
+  description = 'Image Creator for Linux Distributions',
+  author='Jian-feng Ding, Qiang Zhang, Gui Chen',
+  author_email='jian-feng.ding@intel.com, qiang.z.zhang@intel.com, gui.chen@intel.com',
+  url='https://github.com/jfding/mic',
+  scripts=[
+      'tools/mic',
+      ],
+  packages = PACKAGES,
+  data_files = [("%s/lib/mic/plugins/imager" % prefix, IMAGER_PLUGINS),
+                ("%s/lib/mic/plugins/backend" % prefix, BACKEND_PLUGINS),
+                ("%s/etc/mic" % root, [conffile])]
+)