sfadump -x to show a full xml dump of credentials
Thierry Parmentelat [Wed, 19 Sep 2012 10:09:07 +0000 (12:09 +0200)]
clientbin/sfadump.py
sfa/trust/credential.py

index b366aec..57fdf79 100755 (executable)
@@ -88,7 +88,7 @@ def handle_input_kind (filename, options, kind):
     elif kind=="credential":
         cred = Credential(filename = filename)
         print '--------------------',filename,'IS A',kind
-        cred.dump(dump_parents = options.dump_parents)
+        cred.dump(dump_parents = options.dump_parents, show_xml=options.show_xml)
         if options.extract_gids:
             print '--------------------',filename,'embedded GIDS'
             extract_gids(cred, extract_parents = options.dump_parents)
@@ -107,7 +107,8 @@ display info on input files"""
     parser.add_option("-g", "--extract-gids", action="store_true", dest="extract_gids", default=False, help="Extract GIDs from credentials")
     parser.add_option("-p", "--dump-parents", action="store_true", dest="dump_parents", default=False, help="Show parents")
     parser.add_option("-e", "--extensions", action="store_true", dest="show_extensions", default="False", help="Show certificate extensions")
-    parser.add_option("-v", "--verbose", action='count', dest='verbose', default=0)
+    parser.add_option("-v", "--verbose", action='count', dest='verbose', default=0, help="More and more verbose")
+    parser.add_option("-x", "--xml", action='store_true', dest='show_xml', default=False, help="dumps xml tree (cred. only)")
     (options, args) = parser.parse_args()
 
     logger.setLevelFromOptVerbose(options.verbose)
index a32a49a..01542a0 100644 (file)
@@ -1037,7 +1037,7 @@ class Credential(object):
         print self.dump_string(*args, **kwargs)
 
 
-    def dump_string(self, dump_parents=False):
+    def dump_string(self, dump_parents=False, show_xml=False):
         result=""
         result += "CREDENTIAL %s\n" % self.get_subject()
         filename=self.get_filename()
@@ -1061,4 +1061,16 @@ class Credential(object):
             result += "\nPARENT"
             result += self.parent.dump_string(True)
 
+        if show_xml:
+            try:
+                tree = etree.parse(StringIO(self.xml))
+                aside = etree.tostring(tree, pretty_print=True)
+                result += "\nXML\n"
+                result += aside
+                result += "\nEnd XML\n"
+            except:
+                import traceback
+                print "exc. Credential.dump_string / XML"
+                traceback.print_exc()
+
         return result