Last active
October 30, 2023 22:52
-
-
Save KimSarabia/3743bbb182a756b4cb135cc4c4190654 to your computer and use it in GitHub Desktop.
Script accepts a list of database names from a .txt file and perform the add or del operation on a specified dblist (e.g., legacy-vector).
This file contains hidden or 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
import subprocess | |
import argparse | |
# Command: `python bulk_removal.py del dbnames.txt legacy-vector` | |
def execute_composer_commands(operation, dblist_file, dblist_name): | |
# Check if the operation is valid | |
if operation not in ("add", "del"): | |
print("Invalid operation. Use 'add' or 'del'.") | |
return | |
try: | |
with open(dblist_file, "r") as file: | |
for line in file: | |
dbname = line.strip() | |
command = f"composer manage-dblist {operation} {dbname} {dblist_name}" | |
try: | |
# Execute the command | |
subprocess.run(command, shell=True, check=True) | |
print(f"Executed: {command}") | |
except subprocess.CalledProcessError as e: | |
print(f"Error executing command: {e}") | |
except FileNotFoundError: | |
print(f"File not found: {dblist_file}") | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description="Execute Composer manage-dblist commands on a list of databases.") | |
parser.add_argument("operation", choices=["add", "del"], help="Operation: 'add' or 'del'") | |
parser.add_argument("dblist_file", help="Path to a .txt file containing a list of database names") | |
parser.add_argument("dblist_name", help="Dblist name for the operation") | |
args = parser.parse_args() | |
execute_composer_commands(args.operation, args.dblist_file, args.dblist_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice!