forked from google/nftables
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="") |