Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import re
- import os
- import sys
- multiline_coment = re.compile(r'/\*\*.+?\*/', flags=re.DOTALL)
- extensions = tuple('.' + ext for ext in (
- 'java',
- ))
- arg_path = sys.argv[1]
- def is_supported_filetype(file_name: str) -> bool:
- return any(map(file_name.endswith, extensions))
- def apply_tranformations(file_name: str, transforms: tuple) -> None:
- with open(file_name, 'r+') as fh:
- file_content = fh.read()
- for trans in transforms:
- file_content = trans(file_content)
- fh.seek(0)
- fh.truncate()
- fh.write(file_content)
- def remove_multiline_comments(s: str) -> str:
- return multiline_coment.sub('', s)
- if os.path.isdir(arg_path):
- for path, _, files in os.walk(arg_path):
- for file in files:
- if is_supported_filetype(file):
- apply_tranformations(os.path.join(path, file), (remove_multiline_comments,))
- elif os.path.isfile(arg_path):
- apply_tranformations(arg_path, (remove_multiline_comments,))
- else:
- print(f'Are you kidding me? {arg_path}')
Add Comment
Please, Sign In to add comment