Skip to content

Commit

Permalink
Fixed multiprocessing and added code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alichtman committed Nov 23, 2018
1 parent 5a6dfad commit da99598
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ install:
- pipenv install --dev

script:
- pytest
- pytest --cov=shallow_backup

after_success:
# Hack to get around https://github.com/pytest-dev/pytest-cov/issues/242
- pytest --cov=shallow_backup
- coveralls

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Downloads](http://pepy.tech/badge/shallow-backup)](http://pepy.tech/count/shallow-backup)
[![Build Status](https://travis-ci.com/alichtman/shallow-backup.svg?branch=master)](https://travis-ci.com/alichtman/shallow-backup)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1719da4d7df5455d8dbb4340c428f851)](https://www.codacy.com/app/alichtman/shallow-backup?utm_source=github.com&utm_medium=referral&utm_content=alichtman/shallow-backup&utm_campaign=Badge_Grade)
<!-- [![Coverage Status](https://coveralls.io/repos/github/alichtman/shallow-backup/badge.svg?branch=master)](https://coveralls.io/github/alichtman/shallow-backup?branch=master) -->
[![Coverage Status](https://coveralls.io/repos/github/alichtman/shallow-backup/badge.svg?branch=master)](https://coveralls.io/github/alichtman/shallow-backup?branch=master)

`shallow-backup` lets you easily create lightweight backups of installed packages, applications, fonts and dotfiles, and automatically push them to a remote Git repository.

Expand Down
26 changes: 6 additions & 20 deletions shallow_backup/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@
from .config import get_config


# TODO: Move to UTILS.
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 backup_dotfiles(backup_dest_path, home_path=os.path.expanduser("~"), skip=False):
"""
Create `dotfiles` dir and makes copies of dotfiles and dotfolders.
Expand Down Expand Up @@ -57,18 +43,18 @@ def backup_dotfiles(backup_dest_path, home_path=os.path.expanduser("~"), skip=Fa
dest_path = quote(os.path.join(backup_dest_path, dotfile))
dotfiles_mp_in.append((dotfile_path, dest_path))

# Multiprocessing
with mp.Pool(mp.cpu_count()):
print_blue_bold("Backing up dotfolders...")
for x in dotfolders_mp_in:
x = list(x)
mp.Process(target=copy_dir_if_valid, args=(x[0], x[1],)).start()
p = mp.Process(target=copy_dir_if_valid, args=(x[0], x[1],))
p.start()
p.join()

with mp.Pool(mp.cpu_count()):
print_blue_bold("Backing up dotfiles...")
for x in dotfiles_mp_in:
x = list(x)
mp.Process(target=copyfile, args=(x[0], x[1],)).start()
p = mp.Process(target=copyfile, args=(x[0], x[1],))
p.start()
p.join()


def backup_configs(backup_path, skip=False):
Expand Down
13 changes: 13 additions & 0 deletions shallow_backup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,16 @@ def expand_to_abs_path(path):
expanded_path = os.path.expanduser(path)
expanded_path = os.path.expandvars(expanded_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)

0 comments on commit da99598

Please sign in to comment.