-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_quickstart.py
More file actions
67 lines (59 loc) · 2.18 KB
/
_quickstart.py
File metadata and controls
67 lines (59 loc) · 2.18 KB
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
# coding: utf-8
import os
import re
from pathlib import Path
CONFIGURATION = {}
HERE = os.path.abspath(os.path.dirname(__file__))
def set_configuration() -> None:
REPOSITORY_NAME = os.path.basename(HERE)
PACKAGE_NAME = input(f"> Package Name ({REPOSITORY_NAME}): ")
if len(PACKAGE_NAME) == 0:
PACKAGE_NAME = REPOSITORY_NAME
PACKAGE_NAME_CODE = PACKAGE_NAME.replace("-", "")
AUTHOR = input("> Author (GitHub username): @")
CONFIGURATION.update(
{
"REPOSITORY_NAME": REPOSITORY_NAME,
"PACKAGE_NAME": PACKAGE_NAME,
"PACKAGE_NAME_CODE": PACKAGE_NAME_CODE,
"MODULE_NAME": input("> Module Name: "),
"DESCRIPTION": input("> Description: "),
"AUTHOR": AUTHOR,
"AUTHOR_EMAIL": input("> Author's Email: "),
"TWITTER_USERNAME": input("> Twitter Username: @"),
"PROJECT_URL": f"https://github.com/{ AUTHOR }/{REPOSITORY_NAME}",
"DOCUMENTATION_URL": f"https://{ AUTHOR }.github.io/{REPOSITORY_NAME}"
}
)
def replace(match: re.Match) -> str:
before: str = match.group(1)
after: str = CONFIGURATION.get(before)
if after is None:
after = match.group(0)
else:
print(f"\tRenamed from {before} to {after}")
return after
def rename(string: str) -> str:
return re.sub(
pattern=r"{{(?:\s+)?([A-Z_]+?)(?:\s+)?}}", repl=replace, string=string
)
if __name__ == "__main__":
set_configuration()
p = Path(HERE)
for path in p.glob("**/*"):
rela_path = str(path.resolve().relative_to(HERE))
if path.is_dir():
dirname = rename(rela_path)
if rela_path != dirname:
path.rename(dirname)
print(f"\033[32m[DIR]\033[0m renamed from {rela_path} to {dirname}")
elif path.is_file():
try:
with path.open(mode="r") as f:
lines = f.readlines()
print(f"\033[34m[FILE]\033[0m: {rela_path}")
lines = [rename(e) for e in lines]
with path.open(mode="w") as f:
f.writelines(lines)
except Exception as e:
pass