-k removes keys
authorFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Thu, 18 Jun 2009 21:19:22 +0000 (21:19 +0000)
committerFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Thu, 18 Jun 2009 21:19:22 +0000 (21:19 +0000)
cmdline/getRecord.py

index 3e4c068..e048742 100755 (executable)
@@ -28,38 +28,42 @@ def create_parser():
     parser.add_option("-d", "--debug", dest="DEBUG", action="store_true",
         default=False,  help = "record file path")
     parser.add_option("-k", "--key", dest="withkey", action="store_true",
-        default=False,  help = "print keys")
+        default=False,  help = "print SSH keys and certificates")
+    parser.add_option("-p", "--plinfo", dest="plinfo", action="store_true",
+        default=False,  help = "print PlanetLab specific internal fields")
    
     return parser    
 
+
 def printRec(record, filters, options):
     line = ""
     if len(filters):
         for filter in filters:
             if options.DEBUG:  print "Filtering on %s" %filter
-            if options.withkey:
-                line += "%s: " %filter
-            line += "%s\n" % \
-                printVal(record.dict["record"].get(filter, None))
-            print line
+            line += "%s: %s\n" % (filter, 
+                printVal(record.dict["record"].get(filter, None)))
+        print line
     else:
         # print the wole thing
         for (key, value) in record.dict["record"].iteritems():
-            if options.withkey:
-                line += "%s: " % key
-            line += "%s\n" % printVal(value)
+            if (not options.withkey and key in ('gid', 'keys')) or\
+                (not options.plinfo and key == 'pl_info'):
+                continue
+            line += "%s: %s\n" % (key, printVal(value))
         print line
 
+
 # fix the iteratable values
 def printVal(value):
     line = ""
     if type(value) in (tuple, list):
         for i in value:
             line += "%s " % i
-    else:
+    elif value != None:
         line += value
     return line.rstrip("\n")
 
+
 def main():
     parser = create_parser(); 
     (options, args) = parser.parse_args()