guru_sdk/guru_app/tools/bin/update_repo_url

36 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python3
import os,sys,re
print("Input argument is %s" %(sys.argv[1:]))
arguments = sys.argv[1:]
if (len(arguments) != 2):
print("Arguments Invalid!")
sys.exit()
findrepo = sys.argv[1]
newrepo = sys.argv[2]
print(f"upgrade {findrepo}.git library to {newrepo}")
# Get the current directory
current_dir = os.getcwd()
# Iterate through all files in the directory
for dirpath, dirnames, filenames in os.walk(current_dir):
# Check if the file is a pubspec.yaml file
for filename in filenames:
if filename == "pubspec.yaml":
# Open the pubspec.yaml file
file_path = os.path.join(dirpath, filename)
with open(file_path, 'r') as file:
# Read the contents of the file
filedata = file.read()
# Replace the ref value for the libraries with git link that contains "example.com"
filedata = re.sub(fr"(.*url: )(.*{findrepo}.*)", fr'\1{newrepo}', filedata)
# Write the file out again
with open(file_path, 'w') as file:
file.write(filedata)
print(f"Upgrade Completed => {file_path}")