must explicitly catch ConfigParser.MissingSectionHeaderError
[sfa.git] / sfa / util / config.py
index 499ab1f..7220afb 100644 (file)
@@ -47,7 +47,7 @@ DO NOT EDIT. This file was automatically generated at
         if filename:
             try:
                 self.config.read(filename)
-            except:
+            except ConfigParser.MissingSectionHeaderError:
                 if filename.endswith('.xml'):
                     self.load_xml(filename)
                 else:
@@ -117,6 +117,24 @@ DO NOT EDIT. This file was automatically generated at
     def validate_type(self, var_type, value):
         return True
 
+    @staticmethod
+    def is_xml(config_file):
+        try:
+            x = Xml(config_file)
+            return True     
+        except:
+            return False
+
+    @staticmethod
+    def is_ini(config_file):
+        try:
+            c = ConfigParser.ConfigParser()
+            c.read(config_file)
+            return True
+        except:
+            return False
+
+
     def dump(self, sections = []):
         sys.stdout.write(output_python())
 
@@ -174,7 +192,7 @@ DO NOT EDIT. This file was automatically generated at
     def output_xml(self, encoding = "utf-8"):
         pass
 
-    def output_variables(self):
+    def output_variables(self, encoding="utf-8"):
         """
         Return list of all variable names.
         """