mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2024-11-22 08:21:04 +01:00
Solved replacement bug
This commit is contained in:
parent
d4799af904
commit
8c4785dfe6
@ -8,20 +8,23 @@ def check_and_add_entry(file_path, host, database, username, password):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
df = pd.DataFrame(columns=['host', 'database', 'username', 'password'])
|
df = pd.DataFrame(columns=['host', 'database', 'username', 'password'])
|
||||||
|
|
||||||
# Check if the entry exists
|
# Check if the entry exists and remove it
|
||||||
mask = (df['host'] == host) & (df['database'] == database) & (df['username'] == username) & (df['password'] == password)
|
mask = (df['host'] == host) & (df['database'] == database) & (df['username'] == username)
|
||||||
if not df[mask].empty:
|
if not df[mask].empty:
|
||||||
print("Entry already exists.")
|
print("Replacing existing entry.")
|
||||||
|
df = df[~mask]
|
||||||
else:
|
else:
|
||||||
# Add the new entry
|
print("Adding new entry.")
|
||||||
new_entry = {'host': host, 'database': database, 'username': username, 'password': password}
|
|
||||||
df = df.append(new_entry, ignore_index=True)
|
# Add (or replace) the entry
|
||||||
# Save the updated CSV file
|
new_entry = {'host': host, 'database': database, 'username': username, 'password': password}
|
||||||
df.to_csv(file_path, sep=';', index=False)
|
df = df.append(new_entry, ignore_index=True)
|
||||||
print("New entry added.")
|
|
||||||
|
# Save the updated CSV file
|
||||||
|
df.to_csv(file_path, sep=';', index=False)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Check and add a database entry to a CSV file.")
|
parser = argparse.ArgumentParser(description="Check and replace (or add) a database entry in a CSV file.")
|
||||||
parser.add_argument("file_path", help="Path to the CSV file")
|
parser.add_argument("file_path", help="Path to the CSV file")
|
||||||
parser.add_argument("host", help="Database host")
|
parser.add_argument("host", help="Database host")
|
||||||
parser.add_argument("database", help="Database name")
|
parser.add_argument("database", help="Database name")
|
||||||
|
Loading…
Reference in New Issue
Block a user