Skip to content

Commit

Permalink
v1.0.8
Browse files Browse the repository at this point in the history
Bugfixes #12  #15
  • Loading branch information
WhaleJ84 authored Jan 10, 2021
2 parents f68c084 + 63baf26 commit a13cf24
Show file tree
Hide file tree
Showing 18 changed files with 288 additions and 86 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
distro:
- ubuntu2004

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: '3.x'
python-version: ${{ matrix.python-version }}

- name: Install coverage
run: |
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ setuptools = "*"
wheel = "*"
pylint = "*"
twine = "*"
coverage = "*"

[requires]
python_version = "3.8"
63 changes: 59 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# hb\_organiser

[![PyPI](https://img.shields.io/pypi/v/hb-organiser.svg)](https://pypi.python.org/pypi/hb-organiser)
![Unittests](https://github.com/WhaleJ84/hb_organiser/workflows/Unittests/badge.svg)
[![image](https://img.shields.io/pypi/pyversions/hb-organiser.svg)](https://python.org/pypi/hb-organiser)
[![Unittests](https://github.com/WhaleJ84/hb_organiser/workflows/Unittests/badge.svg)](https://github.com/WhaleJ84/hb_organiser/actions?query=workflow%3AUnittests)
[![codecov](https://codecov.io/gh/WhaleJ84/hb_organiser/branch/main/graph/badge.svg?token=IJSKBUAP81)](https://codecov.io/gh/WhaleJ84/hb_organiser)
![Pylint](https://github.com/WhaleJ84/hb_organiser/workflows/Pylint/badge.svg)
[![Pylint](https://github.com/WhaleJ84/hb_organiser/workflows/Pylint/badge.svg)](https://github.com/WhaleJ84/hb_organiser/actions?query=workflow%3APylint)

Organises Humble Bundle bundles based on their platform.
Designed to work around the structure created via Talonius' [hb-downloader](https://github.com/talonius/hb-downloader).
Other automated HB downloaders may not work with this out of the box.

![Copying files](media/hb_organiser_demo.png)
![An image of hb-organiser copying files](https://i.imgur.com/Ti1wuri.png)

## Install

Expand Down
6 changes: 6 additions & 0 deletions build/lib/hb_organiser/bundle_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def __init__(self, name, path):
"""
self.name = name
self.path = join(path, self.name)

# FileNotFound error thrown if `/path/to/file` given instead of `/path/to/file/`
# As it creates `/path/to/file/file`. This appears to resolve that
if self.path.split('/')[-2] == self.name:
self.path = path

self.items = len(glob(f"{self.path}/**", recursive=True))-1


Expand Down
17 changes: 12 additions & 5 deletions build/lib/hb_organiser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
Contains the code pertaining to the CLI. All back-end logic is located elsewhere.
"""
import argparse
from sys import exit as sys_exit
from sys import argv

from hb_organiser.check import source_exists
from hb_organiser.config import Config
from hb_organiser.organiser import HBOrganiser
from hb_organiser.logger import logger


def cli():
def cli(args=None):
"""
Contains the code pertaining to the CLI. All back-end logic is located elsewhere.
Expand All @@ -35,8 +35,14 @@ def cli():
help="destination directory of sorted bundles. overrides location specified in config file. "
"if no destination is given, a dry run will occur - displaying what would have happened."
)
args = parser.parse_args()

if args is not None:
args = parser.parse_args(args)
else:
args = parser.parse_args()


# def verify_args(args):
if args.source:
source = args.source
else:
Expand All @@ -58,10 +64,11 @@ def cli():
logger.debug('No destination given via CLI or config. Defaulting to None')

if not source_exists(source):
sys_exit(1)
return False
organiser = HBOrganiser(source, destination, args.platform)
organiser.loop_through_bundles()
return True


if __name__ == '__main__':
cli()
cli(argv[1:])
63 changes: 35 additions & 28 deletions build/lib/hb_organiser/organiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def ensure_directory_exists(self, target, task=None):
print(f"{task} MKDIR: {destination}")
Path(destination).mkdir(parents=True, exist_ok=True)

@staticmethod
def copy_file(source, destination, task=None):
def copy_file(self, source, destination, task=None):
"""
Copies the source to the destination.
Before each operation, the source file is logged.
Expand All @@ -61,31 +60,39 @@ def copy_file(source, destination, task=None):
:type task: str
:return:
"""
if not isfile(destination):
# TODO: Fix this duplicate code section.
# Was nastily thrown in to fix a bug
try:
if source in open('queue.txt'):
print(f"{task} COPY: {source} {destination}")
log = open('queue.txt', 'w')
log.write(source)
log.close()
copyfile(source, destination)
log = open('queue.txt', 'w')
log.write('')
log.close()
except FileNotFoundError:
pass
print(f"{task} COPY: {source} {destination}")
log = open('queue.txt', 'w')
log.write(source)
log.close()
copyfile(source, destination)
log = open('queue.txt', 'w')
log.write('')
log.close()
else:
print(f"{task} SKIP: {destination}")
complete = 'DONE'
try:
if source not in open('queue.txt') and not isfile(destination):
print(f"{task} COPYING: {source} {destination}\r", end="", flush=True)
complete = 'COPIED'
log = open('queue.txt', 'w')
log.write(source)
log.close()
elif source in open('queue.txt'):
print(f"{task} RE-COPING: {source} {destination}\r", end="", flush=True)
complete = 'RE-COPIED'
else:
print(f"{task} SKIPPED: {destination}")
return True
except FileNotFoundError:
print(f"{task} INFO: Creating queue.txt")
open('queue.txt', 'x')
self.copy_file(source, destination, task)

copyfile(source, destination)
print(f"{task} {complete}: {source} {destination}\r", flush=True)

entries = []
log = open('queue.txt')
for entry in log:
if source not in entry:
entries.append(entry)
log.close()

log = open('queue.txt', 'w')
log.writelines(entries)
log.close()
return True

def loop_through_bundles(self):
"""
Expand Down Expand Up @@ -128,5 +135,5 @@ def loop_through_bundles(self):
task += 1
return True
except KeyboardInterrupt:
print('INFO: Manual intervention. exiting.')
print('\nINFO: Manual intervention. exiting.')
return False
48 changes: 48 additions & 0 deletions build/lib/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from os.path import abspath
from unittest import TestCase

from hb_organiser.cli import *


class HBOrganiserCliTesCase(TestCase):
def setUp(self) -> None:
pass

def tearDown(self) -> None:
pass

def test_verify_args_returns_true_on_good_relative_source_path_with_trailing_forward_slash(self):
result = cli(['-s', 'tests/test_libraries/library/', 'all'])
HBOrganiserCliTesCase.assertTrue(self, result)

def test_verify_args_returns_true_on_good_absolute_source_path_with_trailing_forward_slash(self):
result = cli(['-s', abspath('tests/test_libraries/library/'), 'all'])
HBOrganiserCliTesCase.assertTrue(self, result)

def test_verify_args_returns_true_on_good_relative_source_path_without_trailing_forward_slash(self):
result = cli(['-s', 'tests/test_libraries/library', 'all'])
HBOrganiserCliTesCase.assertTrue(self, result)

def test_verify_args_returns_true_on_good_absolute_source_path_without_trailing_forward_slash(self):
result = cli(['-s', abspath('tests/test_libraries/library'), 'all'])
HBOrganiserCliTesCase.assertTrue(self, result)

def test_verify_args_returns_false_on_source_bad_path(self):
result = cli(['-s', 'tests/test_libraries/fake_library', 'all'])
HBOrganiserCliTesCase.assertFalse(self, result)

def test_verify_args_returns_true_on_good_relative_destination_path_with_trailing_forward_slash(self):
result = cli(['-s', 'tests/test_libraries/library/', '-d', 'tests/test_destination/', 'all'])
HBOrganiserCliTesCase.assertTrue(self, result)

def test_verify_args_returns_true_on_good_absolute_destination_path_with_trailing_forward_slash(self):
result = cli(['-s', 'tests/test_libraries/library/', '-d', abspath('tests/test_destination/'), 'all'])
HBOrganiserCliTesCase.assertTrue(self, result)

def test_verify_args_returns_true_on_good_relative_destination_path_without_trailing_forward_slash(self):
result = cli(['-s', 'tests/test_libraries/library/', '-d', 'tests/test_destination', 'all'])
HBOrganiserCliTesCase.assertTrue(self, result)

def test_verify_args_returns_true_on_good_absolute_destination_path_without_trailing_forward_slash(self):
result = cli(['-s', 'tests/test_libraries/library/', '-d', abspath('tests/test_destination'), 'all'])
HBOrganiserCliTesCase.assertTrue(self, result)
Binary file added dist/hb_organiser-1.0.8-py3-none-any.whl
Binary file not shown.
Binary file added dist/hb_organiser-1.0.8.tar.gz
Binary file not shown.
14 changes: 9 additions & 5 deletions hb_organiser.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: hb-organiser
Version: 1.0.7
Version: 1.0.8
Summary: Organises Humble Bundle bundles based on their platform.
Home-page: https://github.com/WhaleJ84/hb_organiser
Author: James Whale
Expand All @@ -9,15 +9,16 @@ License: UNKNOWN
Description: # hb\_organiser

[![PyPI](https://img.shields.io/pypi/v/hb-organiser.svg)](https://pypi.python.org/pypi/hb-organiser)
![Unittests](https://github.com/WhaleJ84/hb_organiser/workflows/Unittests/badge.svg)
[![image](https://img.shields.io/pypi/pyversions/hb-organiser.svg)](https://python.org/pypi/hb-organiser)
[![Unittests](https://github.com/WhaleJ84/hb_organiser/workflows/Unittests/badge.svg)](https://github.com/WhaleJ84/hb_organiser/actions?query=workflow%3AUnittests)
[![codecov](https://codecov.io/gh/WhaleJ84/hb_organiser/branch/main/graph/badge.svg?token=IJSKBUAP81)](https://codecov.io/gh/WhaleJ84/hb_organiser)
![Pylint](https://github.com/WhaleJ84/hb_organiser/workflows/Pylint/badge.svg)
[![Pylint](https://github.com/WhaleJ84/hb_organiser/workflows/Pylint/badge.svg)](https://github.com/WhaleJ84/hb_organiser/actions?query=workflow%3APylint)

Organises Humble Bundle bundles based on their platform.
Designed to work around the structure created via Talonius' [hb-downloader](https://github.com/talonius/hb-downloader).
Other automated HB downloaders may not work with this out of the box.

![Copying files](media/hb_organiser_demo.png)
![An image of hb-organiser copying files](https://i.imgur.com/Ti1wuri.png)

## Install

Expand Down Expand Up @@ -61,9 +62,12 @@ Description: # hb\_organiser
This could be useful in other situations such as organising music.

Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Natural Language :: English
Requires-Python: >=3.8
Requires-Python: >=3.6
Description-Content-Type: text/markdown
3 changes: 2 additions & 1 deletion hb_organiser.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ hb_organiser.egg-info/dependency_links.txt
hb_organiser.egg-info/entry_points.txt
hb_organiser.egg-info/top_level.txt
tests/__init__.py
tests/test_checks.py
tests/test_checks.py
tests/test_cli.py
6 changes: 6 additions & 0 deletions hb_organiser/bundle_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def __init__(self, name, path):
"""
self.name = name
self.path = join(path, self.name)

# FileNotFound error thrown if `/path/to/file` given instead of `/path/to/file/`
# As it creates `/path/to/file/file`. This appears to resolve that
if self.path.split('/')[-2] == self.name:
self.path = path

self.items = len(glob(f"{self.path}/**", recursive=True))-1


Expand Down
Loading

0 comments on commit a13cf24

Please sign in to comment.