def __init__(self, file = "/etc/planetlab/plc_config.xml"): try: from plc_config import PLCConfiguration except: sys.path.append(myplc) from plc_config import PLCConfiguration # Load plc_config.xml try: cfg = PLCConfiguration(file) except: # Try myplc directory try: cfg = PLCConfiguration(myplc + os.sep + "plc_config.xml") except: raise PLCAPIError("Could not find plc_config.xml in " + \ file + ", " + \ myplc + os.sep + "plc_config.xml") for (category, variablelist) in cfg.variables().values(): for variable in variablelist.values(): # Try to cast each variable to an appropriate Python # type. if variable['type'] == "int": value = int(variable['value']) elif variable['type'] == "double": value = float(variable['value']) elif variable['type'] == "boolean": if variable['value'] == "true": value = True else: value = False else: value = variable['value'] # Variables are split into categories such as # "plc_api", "plc_db", etc. Within each category are # variables such as "host", "port", etc. For backward # compatibility, refer to variables by their shell # names. shell_name = category['id'].upper() + "_" + variable['id'].upper() setattr(self, shell_name, value)