mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Begining to build in directory recursion for book scanning
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
books/*
|
||||||
12
.vscode/settings.json
vendored
Executable file
12
.vscode/settings.json
vendored
Executable 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
3
__init__.py
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
sys.path.insert(0, os.path.abspath('.'))
|
||||||
BIN
__pycache__/config.cpython-37.pyc
Executable file
BIN
__pycache__/config.cpython-37.pyc
Executable file
Binary file not shown.
BIN
__pycache__/library.cpython-37.pyc
Normal file
BIN
__pycache__/library.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/main.cpython-37.pyc
Executable file
BIN
__pycache__/main.cpython-37.pyc
Executable file
Binary file not shown.
BIN
__pycache__/pyShelf.cpython-37.pyc
Executable file
BIN
__pycache__/pyShelf.cpython-37.pyc
Executable file
Binary file not shown.
0
conf/settings.json
Executable file
0
conf/settings.json
Executable file
11
config.py
Executable file
11
config.py
Executable 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
1
data/shelf.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
["Python Tricks by Dan Bader.epub"]
|
||||||
40
library.py
Executable file
40
library.py
Executable 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
10
main.py
Executable 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
33
pyShelf.py
Executable 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
0
tests/__init__.py
Executable file
BIN
tests/__pycache__/test_library.cpython-37.pyc
Normal file
BIN
tests/__pycache__/test_library.cpython-37.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/test_sysio.cpython-37.pyc
Executable file
BIN
tests/__pycache__/test_sysio.cpython-37.pyc
Executable file
Binary file not shown.
18
tests/test_library.py
Executable file
18
tests/test_library.py
Executable 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
22
tests/test_sysio.py
Executable 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()
|
||||||
Reference in New Issue
Block a user