OLD | NEW |
(Empty) | |
| 1 from __future__ import print_function |
| 2 import sys |
| 3 import os |
| 4 import argparse |
| 5 from .unparser import roundtrip |
| 6 from . import dump |
| 7 |
| 8 |
| 9 def roundtrip_recursive(target, dump_tree=False): |
| 10 if os.path.isfile(target): |
| 11 print(target) |
| 12 print("=" * len(target)) |
| 13 if dump_tree: |
| 14 dump(target) |
| 15 else: |
| 16 roundtrip(target) |
| 17 print() |
| 18 elif os.path.isdir(target): |
| 19 for item in os.listdir(target): |
| 20 if item.endswith(".py"): |
| 21 roundtrip_recursive(os.path.join(target, item), dump_tree) |
| 22 else: |
| 23 print( |
| 24 "WARNING: skipping '%s', not a file or directory" % target, |
| 25 file=sys.stderr |
| 26 ) |
| 27 |
| 28 |
| 29 def main(args): |
| 30 parser = argparse.ArgumentParser(prog="astunparse") |
| 31 parser.add_argument( |
| 32 'target', |
| 33 nargs='+', |
| 34 help="Files or directories to show roundtripped source for" |
| 35 ) |
| 36 parser.add_argument( |
| 37 '--dump', |
| 38 type='bool', |
| 39 help="Show a pretty-printed AST instead of the source" |
| 40 ) |
| 41 |
| 42 arguments = parser.parse_args(args) |
| 43 for target in arguments.target: |
| 44 roundtrip_recursive(target, dump_tree=arguments.dump) |
| 45 |
| 46 |
| 47 if __name__ == "__main__": |
| 48 main(sys.argv[1:]) |
OLD | NEW |