tweak plc.d/db so that clean-dump works better, and can take an optional number of...
[plcapi.git] / PLC / Config.py
index 7d666b3..690f9e3 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bin/python
 #
 # PLCAPI configuration store. Supports XML-based configuration file
 # format exported by MyPLC.
@@ -6,8 +5,6 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2004-2006 The Trustees of Princeton University
 #
-# $Id$
-#
 
 import os
 import sys
@@ -31,15 +28,15 @@ class Config:
     def __init__(self, file = "/etc/planetlab/plc_config"):
         # Load plc_config
         try:
-            execfile(file, self.__dict__)
+            exec(compile(open(file).read(), file, 'exec'), self.__dict__)
         except:
             # Try myplc directory
             try:
-                execfile(file, self.__dict__)
+                exec(compile(open(myplc + os.sep + "plc_config").read(), myplc + os.sep + "plc_config", 'exec'), self.__dict__)
             except:
                 raise PLCAPIError("Could not find plc_config in " + \
                                   file + ", " + \
-                                  myplc + "plc_config")
+                                  myplc + os.sep + "plc_config")
 
 class XMLConfig:
     """
@@ -64,10 +61,10 @@ class XMLConfig:
             except:
                 raise PLCAPIError("Could not find plc_config.xml in " + \
                                   file + ", " + \
-                                  myplc + "plc_config.xml")
+                                  myplc + os.sep + "plc_config.xml")
 
-        for (category, variablelist) in cfg.variables().values():
-            for variable in variablelist.values():
+        for (category, variablelist) in list(cfg.variables().values()):
+            for variable in list(variablelist.values()):
                 # Try to cast each variable to an appropriate Python
                 # type.
                 if variable['type'] == "int":
@@ -93,4 +90,4 @@ class XMLConfig:
 if __name__ == '__main__':
     import pprint
     pprint = pprint.PrettyPrinter()
-    pprint.pprint(Config().__dict__.items())
+    pprint.pprint(list(Config().__dict__.items()))