# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-import os, re
+import os, sys, re
import ConfigParser
import msger
DEFAULT_GSITECONF = '/etc/mic/mic.conf'
+def get_siteconf(siteconf="etc/mic/mic.conf"):
+ mic_path = os.path.dirname(__file__)
+ path_ptn = re.compile(r"(?P<prefix>.*)\/lib(64)?\/.*")
+ m = path_ptn.match(mic_path)
+ if m:
+ if m.group('prefix') == "/usr":
+ return DEFAULT_GSITECONF
+ else:
+ return os.path.join(m.group('prefix'), siteconf)
+ return None
+
class ConfigMgr(object):
DEFAULTS = {'common': {
"distro_name": "Default Distribution",
# reset config options
self.reset()
+ if not siteconf:
+ siteconf = get_siteconf()
+ if not siteconf or not os.path.exists(siteconf):
+ siteconf = DEFAULT_GSITECONF
+
# initial options from siteconf
- if siteconf:
- self._siteconf = siteconf
- else:
- # use default site config
- self._siteconf = DEFAULT_GSITECONF
+ self._siteconf = siteconf
if ksconf:
self._ksconf = ksconf
BACKEND_PLUGINS = glob.glob(os.path.join("plugins", "backend", "*.py"))
# the following code to do a simple parse for '--prefix' opts
-prefix = '/usr'
+prefix = sys.prefix
is_next = False
for arg in sys.argv:
if is_next:
break
if '--prefix=' in arg:
prefix = arg[9:]
+ break
elif '--prefix' == arg:
is_next = True
-if prefix == '/usr':
+# expand the path, for user may type some unexcepted format
+prefix = os.path.abspath(os.path.expanduser(prefix)).rstrip('/')
+if prefix.lstrip('/') == 'usr':
etc_prefix = '/etc'
else:
etc_prefix = os.path.join(prefix, 'etc')