autopep8
[sfa.git] / clientbin / getNodes.py
index ec2e4a2..89689a5 100644 (file)
@@ -7,6 +7,7 @@ from pprint import pprint
 
 from sfa.util.py23 import StringType
 
+
 def create_parser():
     command = sys.argv[0]
     argv = sys.argv[1:]
@@ -14,27 +15,27 @@ def create_parser():
     description = """getNodes will open a rspec file and print all key/values, or filter results based on a given key or set of keys."""
     parser = OptionParser(usage=usage, description=description)
     parser.add_option("-i", "--infile", dest="infile", default=None,
-                      help = "input rspec file")
+                      help="input rspec file")
     parser.add_option("-t", "--tag", dest="tag", default=None,
-                      help = "filter rspec for this tag")
+                      help="filter rspec for this tag")
     parser.add_option("-a", "--attribute", dest="attribute", default=None,
-                      help = "comma separated list of attributes to display")
+                      help="comma separated list of attributes to display")
     parser.add_option("-r", "--recursive", dest="print_children", default=False,  action="store_true",
-                      help = "print the tag's child nodes")
+                      help="print the tag's child nodes")
 
-    return parser    
+    return parser
 
 
 def print_dict(rdict, options, counter=1):
     print_children = options.print_children
     attributes = []
-    if options.attribute: 
-        attributes = options.attribute.split(',') 
+    if options.attribute:
+        attributes = options.attribute.split(',')
     lists = []
     tab = "    "
-    
+
     if not isinstance(rdict, dict):
-        raise "%s not a dict" % rdict 
+        raise "%s not a dict" % rdict
     for (key, value) in rdict.iteritems():
         if isinstance(value, StringType):
             if (attributes and key in attributes) or not attributes:
@@ -44,29 +45,30 @@ def print_dict(rdict, options, counter=1):
                 if isinstance(listitem, dict):
                     lists.append((key, listitem))
         elif isinstance(value, dict):
-            lists.append((key, value)) 
-    
-    if counter == 1 or print_children: 
+            lists.append((key, value))
+
+    if counter == 1 or print_children:
         for (key, listitem) in lists:
             if isinstance(listitem, dict):
                 print tab * (counter - 1) + key
-                print_dict(listitem, options, counter+1)
+                print_dict(listitem, options, counter + 1)
     elif not attributes or (attributes and 'children' in attributes):
         keys = set([key for (key, listitem) in lists])
-        if keys: print tab * (counter) + "(children: %s)" % (",".join(keys))    
-        
+        if keys:
+            print tab * (counter) + "(children: %s)" % (",".join(keys))
+
 
 #
 # this code probably is obsolete
 # RSpec is not imported, it does not have a toDict() method anyway
 # plus, getNodes.py is not exposed in packaging
-# 
+#
 def main():
-    parser = create_parser()
+    parser = create_parser()
     (options, args) = parser.parse_args()
     if not options.infile:
         print "RSpec file not specified"
-        return 
+        return
 
     rspec = RSpec()
     try:
@@ -79,14 +81,15 @@ def main():
         rspec_dicts = rspec.getDictsByTagName(tag_name)
         rspec_dict = {tag_name: rspec_dicts}
     else:
-        rspec_dict = rspec.toDict()  
-  
+        rspec_dict = rspec.toDict()
+
     print_dict(rspec_dict, options)
 
     return
 
 if __name__ == '__main__':
-    try: main()
+    try:
+        main()
     except Exception as e:
         raise
         print e