Begining to build in directory recursion for book scanning

This commit is contained in:
Mike
2019-09-24 16:47:29 -04:00
commit 3c49cdf5e2
18 changed files with 151 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
books/*

12
.vscode/settings.json vendored Executable file
View File

@@ -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
}

3
__init__.py Executable file
View File

@@ -0,0 +1,3 @@
import sys
import os
sys.path.insert(0, os.path.abspath('.'))

BIN
__pycache__/config.cpython-37.pyc Executable file

Binary file not shown.

Binary file not shown.

BIN
__pycache__/main.cpython-37.pyc Executable file

Binary file not shown.

Binary file not shown.

0
conf/settings.json Executable file
View File

11
config.py Executable file
View File

@@ -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

1
data/shelf.json Normal file
View File

@@ -0,0 +1 @@
["Python Tricks by Dan Bader.epub"]

40
library.py Executable file
View File

@@ -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

10
main.py Executable file
View File

@@ -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)

33
pyShelf.py Executable file
View File

@@ -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

0
tests/__init__.py Executable file
View File

Binary file not shown.

Binary file not shown.

18
tests/test_library.py Executable file
View File

@@ -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()

22
tests/test_sysio.py Executable file
View File

@@ -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()