Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option --copy-only #2012

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Add support for SketchyBar (via @LarsRefsgaard)
- Add support for nvm (via @Wxh16144)
- Add support for PHPStorm 2023.3 (via @damosse31)
- Add --copy-only option (via @dracorp)

## Mackup 0.8.40

Expand Down
7 changes: 6 additions & 1 deletion mackup/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class ApplicationProfile(object):
"""Instantiate this class with application specific data."""

def __init__(self, mackup, files, dry_run, verbose):
def __init__(self, mackup, files, dry_run, verbose, copy_only):
"""
Create an ApplicationProfile instance.

Expand All @@ -29,6 +29,7 @@ def __init__(self, mackup, files, dry_run, verbose):
self.files = list(files)
self.dry_run = dry_run
self.verbose = verbose
self.copy_only = copy_only

def getFilepaths(self, filename):
"""
Expand Down Expand Up @@ -106,13 +107,17 @@ def backup(self):
utils.delete(mackup_filepath)
# Copy the file
utils.copy(home_filepath, mackup_filepath)
if self.copy_only:
continue
# Delete the file in the home
utils.delete(home_filepath)
# Link the backuped file to its original place
utils.link(mackup_filepath, home_filepath)
else:
# Copy the file
utils.copy(home_filepath, mackup_filepath)
if self.copy_only:
continue
# Delete the file in the home
utils.delete(home_filepath)
# Link the backuped file to its original place
Expand Down
26 changes: 17 additions & 9 deletions mackup/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
mackup --version

Options:
-h --help Show this screen.
-f --force Force every question asked to be answered with "Yes".
-r --root Allow mackup to be run as superuser.
-n --dry-run Show steps without executing.
-v --verbose Show additional details.
--version Show version.
-h --help Show this screen.
-f --force Force every question asked to be answered with "Yes".
-r --root Allow mackup to be run as superuser.
-n --dry-run Show steps without executing.
-c --copy-only Copy only files when backup.
Copy link

Choose a reason for hiding this comment

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

Idiomatic English would be more like: "Only copy files when backing up"

-v --verbose Show additional details.
--version Show version.

Modes of action:
1. list: display a list of all supported applications.
Expand Down Expand Up @@ -83,13 +84,17 @@ def printAppHeader(app_name):

verbose = args["--verbose"]

copy_only = args["--copy-only"]

if args["backup"]:
# Check the env where the command is being run
mckp.check_for_usable_backup_env()

# Backup each application
for app_name in sorted(mckp.get_apps_to_backup()):
app = ApplicationProfile(mckp, app_db.get_files(app_name), dry_run, verbose)
app = ApplicationProfile(
mckp, app_db.get_files(app_name), dry_run, verbose, copy_only
)
printAppHeader(app_name)
app.backup()

Expand All @@ -100,7 +105,8 @@ def printAppHeader(app_name):
# Restore the Mackup config before any other config, as we might need
# it to know about custom settings
mackup_app = ApplicationProfile(
mckp, app_db.get_files(MACKUP_APP_NAME), dry_run, verbose
mckp, app_db.get_files(MACKUP_APP_NAME), dry_run, verbose,
copy_only
)
printAppHeader(MACKUP_APP_NAME)
mackup_app.restore()
Expand All @@ -116,7 +122,9 @@ def printAppHeader(app_name):
app_names.discard(MACKUP_APP_NAME)

for app_name in sorted(app_names):
app = ApplicationProfile(mckp, app_db.get_files(app_name), dry_run, verbose)
app = ApplicationProfile(
mckp, app_db.get_files(app_name), dry_run, verbose, copy_only
)
printAppHeader(app_name)
app.restore()

Expand Down