fix broken sfi config
[sfa.git] / sfa / client / sfi.py
index dce1ac2..5349d43 100644 (file)
@@ -234,11 +234,9 @@ def load_record_from_opts(options):
     return Record(dict=record_dict)
 
 def load_record_from_file(filename):
-    f=codecs.open(filename, encoding="utf-8", mode="r")
-    xml_string = f.read()
-    f.close()
-    return Record(xml=xml_string)
-
+    with codecs.open(filename, encoding="utf-8", mode="r") as f:
+        xml_str = f.read()
+    return Record(xml=xml_str)
 
 import uuid
 def unique_call_id(): return uuid.uuid4().urn
@@ -939,13 +937,14 @@ use this if you mean an authority instead""")
         for (section, tuples) in flags:
             print "[{}]".format(section)
             try:
-                for (external_name, internal_name) in tuples:
-                    print "{:-20} = {}".format(external_name, getattr(self, internal_name))
+                for external_name, internal_name in tuples:
+                    print "{:<20} = {}".format(external_name, getattr(self, internal_name))
             except:
-                for name in tuples:
-                    varname = "{}_{}".format(section.upper(), name.upper())
+                print 'failed'
+                for external_name, internal_name in tuples:
+                    varname = "{}_{}".format(section.upper(), external_name.upper())
                     value = getattr(self.config_instance,varname)
-                    print "{:-20} = {}".format(name, value)
+                    print "{:<20} = {}".format(external_name, value)
         # xxx should analyze result
         return 0
 
@@ -1054,12 +1053,12 @@ use this if you mean an authority instead""")
             try:
                 record_filepath = args[0]
                 rec_file = self.get_record_file(record_filepath)
-                record_dict.update(load_record_from_file(rec_file).todict())
+                record_dict.update(load_record_from_file(rec_file).record_to_dict())
             except:
                 print "Cannot load record file {}".format(record_filepath)
                 sys.exit(1)
         if options:
-            record_dict.update(load_record_from_opts(options).todict())
+            record_dict.update(load_record_from_opts(options).record_to_dict())
         # we should have a type by now
         if 'type' not in record_dict :
             self.print_help()
@@ -1086,9 +1085,9 @@ use this if you mean an authority instead""")
         if len(args) > 0:
             record_filepath = args[0]
             rec_file = self.get_record_file(record_filepath)
-            record_dict.update(load_record_from_file(rec_file).todict())
+            record_dict.update(load_record_from_file(rec_file).record_to_dict())
         if options:
-            record_dict.update(load_record_from_opts(options).todict())
+            record_dict.update(load_record_from_opts(options).record_to_dict())
         # at the very least we need 'type' here
         if 'type' not in record_dict or record_dict['type'] is None:
             self.print_help()