Added basic documentation to all backend objects

This commit is contained in:
Mike Young
2019-12-01 12:35:40 -05:00
parent c5ad0a2bb7
commit 9dc1acf6b9
13 changed files with 159 additions and 33 deletions

View File

@@ -32,6 +32,9 @@ class Config:
self.auto_scan = True
def open_file(self, _cp):
"""
Opens config.json and reads in configuration options
"""
with open(str(_cp), "r") as read_file:
data = json.load(read_file)
return data

View File

@@ -15,9 +15,9 @@ from .storage import Storage
class Catalogue:
"""Decodes and stores book information"""
"""Step One: filter_books"""
"""
Decodes book metadata for storage
"""
def __init__(self, config):
self.file_list = []
@@ -33,6 +33,9 @@ class Catalogue:
self.config = config
def scan_folder(self, _path=None):
"""
Scan folder by _path, allows recurisive scanning
"""
if _path is not None:
folder = _path
elif os.path.isdir(str(self.root_dir) + "/" + self.book_folder):
@@ -48,11 +51,10 @@ class Catalogue:
def filter_books(self):
"""
Scan book folder recursively for epub files
filter_books(0) -> Catalogue.books
filter_books(1) -> self.books[]
:param ret: 0 -> create class property -> dump json
:param ret: 1 -> create & return class property
Calls scan_folder and filters out book files
Proceeds to call process_book
:returns self._book_list_expanded: json string containing all book metadata
"""
self.scan_folder()
regx = re.compile(r"\.epub")
@@ -111,14 +113,23 @@ class Catalogue:
return book_details
def extract_content(self, book_zip, book):
"""
Opens epub as zip file filters then stores as list any files matching opf_regx
"""
content = book_zip.open(list(filter(self.opf_regx.search, book["files"]))[0])
return content
def extract_cover_html(self, book_zip, book):
"""
Opens epub as zip file filters then stores as list any files matching html_regx
"""
cover = book_zip.open(list(filter(self.html_regx.search, book["files"]))[0])
return cover
def extract_cover_image(self, book_zip, book):
"""
Opens epub as zip file filters then stores as list any files matching cover_regx
"""
cover = book_zip.open(list(filter(self.cover_regx.search, book["files"]))[0])
try:
cover = book_zip.read(cover.name)
@@ -127,6 +138,9 @@ class Catalogue:
return False
def compare_shelf_current(self):
"""
Calls storage system, gets list of books stored and compares against files on disk
"""
db = Storage(self.db_pointer, self.config)
stored = db.book_paths_list()
closed = db.close()
@@ -142,6 +156,11 @@ class Catalogue:
return c
def import_books(self, list=None):
"""
Main entry point for import operations.
Gets a list of new files via compare_shelf_current.
Iterates over list and inserts new books into database.
"""
book_list = self.compare_shelf_current()
db = Storage(self.db_pointer, self.config)
for book in book_list:

View File

@@ -25,7 +25,9 @@ class InitFiles:
print("File check complete.")
def CreateFile(self, _pointer):
"""Create the file"""
"""
Checks if file exists and creates it if not
"""
if not os.path.isdir(os.path.split(_pointer)[0]):
os.mkdir(os.path.split(_pointer)[0])
f = open(_pointer, "w+")
@@ -52,6 +54,7 @@ class BookDisplay:
def nextPage(self):
"""
## TODO Remove me
Goto next book page
:return: new current_page
"""
@@ -60,6 +63,7 @@ class BookDisplay:
def previousPage(self):
"""
## TODO Remove me
Goto previous book page
:return: new current_page
"""
@@ -68,8 +72,8 @@ class BookDisplay:
def booksPerPage(self, screen_size):
"""
## TODO Remove me
Set books per page
:param screen_size: Array containing x,y pixel sizes
:return: self.books_per_page
"""

View File

@@ -69,6 +69,9 @@ class Storage:
return False
def book_paths_list(self):
"""
Get file paths from database for comparison to system files
"""
q = """SELECT file_name FROM books"""
x = self.cursor.execute(q)
try:
@@ -78,6 +81,9 @@ class Storage:
return x
def commit(self):
"""
Commit database transactions
"""
try:
self.db.commit()
return True
@@ -85,5 +91,8 @@ class Storage:
return e
def close(self):
"""
Close database connection
"""
self.db.close()
return True

View File

@@ -11,6 +11,10 @@ sys.path.append(os.path.abspath("."))
def execute_scan(root):
"""
Main scan execution
:param root: Project root. Required to properly execute program. Sends to configuration.
"""
_t1 = time.time()
config = Config(root) # Get configuration settings
InitFiles(config.file_array) # Initialize file system