-
Notifications
You must be signed in to change notification settings - Fork 7
/
create_ln.py
41 lines (34 loc) · 1.03 KB
/
create_ln.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
#!/usr/bin/env python3
import os
from pathlib import Path
"""
Use for Nginx deployment.
After add new file in /etc/nginx/sites-avaliable/,
run this script to create soft link into ../sites-enabled/
"""
def run_and_echo(cmd: str) -> int:
print("-->", cmd)
return os.system(cmd)
def main():
pwd = Path(__file__).resolve().parent
dirname = "sites-avaliable"
if pwd.name != dirname:
pwd = pwd.with_name(dirname)
if not pwd.exists():
pwd = Path("/etc/nginx/") / dirname
target = pwd.parent / "sites-enabled"
count = linked = 0
for i in pwd.glob("*.*"):
name = i.name
if name.endswith(".bak") or name.endswith(".py"):
continue
count += 1
p = target.joinpath(name)
if not p.exists():
print(f"creating ln of {name} ...")
run_and_echo(f"sudo ln -s {i} {p}")
linked += 1
if not linked:
print(f"{count} conf files found, but no one need to create soft link.")
if __name__ == "__main__":
main()