Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions mackup/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

Usage:
mackup list
mackup [options] backup
mackup [options] restore
mackup [options] backup [--] [<application> ...]
mackup [options] restore [--] [<application> ...]
mackup show <application>
mackup [options] uninstall
mackup [options] uninstall [--] [<application> ...]
mackup (-h | --help)
mackup --version

Expand Down Expand Up @@ -87,8 +87,14 @@ def printAppHeader(app_name):
# Check the env where the command is being run
mckp.check_for_usable_backup_env()

applications = sorted(mckp.get_apps_to_backup())

# To allow for specific applications to be backed up, we replace the full list with only the valid ones from the command line
if args["<application>"]:
applications = list(set(args["<application>"]) & set(applications))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it fail here if any explicit application is not recognized?
silent ignoring them seems dangerous, as it would imply everything went fine

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should also be sorted again, to maintain the same behaviour


# Backup each application
for app_name in sorted(mckp.get_apps_to_backup()):
for app_name in applications:
app = ApplicationProfile(mckp, app_db.get_files(app_name), dry_run, verbose)
printAppHeader(app_name)
app.backup()
Expand All @@ -115,7 +121,13 @@ def printAppHeader(app_name):
# Mackup has already been done
app_names.discard(MACKUP_APP_NAME)

for app_name in sorted(app_names):
app_names = sorted(app_names)

# To allow for specific applications to be restored up, we replace the full list with only the valid ones from the command line
if args["<application>"]:
app_names = list(set(args["<application>"]) & set(app_names))

for app_name in app_names:
app = ApplicationProfile(mckp, app_db.get_files(app_name), dry_run, verbose)
printAppHeader(app_name)
app.restore()
Expand All @@ -138,7 +150,13 @@ def printAppHeader(app_name):
app_names = mckp.get_apps_to_backup()
app_names.discard(MACKUP_APP_NAME)

for app_name in sorted(app_names):
app_names = sorted(app_names)

# To allow for specific applications to be uninstalled, we replace the full list with only the valid ones from the command line
if args["<application>"]:
app_names = list(set(args["<application>"]) & set(app_names))

for app_name in app_names:
app = ApplicationProfile(
mckp, app_db.get_files(app_name), dry_run, verbose
)
Expand Down Expand Up @@ -179,8 +197,8 @@ def printAppHeader(app_name):

elif args["show"]:
mckp.check_for_usable_environment()
app_name = args["<application>"]

app_name = args["<application>"][0] # Needed because args["<application>"] is now a list
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not support multiple applications also in show command?

# Make sure the app exists
if app_name not in app_db.get_app_names():
sys.exit("Unsupported application: {}".format(app_name))
Expand Down