[manage.py] Add command arguments for action & target projects

This commit is contained in:
Viyurz 2024-10-08 20:38:06 +02:00
parent 252c827d92
commit 5993328cdb
Signed by: Viyurz
SSH key fingerprint: SHA256:IskOHTmhHSJIvAt04N6aaxd5SZCVWW1Guf9tEcxIMj8

View file

@ -300,28 +300,37 @@ def main():
print("\nUsing socket " + env['socket'] + ".") print("\nUsing socket " + env['socket'] + ".")
print("\nChoose action:")
print("[1/S] Setup project")
print("[2/U] Update project")
print("[3/B] Backup project")
action = '' action = ''
if len(sys.argv) > 1:
action = sys.argv[1]
else:
print("\nChoose action:")
print("[1/S] Setup project")
print("[2/U] Update project")
print("[3/B] Backup project")
while action == '': while action == '':
action = input("Action: ") action = input("Action: ")
projects = os.listdir("projects") projects = os.listdir("projects")
print(f"\nProjects list: {projects}") print(f"\nProjects list: {projects}")
if len(sys.argv) > 2:
target_projects = input("Target compose project(s), space separated, leave empty to target all: ") target_projects = sys.argv[2]
else:
target_projects = input("Target compose project(s), space separated, leave empty to target all: ")
if target_projects == '': if target_projects == '':
target_projects = projects target_projects = projects
else: else:
target_projects = target_projects.split(' ') target_projects = re.split(' ?, ?| ', target_projects.strip())
print(f"Target projects: {target_projects}") print(f"Target projects: {target_projects}")
match action:
case '1' | 'S': match action.casefold():
case '1' | 's' | 'setup':
setNftables() setNftables()
for project in target_projects: for project in target_projects:
@ -332,7 +341,7 @@ def main():
print(e, file=sys.stderr) print(e, file=sys.stderr)
print(f"Failed to setup project {project}.", file=sys.stderr) print(f"Failed to setup project {project}.", file=sys.stderr)
case '2' | 'U': case '2' | 'u' | 'update':
for project in target_projects: for project in target_projects:
try: try:
print() print()
@ -341,7 +350,7 @@ def main():
print(e, file=sys.stderr) print(e, file=sys.stderr)
print(f"Failed to update project {project}.", file=sys.stderr) print(f"Failed to update project {project}.", file=sys.stderr)
case '3' | 'B': case '3' | 'b' | 'backup':
print() print()
if not os.path.exists(env['borg_repo']): if not os.path.exists(env['borg_repo']):
print(f"Creating borg repository {env['borg_repo']}.") print(f"Creating borg repository {env['borg_repo']}.")