From 35eb3e02b197095f95d2661c7d001116334aaef3 Mon Sep 17 00:00:00 2001 From: Aroy-Art Date: Sat, 9 Mar 2024 21:59:43 +0100 Subject: [PATCH] Add: script for chaging user role in a sql dump --- PythonScripts/sql_dump_change_role.py | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 PythonScripts/sql_dump_change_role.py diff --git a/PythonScripts/sql_dump_change_role.py b/PythonScripts/sql_dump_change_role.py new file mode 100644 index 0000000..480efcf --- /dev/null +++ b/PythonScripts/sql_dump_change_role.py @@ -0,0 +1,43 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +import sys + +def update_sql_dump(input_file, output_file, old_username, new_username): + try: + # Open input and output files + with open(input_file, 'r') as f_in, open(output_file, 'w') as f_out: + # Iterate through each line in the input file + for line in f_in: + # Replace old username with new username in each line + new_line = line.replace(old_username, new_username) + # Write the modified line to the output file + f_out.write(new_line) + # Print the changed line + if line != new_line: + print("Changed Line:") + print("Old: ", line.strip()) + print("New: ", new_line.strip()) + + print("SQL dump file updated successfully.") + + except FileNotFoundError: + print("Input file not found. Please make sure the input file path is correct.") + + except Exception as e: + print("An error occurred:", str(e)) + +if __name__ == "__main__": + # Check if correct number of arguments provided + if len(sys.argv) != 5: + print("Usage: python sql_dump_change_role.py ") + sys.exit(1) + + # Extract arguments + input_file = sys.argv[1] + output_file = sys.argv[2] + old_username = sys.argv[3] + new_username = sys.argv[4] + + # Call function to update SQL dump + update_sql_dump(input_file, output_file, old_username, new_username)