forked from SagerNet/wireguard-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
module_rename.py
33 lines (24 loc) · 954 Bytes
/
module_rename.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import argparse
import fileinput
PKG_ORIGINAL = "golang.zx2c4.com/wireguard"
PKG_NEW = "github.com/sagernet/wireguard-go"
EXTENSIONS = [".go", ".md", ".mod", ".sh"]
parser = argparse.ArgumentParser()
parser.add_argument("-r", "--reverse", action="store_true")
args = parser.parse_args()
def replace_line(line):
if args.reverse:
return line.replace(PKG_NEW, PKG_ORIGINAL)
return line.replace(PKG_ORIGINAL, PKG_NEW)
for dirpath, dirnames, filenames in os.walk("."):
# Skip hidden directories like .git
dirnames[:] = [d for d in dirnames if not d[0] == "."]
filenames = [f for f in filenames if os.path.splitext(f)[1] in EXTENSIONS]
for filename in filenames:
file_path = os.path.join(dirpath, filename)
with fileinput.FileInput(file_path, inplace=True) as file:
for line in file:
print(replace_line(line), end="")