Page MenuHomeDevCentral
Paste P349

credentials-repo-replace.py
ActivePublic

Authored by dereckson on Jan 28 2024, 19:30.
Tags
None
Referenced Files
F2582513: credentials-repo-replace.py
Jan 28 2024, 19:30
Subscribers
None
#!/usr/bin/env python3
import sys
# -------------------------------------------------------------
# Migrate : string replacement
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def migrate_all(orig_list, dest_list):
for orig, dest in zip(orig_list, dest_list):
migrate(orig, dest)
def migrate(orig, dest):
orig_re = orig.replace(".", "\.")
print(f"rg -l -F {orig} | xargs gsed -i s@{orig_re}@{dest}@g")
# -------------------------------------------------------------
# Application entry point
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def run(orig_file, dest_file):
orig_list = [line.strip() for line in open(orig_file)]
dest_list = [line.strip() for line in open(dest_file)]
migrate_all(orig_list, dest_list)
if __name__ == "__main__":
run("from", "to")