Add module_rename.py
This commit is contained in:
parent
177dea9806
commit
dfa4a8968f
1 changed files with 33 additions and 0 deletions
33
module_rename.py
Normal file
33
module_rename.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import argparse
|
||||
import fileinput
|
||||
|
||||
|
||||
PKG_ORIGINAL = "github.com/tailscale/wireguard-go"
|
||||
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="")
|
||||
Loading…
Add table
Add a link
Reference in a new issue