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

Refactor --add option and bump to v3.3 #250

Merged
merged 2 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Contents
* [What can I back up?](#what-can-i-back-up)
* [Backup Customization](#backup-customization)
* [Output Structure](#output-structure)
* [Reinstallation](#reinstallation)
* [Inspiration](#inspiration)
* [Want to contribute?](#want-to-contribute)

Expand Down Expand Up @@ -46,6 +47,7 @@ Usage: shallow-backup [OPTIONS]
Written by Aaron Lichtman (@alichtman).

Options:
--add_dot Add a dotfile or dotfolder to config by path.
-all Full back up.
-configs Back up app config files.
-delete_config Delete config file.
Expand Down Expand Up @@ -195,6 +197,10 @@ backup_dir/
└── sublime3_list.txt
```

### Reinstallation

To reinstall your dotfiles, clone your dotfiles repo and make sure your shallow-backup config path can be found at either `~/.config/shallow-backup.conf` or `$XDG_CONFIG_HOME/.shallow_backup.conf`. Set the `backup-path` key in the config to the path of your cloned dotfiles. Then run `$ shallow-backup -reinstall_dots`.

### Inspiration
---

Expand Down
10 changes: 5 additions & 5 deletions shallow_backup/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# custom help options
@click.command(context_settings=dict(help_option_names=['-h', '-help', '--help']))
@click.option('--add', default=None, help="Add a dotfile or dotfolder by path.")
@click.option('--add_dot', default=None, help="Add a dotfile or dotfolder to config by path.")
@click.option('-all', is_flag=True, default=False, help="Full back up.")
@click.option('-configs', is_flag=True, default=False, help="Back up app config files.")
@click.option('-delete_config', is_flag=True, default=False, help="Delete config file.")
Expand All @@ -32,7 +32,7 @@
@click.option('-separate_dotfiles_repo', is_flag=True, default=False, help="Use if you are trying to maintain a separate dotfiles repo and running into issue #229.")
@click.option('-show', is_flag=True, default=False, help="Display config file.")
@click.option('--version', '-v', is_flag=True, default=False, help='Display version and author info.')
def cli(add, all, configs, delete_config, destroy_backup, dotfiles, fonts, new_path,
def cli(add_dot, all, configs, delete_config, destroy_backup, dotfiles, fonts, new_path,
no_splash, old_path, packages, reinstall_all, reinstall_configs,
reinstall_dots, reinstall_fonts, reinstall_packages, remote,
separate_dotfiles_repo, show, version):
Expand All @@ -46,7 +46,7 @@ def cli(add, all, configs, delete_config, destroy_backup, dotfiles, fonts, new_p
upgrade_from_pre_v3()

# Process CLI args
admin_action = any([add, delete_config, destroy_backup, show, version])
admin_action = any([add_dot, delete_config, destroy_backup, show, version])
has_cli_arg = any([old_path, all, dotfiles, packages, fonts, configs,
reinstall_dots, reinstall_fonts, reinstall_all,
reinstall_configs, reinstall_packages])
Expand All @@ -67,8 +67,8 @@ def cli(add, all, configs, delete_config, destroy_backup, dotfiles, fonts, new_p
destroy_backup_dir(backup_home_path)
elif show:
show_config()
elif add:
new_config = add_path(backup_config, add)
elif add_dot:
new_config = add_dot_path_to_config(backup_config, add_dot)
write_config(new_config)
sys.exit()

Expand Down
14 changes: 7 additions & 7 deletions shallow_backup/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def delete_config_file():
print_red_bold("ERROR: No config file found.")


def add_path(backup_config: dict, filePath: str) -> dict:
def add_dot_path_to_config(backup_config: dict, file_path: str) -> dict:
"""
Add a path to the config under the correct heading (dotfiles / dotfolders).
Exits if the filepath parameter is invalid.
Expand All @@ -125,14 +125,14 @@ def strip_home(full_path):
"""
return full_path[len(os.path.expanduser("~")) + 1:]

absPath = path.abspath(filePath)
if not path.exists(absPath):
print_path_red("Invalid file path:", absPath)
abs_path = path.abspath(file_path)
if not path.exists(abs_path):
print_path_red("Invalid file path:", abs_path)
sys.exit(1)
elif path.isdir(absPath):
backup_config["dotfolders"] += [strip_home(absPath)]
elif path.isdir(abs_path):
backup_config["dotfolders"] += [strip_home(abs_path)]
else: # Otherwise it's a dotfile
backup_config["dotfiles"] += [strip_home(absPath)]
backup_config["dotfiles"] += [strip_home(abs_path)]
return backup_config


Expand Down
2 changes: 1 addition & 1 deletion shallow_backup/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ProjInfo:
PROJECT_NAME = 'shallow-backup'
VERSION = '3.2'
VERSION = '3.3'
AUTHOR_GITHUB = 'alichtman'
AUTHOR_FULL_NAME = 'Aaron Lichtman'
DESCRIPTION = "Easily create lightweight backups of installed packages, dotfiles, and more."
Expand Down