You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.6 KiB

  1. from gooey import source_parser
  2. __author__ = 'Chris'
  3. """
  4. Pretty Printing util for inspecting the various ast objects
  5. """
  6. import ast
  7. from _ast import Assign, Call
  8. def pretty_print(node, indent):
  9. d = node.__dict__
  10. for k, v in d.iteritems():
  11. if isinstance(v, list):
  12. print '-' * indent, k, ": "
  13. for i in v:
  14. pretty_print(i, indent + 2)
  15. elif 'ast' in str(type(v)):
  16. pretty_print(v, indent + 2)
  17. else:
  18. print '-' * indent, k, ": ", v
  19. if __name__ == '__main__':
  20. lines = '''
  21. def main():
  22. x = 1
  23. y = 2
  24. foo, doo = ("poo", "poo")
  25. smarser = argparse.ArgumentParser(description='Example Argparse Program', formatter_class=RawDescriptionHelpFormatter)
  26. random_junk = 123412353454356
  27. smarser.add_argument("filename", help="Name of the file you want to read") # positional'
  28. smarser.add_argument("outfile", help="Name of the file where you'll save the output") # positional
  29. bar = x + y
  30. baz = random_junk * 5
  31. '''
  32. lines2 = '''
  33. def main():
  34. try:
  35. foo, doo = ("poo", "poo")
  36. smarser = argparse.ArgumentParser(description='Example Argparse Program', formatter_class=RawDescriptionHelpFormatter)
  37. smarser.add_argument("filename", help="Name of the file you want to read") # positional'
  38. smarser.add_argument("outfile", help="Name of the file where you'll save the output") # positional
  39. smarser.parse_args()
  40. except:
  41. pass
  42. '''
  43. nodes = ast.parse(open(r'C:\Users\Chris\Dropbox\pretty_gui\Gooey\gooey\mockapplications\mockapp_import_argparse.py').read())
  44. pretty_print(nodes, 1)