Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import os
- import re
- top_level_decl_re = re.compile(r'^('
- r'class (?P<cname>[A-Za-z0-9_]+)(\(([A-Za-z0-9_.]+(, [A-Za-z0-9_.]+)*)?\))?'
- r'|'
- 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_.\[\]{}"]+)?)*)?\))'
- r':')
- if __name__ == '__main__':
- path = sys.argv[1]
- outdir = sys.argv[2] if len(sys.argv) > 2 else path + '_cut'
- if not os.path.isdir(outdir):
- os.mkdir(outdir)
- outdir += os.sep
- current_out = open(outdir + 'top', 'w')
- print('Processing {}...'.format(path))
- print('- top')
- with open(path, 'r') as input:
- for line in input:
- m = top_level_decl_re.match(line)
- if m:
- name = m.group('cname') or m.group('dname')
- current_out.close()
- print('- {}'.format(name))
- current_out = open(outdir + name, 'w')
- current_out.write(line)
- current_out.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement