commit 3c49cdf5e2ae845d2d566606f7f547a3ecc2a997 Author: Mike Date: Tue Sep 24 16:47:29 2019 -0400 Begining to build in directory recursion for book scanning diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4cf998c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +books/* diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100755 index 0000000..66bfd50 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,12 @@ +{ + "python.testing.unittestArgs": [ + "-v", + "-s", + "./tests", + "-p", + "test_*.py" + ], + "python.testing.pytestEnabled": false, + "python.testing.nosetestsEnabled": false, + "python.testing.unittestEnabled": true +} \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100755 index 0000000..d68f921 --- /dev/null +++ b/__init__.py @@ -0,0 +1,3 @@ +import sys +import os +sys.path.insert(0, os.path.abspath('.')) \ No newline at end of file diff --git a/__pycache__/config.cpython-37.pyc b/__pycache__/config.cpython-37.pyc new file mode 100755 index 0000000..e08c325 Binary files /dev/null and b/__pycache__/config.cpython-37.pyc differ diff --git a/__pycache__/library.cpython-37.pyc b/__pycache__/library.cpython-37.pyc new file mode 100644 index 0000000..928ec1c Binary files /dev/null and b/__pycache__/library.cpython-37.pyc differ diff --git a/__pycache__/main.cpython-37.pyc b/__pycache__/main.cpython-37.pyc new file mode 100755 index 0000000..07efeb4 Binary files /dev/null and b/__pycache__/main.cpython-37.pyc differ diff --git a/__pycache__/pyShelf.cpython-37.pyc b/__pycache__/pyShelf.cpython-37.pyc new file mode 100755 index 0000000..c06098d Binary files /dev/null and b/__pycache__/pyShelf.cpython-37.pyc differ diff --git a/conf/settings.json b/conf/settings.json new file mode 100755 index 0000000..e69de29 diff --git a/config.py b/config.py new file mode 100755 index 0000000..0ebcdcb --- /dev/null +++ b/config.py @@ -0,0 +1,11 @@ +class Config: + """Main System Configuration""" + def __init__(self): + self.book_path = "books/" + self.book_shelf = "data/shelf.json" + self.file_array = [ + "data/catalogue.json", + "data/shelf.json", + "conf/settings.json" + ] + self.auto_scan = True \ No newline at end of file diff --git a/data/shelf.json b/data/shelf.json new file mode 100644 index 0000000..e8bf18b --- /dev/null +++ b/data/shelf.json @@ -0,0 +1 @@ +["Python Tricks by Dan Bader.epub"] \ No newline at end of file diff --git a/library.py b/library.py new file mode 100755 index 0000000..ae0520c --- /dev/null +++ b/library.py @@ -0,0 +1,40 @@ +#!/usr/bin/python +import json +import os +import re +from config import Config +config = Config() + + +class Catalogue: + """Decodes and stores book information""" + def __init__(self): + with open(config.book_shelf, 'r') as f: + try: + self.catalogue = json.load(f) + self.current_files = self.scan_folder() + except Exception: + with open(config.book_shelf, 'w') as f: + json.dump(self.filter_books(), f) + + def scan_folder(self): + file_list = [] + for f in os.listdir(config.book_path): + file_list.append(f) + return file_list + + def filter_books(self): + scan = self.scan_folder() + breakpoint() + regx = re.compile(r"\.epub") + self.books = list(filter(regx.search, scan)) + return self.books + + def compare_shelf_current(self): + try: + self.books + except Exception: + self.filter_books() + breakpoint() + unique = set(self.books) - set(self.catalogue) + return unique diff --git a/main.py b/main.py new file mode 100755 index 0000000..ab32539 --- /dev/null +++ b/main.py @@ -0,0 +1,10 @@ +#!/usr/bin/python +# import zipfile as Zip +from pyShelf import InitFiles +from config import Config +from library import Catalogue + +config = Config() + +InitFiles(config.file_array) + diff --git a/pyShelf.py b/pyShelf.py new file mode 100755 index 0000000..aefeb2a --- /dev/null +++ b/pyShelf.py @@ -0,0 +1,33 @@ +#!/usr/bin/python +import os +import zipfile +from config import Config +config = Config() + +class InitFiles: + """First run file creation operations""" + def __init__(self, file_array): + print("Begining creation of file structure") + for _pointer in file_array: + if not os.path.isfile(_pointer): + self.CreateFile(_pointer) + + def CreateFile(self, _pointer): + """Create the file""" + if not os.path.isdir(os.path.split(_pointer)[0]): + os.mkdir(os.path.split(_pointer)[0]) + f = open(_pointer, "w+") + f.close() + + +class Epub: + """All Epub file handling""" + def __init__(self): + global config + self.book_path = config.book_path + + def import_book(self): + pass + + def book_list(self): + pass diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/tests/__pycache__/test_library.cpython-37.pyc b/tests/__pycache__/test_library.cpython-37.pyc new file mode 100644 index 0000000..d9d8f8e Binary files /dev/null and b/tests/__pycache__/test_library.cpython-37.pyc differ diff --git a/tests/__pycache__/test_sysio.cpython-37.pyc b/tests/__pycache__/test_sysio.cpython-37.pyc new file mode 100755 index 0000000..ab8ae3b Binary files /dev/null and b/tests/__pycache__/test_sysio.cpython-37.pyc differ diff --git a/tests/test_library.py b/tests/test_library.py new file mode 100755 index 0000000..3b4a59b --- /dev/null +++ b/tests/test_library.py @@ -0,0 +1,18 @@ +import unittest +from library import Catalogue + + +class Testing(unittest.TestCase): + + def test_libray_catalogue(self): + self.assertIsNotNone(Catalogue()) + + def test_library_catalogue_scan_folder(self): + self.assertIsInstance(Catalogue().scan_folder(), object) + + def test_library_catalogue_compare_shelf_current(self): + self.assertIsInstance(Catalogue().compare_shelf_current(), Catalogue) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_sysio.py b/tests/test_sysio.py new file mode 100755 index 0000000..39cf27f --- /dev/null +++ b/tests/test_sysio.py @@ -0,0 +1,22 @@ +import unittest +import os +import shutil +from pyShelf import InitFiles +from pyShelf import Epub + + +class SysIoTest(unittest.TestCase): + + def test_sysio_InitFiles(self): + file_array = ["temp/test_file_1", "temp/test_file_2"] + InitFiles(file_array) + self.assertTrue(os.path.isfile(file_array[0])) + + def tearDown(self): + try: + shutil.rmtree("temp") + except Exception as e: + pass + +if __name__ == '__main__': + unittest.main()