Skip to content

Commit

Permalink
Allow img directory to persist for backing up dots separately
Browse files Browse the repository at this point in the history
  • Loading branch information
alichtman committed Sep 24, 2019
1 parent b33db09 commit fe8fc0d
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions shallow_backup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ def mkdir_overwrite(path):
files = []
for f in os.listdir(path):
full_path = os.path.join(path, f)
# Allow dotfiles to be a sub-repo.
if full_path.endswith(".git") or full_path.endswith(".gitignore") or full_path.endswith("README.md"):
# Allow dotfiles to be a sub-repo, and protect img folder.
if full_path.endswith(".git") or \
full_path.endswith(".gitignore") or \
full_path.endswith("README.md") or \
full_path.endswith("img"):
continue

if os.path.isdir(full_path):
Expand Down Expand Up @@ -94,6 +97,19 @@ def mkdir_warn_overwrite(path):
print_path_blue("Created directory:", path)


def overwrite_dir_prompt_if_needed(path, needed):
"""
Prompts the user before deleting the directory if needed.
This function lets the CLI args silence the prompts.
:param path: absolute path
:param needed: boolean
"""
if not needed:
mkdir_warn_overwrite(path)
else:
mkdir_overwrite(path)


def empty_backup_dir_check(backup_path, backup_type):
if not os.path.isdir(backup_path) or not os.listdir(backup_path):
print_red_bold('No {} backup found.'.format(backup_type))
Expand Down Expand Up @@ -155,18 +171,5 @@ def expand_to_abs_path(path):
return os.path.abspath(expanded_path)


def overwrite_dir_prompt_if_needed(path, needed):
"""
Prompts the user before deleting the directory if needed.
This function lets the CLI args silence the prompts.
:param path: absolute path
:param needed: boolean
"""
if not needed:
mkdir_warn_overwrite(path)
else:
mkdir_overwrite(path)


def create_dir_if_doesnt_exist(path):
os.makedirs(path, exist_ok=True)

0 comments on commit fe8fc0d

Please sign in to comment.