X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=geni%2Futil%2Fconfig.py;h=9f9e018bd01d6b06167f7578d367c79385fb1e3c;hb=39d5f4aec6848b2568c69b2c76f554ed3920741c;hp=90aee0d04d7cd09adae38a0ea6f25399a1be6333;hpb=6db0c6dc85876673b06cf81e4b4e948e0e0515d1;p=sfa.git diff --git a/geni/util/config.py b/geni/util/config.py index 90aee0d0..9f9e018b 100644 --- a/geni/util/config.py +++ b/geni/util/config.py @@ -14,12 +14,11 @@ # Note that Geniwrapper does not access any of the PLC databases directly via # a mysql connection; All PLC databases are accessed via PLCAPI. -import os -import sys +from os.path import join,dirname,basename,abspath from geni.util.debug import log import traceback -geni = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))+ os.sep + "geni" +geni = join(dirname(dirname(dirname(abspath(__file__)))), "geni") class Config: """ @@ -27,23 +26,27 @@ class Config: fast but no type conversions. """ - def __init__(self, file = "/etc/geni/geni_config"): + def __init__(self, filepath = "/etc/geni/geni_config"): # Load plc_config loaded = False - path = os.path.dirname(os.path.abspath(__file__)) + # path to config.py source + path = dirname(abspath(__file__)) self.path = path - self.basepath = os.path.dirname(self.path) - filename = file.split(os.sep)[-1] - alt_file = path + os.sep + 'util' + os.sep + filename - geni_file = geni + os.sep + 'util' + os.sep + filename - files = [file, alt_file, geni_file] - - for file in files: + # parent directory of config.py source + self.basepath = dirname(self.path) + # path to actual config file + filename = basename(filepath) + alt_file = join(self.path, 'util', filename) + geni_file = join(geni, 'util', filename) + files = [filepath, alt_file, geni_file] + + for config_file in files: try: - execfile(file, self.__dict__) + execfile(config_file, self.__dict__) loaded = True - self.config_file = file + self.config_file = config_file + self.config_path = dirname(config_file) break except: pass @@ -53,11 +56,11 @@ class Config: # set up some useful variables - def load(self, file): + def load(self, filepath): try: - execfile(file, self.__dict__) + execfile(filepath, self.__dict__) except: - raise Exception, "Could not find config in " + file + raise Exception, "Could not find config in " + filepath plcConfig = Config("/etc/planetlab/plc_config")