Skip to content

Commit

Permalink
Refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
alichtman committed May 10, 2020
1 parent 4dddcc9 commit 65161a5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
8 changes: 2 additions & 6 deletions shallow_backup/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,13 @@ def print_version_info(cli=True):


def splash_screen():
"""
Display splash graphic, and then stylized version and author info.
"""
"""Display splash graphic, and then stylized version and author info."""
print(Fore.YELLOW + Style.BRIGHT + "\n" + ProjInfo.LOGO + Style.RESET_ALL)
print_version_info(False)


def print_section_header(title, color):
"""
Prints variable sized section header
"""
"""Prints variable sized section header."""
block = "#" * (len(title) + 2)
print("\n" + color + Style.BRIGHT + block)
print("#", title)
Expand Down
12 changes: 5 additions & 7 deletions shallow_backup/reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@


def reinstall_dots_sb(dots_path, home_path=os.path.expanduser("~")):
"""
Reinstall all dotfiles and folders by copying them to the home dir.
"""
"""Reinstall all dotfiles and folders by copying them to the home dir."""
empty_backup_dir_check(dots_path, 'dotfile')
print_section_header("REINSTALLING DOTFILES", Fore.BLUE)

Expand All @@ -34,10 +32,10 @@ def reinstall_dots_sb(dots_path, home_path=os.path.expanduser("~")):
destination = home_path
try:
copy(file, destination)
except PermissionError as e:
print_red_bold(f"ERROR: {e}")
except FileNotFoundError as e:
print_red_bold(f"ERROR: {e}")
except PermissionError as err:
print_red_bold(f"ERROR: {err}")
except FileNotFoundError as err:
print_red_bold(f"ERROR: {err}")
print_section_header("DOTFILE REINSTALLATION COMPLETED", Fore.BLUE)


Expand Down
3 changes: 1 addition & 2 deletions shallow_backup/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@


def upgrade_from_pre_v3():
"""
Before v3.0, the config file was stored at ~/.shallow-backup. In v3.0,
"""Before v3.0, the config file was stored at ~/.shallow-backup. In v3.0,
the XDG Base Directory specification was adopted and the new config is
stored in either $XDG_CONFIG_HOME/shallow-backup/shallow-backup.conf or
~/.config/shallow-backup.conf. This method upgrades from
Expand Down
16 changes: 10 additions & 6 deletions shallow_backup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,21 @@ def mkdir_overwrite(path):
full_path = os.path.join(path, f)
# 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"):
full_path.endswith(".gitignore") or \
full_path.endswith("README.md") or \
full_path.endswith("img"):
continue

if os.path.isdir(full_path):
dirs.append(full_path)
else:
files.append(full_path)

[os.remove(file) for file in files]
[rmtree(dir) for dir in dirs]
for file in files:
os.remove(file)

for directory in dirs:
rmtree(directory)
else:
os.makedirs(path)

Expand Down Expand Up @@ -152,7 +155,7 @@ def copy_dir_if_valid(source_dir, backup_path):
Copy dotfolder from $HOME, excluding invalid directories.
"""
invalid = {".Trash", ".npm", ".cache", ".rvm"}
if len(invalid.intersection(set(source_dir.split("/")))) != 0:
if invalid.intersection(set(source_dir.split("/"))) != set():
return
copytree(source_dir, backup_path, symlinks=False)

Expand Down Expand Up @@ -180,4 +183,5 @@ def expand_to_abs_path(path):


def create_dir_if_doesnt_exist(path):
"""Create directory at path"""
os.makedirs(path, exist_ok=True)

0 comments on commit 65161a5

Please sign in to comment.