review on imports & svn keywords
[sfa.git] / geni / util / rspec.py
index f945330..a184dc0 100644 (file)
@@ -1,3 +1,6 @@
+### $Id$
+### $URL$
+
 import sys
 import pprint
 import os
@@ -288,9 +291,30 @@ class Rspec():
             'EDate' : date}
 
 
+    def pprint(self, r = None, depth = 0):
+        """
+        Pretty print the dict
+        """
+        line = ""
+        if r == None: r = self.dict
+        # Set the dept
+        for tab in range(0,depth): line += "    "
+        # check if it's nested
+        if type(r) == dict:
+            for i in r.keys():
+                print line + "%s:" % i
+                self.pprint(r[i], depth + 1)
+        elif type(r) in (tuple, list):
+            for j in r: self.pprint(j, depth + 1)
+        # not nested so just print.
+        else:
+            print line + "%s" %  r
+    
+
 
 class RecordSpec(Rspec):
 
+    root_tag = 'record'
     def parseDict(self, rdict, include_doc = False):
         """
         Convert a dictionary into a dom object and store it.
@@ -298,7 +322,11 @@ class RecordSpec(Rspec):
         self.rootNode = self.dict2dom(rdict, include_doc)
 
     def dict2dom(self, rdict, include_doc = False):
-        record_dict = {'': rdict}
+        record_dict = rdict
+        if not len(rdict.keys()) == 1:
+            record_dict = {self.root_tag : rdict}
         return Rspec.dict2dom(self, record_dict, include_doc)
+
         
 # vim:ts=4:expandtab
+