Skip to content

Commit

Permalink
Add module_rename.py
Browse files Browse the repository at this point in the history
(cherry picked from commit 19e12c3)
  • Loading branch information
nekohasekai committed May 31, 2024
1 parent eaca3b2 commit 6da448a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions module_rename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import argparse
import fileinput


PKG_ORIGINAL = "github.com/google/nftables"
PKG_NEW = "github.com/sagernet/nftables"

EXTENSIONS = [".go", ".mod"]

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="")

0 comments on commit 6da448a

Please sign in to comment.