github.com/sagernet/wireguard-go@v0.0.0-20231215174105-89dec3b2f3e8/module_rename.py (about) 1 #!/usr/bin/env python3 2 # -*- coding: utf-8 -*- 3 4 import os 5 import argparse 6 import fileinput 7 8 9 PKG_ORIGINAL = "golang.zx2c4.com/wireguard" 10 PKG_NEW = "github.com/sagernet/wireguard-go" 11 12 EXTENSIONS = [".go", ".md", ".mod", ".sh"] 13 14 parser = argparse.ArgumentParser() 15 parser.add_argument("-r", "--reverse", action="store_true") 16 args = parser.parse_args() 17 18 19 def replace_line(line): 20 if args.reverse: 21 return line.replace(PKG_NEW, PKG_ORIGINAL) 22 return line.replace(PKG_ORIGINAL, PKG_NEW) 23 24 25 for dirpath, dirnames, filenames in os.walk("."): 26 # Skip hidden directories like .git 27 dirnames[:] = [d for d in dirnames if not d[0] == "."] 28 filenames = [f for f in filenames if os.path.splitext(f)[1] in EXTENSIONS] 29 for filename in filenames: 30 file_path = os.path.join(dirpath, filename) 31 with fileinput.FileInput(file_path, inplace=True) as file: 32 for line in file: 33 print(replace_line(line), end="")