From 96da23c9ae01fed8b0ebf957e128ca1ebf42ad27 Mon Sep 17 00:00:00 2001 From: Faiyaz Ahmed Date: Mon, 15 Jun 2009 20:15:56 +0000 Subject: [PATCH] Move printRecord into rspec class (as pprint). --- cmdline/getRecord.py | 20 ++------------------ cmdline/setRecord.py | 17 ++--------------- geni/util/rspec.py | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/cmdline/getRecord.py b/cmdline/getRecord.py index 12971d9e..24b2ac90 100755 --- a/cmdline/getRecord.py +++ b/cmdline/getRecord.py @@ -32,22 +32,6 @@ def create_parser(): return parser -def printRecord(r, depth = 0): - line = "" - # 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 - printRecord(r[i], depth + 1) - elif type(r) in (tuple, list): - for j in r: printRecord(j, depth + 1) - # not nested so just print. - else: - print line + "%s" % r - - def findRoot(r, filter): root = None if type(r) == dict: @@ -88,9 +72,9 @@ def main(): if options.DEBUG: print "Filtering on key: %s" % args[0] pprint(findRoot(record.dict, args[0])) - printRecord({args[0]: findRoot(record.dict, args[0])}) + record.pprint({args[0]: findRoot(record.dict, args[0])}) else: - printRecord(record.dict) + record.pprint(record.dict) if __name__ == '__main__': try: main() diff --git a/cmdline/setRecord.py b/cmdline/setRecord.py index c710be15..91237c26 100755 --- a/cmdline/setRecord.py +++ b/cmdline/setRecord.py @@ -32,20 +32,6 @@ def create_parser(): return parser -def printRecord(r, depth = 0): - line = "" - # 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 - printRecord(r[i], depth + 1) - elif type(r) in (tuple, list): - for j in r: printRecord(j, depth + 1) - # not nested so just print. - else: - print line + "%s" % r def editDict(replacewith, recordDict, options): # first we find the part of the tree we want to replace @@ -96,7 +82,8 @@ def main(): if options.DEBUG: print "New Record:\n%s" % record.dict - printRecord(record.dict) + record.pprint() + record.rootNode = record.dict2dom(record.dict) s = record.toxml() f = open(options.infile,"w") diff --git a/geni/util/rspec.py b/geni/util/rspec.py index 393d8df5..b4c339b9 100644 --- a/geni/util/rspec.py +++ b/geni/util/rspec.py @@ -288,6 +288,26 @@ 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): @@ -303,6 +323,7 @@ class RecordSpec(Rspec): if not len(rdict.keys()) == 1: record_dict = {self.root_tag : rdict} return Rspec.dict2dom(self, record_dict, include_doc) + # vim:ts=4:expandtab -- 2.43.0