Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import sys
  2. import os
  3. import re
  4.  
  5. top_level_decl_re = re.compile(r'^('
  6. r'class (?P<cname>[A-Za-z0-9_]+)(\(([A-Za-z0-9_.]+(, [A-Za-z0-9_.]+)*)?\))?'
  7. r'|'
  8. r'def (?P<dname>[A-Za-z0-9_]+)\((\*{0,2}[A-Za-z0-9_.]+(=[A-Za-z0-9_.\[\]{}"]+)?(, \*{0,2}[A-Za-z0-9_.]+(=[A-Za-z0-9_.\[\]{}"]+)?)*)?\))'
  9. r':')
  10.  
  11. if __name__ == '__main__':
  12. path = sys.argv[1]
  13. outdir = sys.argv[2] if len(sys.argv) > 2 else path + '_cut'
  14. if not os.path.isdir(outdir):
  15. os.mkdir(outdir)
  16. outdir += os.sep
  17. current_out = open(outdir + 'top', 'w')
  18. print('Processing {}...'.format(path))
  19. print('- top')
  20. with open(path, 'r') as input:
  21. for line in input:
  22. m = top_level_decl_re.match(line)
  23. if m:
  24. name = m.group('cname') or m.group('dname')
  25. current_out.close()
  26. print('- {}'.format(name))
  27. current_out = open(outdir + name, 'w')
  28. current_out.write(line)
  29. current_out.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement