-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathremove_all_py__author__.py
44 lines (27 loc) · 1022 Bytes
/
remove_all_py__author__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "ipetrash"
import re
import shutil
from pathlib import Path
TEMPLATE_DIR = "No __author__ in {path}"
def process_file(file_name: Path):
text = file_name.read_text("utf-8")
text = re.sub(r"__author__ = .+", "", text)
text = re.sub(r"\n{4,}", "\n\n\n", text)
file_name.write_text(text, "utf-8")
def run(path: str):
path = Path(path)
if not path.exists():
raise Exception(f"Not found {path}!")
if not path.is_dir():
raise Exception(f"Must be directory: {path}!")
dir_path = path.parent
copy_dir_path = dir_path / (TEMPLATE_DIR.format(path=path.name))
shutil.rmtree(copy_dir_path, ignore_errors=True)
shutil.copytree(path, copy_dir_path)
# Удалить из всех ее файлов указание автора
for file_name in copy_dir_path.rglob("*.py"):
process_file(file_name)
if __name__ == "__main__":
run(r"C:\Users\ipetrash\PycharmProjects\SNMP_monitor")