-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialize_labels.py
68 lines (47 loc) · 1.92 KB
/
initialize_labels.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
author = input("What is your name (author)? ")
package = input("What is the name of your package? ")
replacements = [
("python_console_package", package),
("entrypoint", package),
("Markus Peitl", author)
]
ignore_paths = [
'.git'
]
def perform_replacements(text, replacements):
new_text = text
for replacement in replacements:
new_text = new_text.replace(replacement[0], replacement[1])
return new_text
for root, dirs, file_names in os.walk(".", topdown=True):
is_filtered = any(ignore_path in root for ignore_path in ignore_paths)
if not is_filtered:
renamed_root_path = perform_replacements(root, replacements)
if(root != renamed_root_path):
print(renamed_root_path)
os.rename(root, renamed_root_path)
for root, dirs, file_names in os.walk(".", topdown=True):
is_filtered = any(ignore_path in root for ignore_path in ignore_paths)
if not is_filtered:
for file_name in file_names:
path = os.path.join(root, file_name)
out_path = perform_replacements(path, replacements)
if(path != out_path):
os.rename(path, out_path)
for root, dirs, file_names in os.walk(".", topdown=True):
is_filtered = any(ignore_path in root for ignore_path in ignore_paths)
if not is_filtered:
for file_name in file_names:
path = os.path.join(root, file_name)
try:
content = None
with open(path, 'r') as file:
content = file.read()
if(content is not None and len(content) > 0):
with open(path, 'w+') as file:
content = perform_replacements(content, replacements)
if(content is not None and len(content) > 0):
file.write(content)
except:
print("Binary file")