Skip to content

Commit

Permalink
chore: make catalog file name into a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoGuadrini committed Feb 8, 2024
1 parent e12eef0 commit 882f3a4
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions bb.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,9 @@ def get_restore_os():
Get the operating system value on catalog by id
:return: os value (string)
"""
global args
global args, catalog_file

config = read_catalog(os.path.join(args.catalog, ".catalog.cfg"))
config = read_catalog(os.path.join(args.catalog, catalog_file))
return config.get(args.id, "os")


Expand Down Expand Up @@ -1659,6 +1659,7 @@ def main():
# Create arguments object
parser = parse_arguments()
args = parser.parse_args()
catalog_file = ".catalog.cfg"

try:
# Check config session
Expand All @@ -1670,20 +1671,20 @@ def main():
elif args.deploy_host:
deploy_configuration(args.deploy_host, args.deploy_user)
elif args.init:
catalog_path = os.path.join(args.init, ".catalog.cfg")
catalog_path = os.path.join(args.init, catalog_file)
init_catalog(catalog_path)
elif args.delete:
catalog_path = os.path.join(args.delete[0], ".catalog.cfg")
catalog_path = os.path.join(args.delete[0], catalog_file)
delete_host(catalog_path, args.delete[1])
elif args.delete_backup:
catalog_path = os.path.join(args.delete_backup[0], ".catalog.cfg")
catalog_path = os.path.join(args.delete_backup[0], catalog_file)
delete_backup(catalog_path, args.delete_backup[1])
elif args.clean:
catalog_path = os.path.join(args.clean, ".catalog.cfg")
catalog_path = os.path.join(args.clean, catalog_file)
clean_catalog(catalog_path)
else:
parser.print_usage()
print("For config usage, --help or -h")
utility.error("For config usage, --help or -h")
exit(1)

# Check backup session
Expand Down Expand Up @@ -1738,7 +1739,7 @@ def main():
),
}
logs.append(log_args)
catalog_path = os.path.join(args.destination, ".catalog.cfg")
catalog_path = os.path.join(args.destination, catalog_file)
backup_catalog = read_catalog(catalog_path)
# Compose command
cmd = compose_command(args, hostname)
Expand Down Expand Up @@ -1817,7 +1818,7 @@ def main():
if not args.type and args.id:
args.type = get_restore_os()
# Read catalog file
catalog_path = os.path.join(args.catalog, ".catalog.cfg")
catalog_path = os.path.join(args.catalog, catalog_file)
restore_catalog = read_catalog(catalog_path)
# Check if select backup-id or last backup
if args.last:
Expand Down Expand Up @@ -1941,7 +1942,7 @@ def main():
"destination": os.path.join(args.catalog, "archive.log"),
}
# Read catalog file
archive_catalog = os.path.join(args.catalog, ".catalog.cfg")
archive_catalog = os.path.join(args.catalog, catalog_file)
# Archive paths
archive_policy(archive_catalog, args.destination)

Expand All @@ -1953,7 +1954,7 @@ def main():
"destination": os.path.join(args.catalog, "backup.list"),
}
# Read catalog file
list_catalog = read_catalog(os.path.join(args.catalog, ".catalog.cfg"))
list_catalog = read_catalog(os.path.join(args.catalog, catalog_file))
# Check specified argument backup-id
if args.id:
# Get session backup id
Expand Down Expand Up @@ -2203,7 +2204,7 @@ def main():
check_rsync(rsync_path)
cmds = list()
# Read catalog file
catalog_path = os.path.join(args.catalog, ".catalog.cfg")
catalog_path = os.path.join(args.catalog, catalog_file)
export_catalog = read_catalog(catalog_path)
# Create destination folder if not exists
if not os.path.exists(args.destination):
Expand Down Expand Up @@ -2275,18 +2276,18 @@ def main():
# Check cut option
if args.cut:
write_catalog(
os.path.join(args.catalog, ".catalog.cfg"),
os.path.join(args.catalog, catalog_file),
args.id,
"cleaned",
"True",
)
# Start export
cmds.append(" ".join(cmd))
run_in_parallel(start_process, cmds, 1)
if os.path.exists(os.path.join(args.destination, ".catalog.cfg")):
if os.path.exists(os.path.join(args.destination, catalog_file)):
# Migrate catalog to new file system
utility.find_replace(
os.path.join(args.destination, ".catalog.cfg"),
os.path.join(args.destination, catalog_file),
args.catalog.rstrip("/"),
args.destination.rstrip("/"),
)
Expand Down

0 comments on commit 882f3a4

Please sign in to comment.