mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2024-11-21 16:01:03 +01:00
Removed unecessary host from seeder function
This commit is contained in:
parent
e2e62c5835
commit
bf9986f282
@ -2,17 +2,17 @@ import pandas as pd
|
||||
import argparse
|
||||
import os
|
||||
|
||||
def check_and_add_entry(file_path, instance, host, database, username, password):
|
||||
def check_and_add_entry(file_path, instance, database, username, password):
|
||||
# Check if the file exists and is not empty
|
||||
if os.path.exists(file_path) and os.path.getsize(file_path) > 0:
|
||||
# Read the existing CSV file with header
|
||||
df = pd.read_csv(file_path, sep=';')
|
||||
else:
|
||||
# Create a new DataFrame with columns if file does not exist
|
||||
df = pd.DataFrame(columns=['instance','host', 'database', 'username', 'password'])
|
||||
df = pd.DataFrame(columns=['instance', 'database', 'username', 'password'])
|
||||
|
||||
# Check if the entry exists and remove it
|
||||
mask = (df['instance'] == instance) & (df['host'] == host) & (df['database'] == database) & (df['username'] == username)
|
||||
mask = (df['instance'] == instance) & (df['database'] == database) & (df['username'] == username)
|
||||
if not df[mask].empty:
|
||||
print("Replacing existing entry.")
|
||||
df = df[~mask]
|
||||
@ -20,7 +20,7 @@ def check_and_add_entry(file_path, instance, host, database, username, password)
|
||||
print("Adding new entry.")
|
||||
|
||||
# Create a new DataFrame for the new entry
|
||||
new_entry = pd.DataFrame([{'instance': instance, 'host': host, 'database': database, 'username': username, 'password': password}])
|
||||
new_entry = pd.DataFrame([{'instance': instance, 'database': database, 'username': username, 'password': password}])
|
||||
|
||||
# Add (or replace) the entry using concat
|
||||
df = pd.concat([df, new_entry], ignore_index=True)
|
||||
@ -32,14 +32,13 @@ def main():
|
||||
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("instance", help="Database instance")
|
||||
parser.add_argument("host", help="Database host")
|
||||
parser.add_argument("database", help="Database name")
|
||||
parser.add_argument("username", help="Username")
|
||||
parser.add_argument("password", nargs='?', default="", help="Password (optional)")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
check_and_add_entry(args.file_path, args.instance, args.host, args.database, args.username, args.password)
|
||||
check_and_add_entry(args.file_path, args.instance, args.database, args.username, args.password)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user