Add: script for chaging user role in a sql dump
All checks were successful
/ test (push) Successful in 31s
All checks were successful
/ test (push) Successful in 31s
This commit is contained in:
parent
d870b808cb
commit
35eb3e02b1
1 changed files with 43 additions and 0 deletions
43
PythonScripts/sql_dump_change_role.py
Normal file
43
PythonScripts/sql_dump_change_role.py
Normal file
|
@ -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 <input_file> <output_file> <old_username> <new_username>")
|
||||
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)
|
Loading…
Reference in a new issue