Ready for alpha?

This commit is contained in:
Mike Young
2019-11-20 22:22:09 -05:00
parent 8e551f3f32
commit bf26dc39a8
16 changed files with 58 additions and 27 deletions

0
src/__init__.py Normal file
View File

View File

@@ -0,0 +1,2 @@
delete from books;
delete from sqlite_sequence where name='books';

View File

@@ -1,5 +1,6 @@
import json
import os
import pathlib
import sys
@@ -9,17 +10,17 @@ class Config:
"""
_fp = "config.json"
print(os.path)
def __init__(self, root=os.path.abspath("../../")):
_data = self.open_file(root)
def __init__(self, root):
_cp = pathlib.Path.joinpath(root, self._fp)
_data = self.open_file(_cp)
self.book_path = _data["BOOKPATH"]
self.TITLE = _data["TITLE"]
self.VERSION = _data["VERSION"]
self.TITLE = self.TITLE + " ver " + self.VERSION
self.book_shelf = _data["BOOKSHELF"]
# self.catalogue_db = "data/catalogue.db"
self.catalogue_db = root + "/" + _data["DATABASE"]
self.catalogue_db = str(root) + "/" + _data["DATABASE"]
self.file_array = [
self.book_shelf,
self.catalogue_db,
@@ -27,7 +28,7 @@ class Config:
self.root = root
self.auto_scan = True
def open_file(self, root):
with open(root + "/" + self._fp, "r") as read_file:
def open_file(self, _cp):
with open(str(_cp), "r") as read_file:
data = json.load(read_file)
return data

View File

@@ -1,11 +1,11 @@
#!/usr/bin/python
import json
import os
import pathlib
import re
import zipfile
from bs4 import BeautifulSoup
from PIL import Image
from .api_hooks import DuckDuckGo
from .config import Config
@@ -29,20 +29,21 @@ class Catalogue:
self.book_shelf = config.book_shelf
self._book_list_expanded = None
self.books = None
self.db_pointer = config.catalogue_db
def scan_folder(self, _path=None):
if _path is not None:
folder = _path
elif os.path.isdir(self.root_dir + "/" + self.book_folder):
folder = self.root_dir + "/" + self.book_folder
elif os.path.isdir(str(self.root_dir) + "/" + self.book_folder):
folder = str(self.root_dir) + "/" + self.book_folder
else:
folder = self.book_folder
for f in os.listdir(folder):
_path = os.path.abspath(folder + "/" + f)
_is_dir = os.path.isdir(_path.strip() + "/")
if _is_dir:
if os.path.isdir(_path.strip() + "/"):
self.file_list.append(self.scan_folder(_path))
self.file_list.append(_path)
else:
self.file_list.append(_path)
def filter_books(self):
"""
@@ -125,7 +126,7 @@ class Catalogue:
return False
def compare_shelf_current(self):
db = Storage()
db = Storage(self.db_pointer)
stored = db.book_paths_list()
closed = db.close()
if self.books is None:
@@ -141,7 +142,7 @@ class Catalogue:
def import_books(self, list=None):
book_list = self.compare_shelf_current()
db = Storage()
db = Storage(self.db_pointer)
for book in book_list:
book = self.process_book(book)
extracted = self.extract_metadata(book)

View File

@@ -1,5 +1,6 @@
#!/usr/bin/python
import os
import time
from .config import Config
from .storage import Storage
@@ -12,11 +13,16 @@ class InitFiles:
"""First run file creation operations"""
def __init__(self, file_array):
print("Begining creation of file structure")
print("Checking for program files")
for _pointer in file_array:
time.sleep(1)
if not os.path.isfile(_pointer):
self.CreateFile(_pointer)
print("Concluded file creation")
print("%s created" % _pointer)
else:
print("%s present" % _pointer)
time.sleep(1)
print("File check complete.")
def CreateFile(self, _pointer):
"""Create the file"""

View File

@@ -11,7 +11,7 @@ from .config import Config
class Storage:
"""Contains all methods for system storage"""
def __init__(self, db_pointer=None):
def __init__(self, db_pointer):
# Optionaly pass db_file to specify another db or for testing
if db_pointer is None:
db_pointer = Config().catalogue_db

View File

@@ -1,14 +1,22 @@
#!/usr/bin/python
import os
import sys
import time
from lib.config import Config
from lib.library import Catalogue
from lib.pyShelf import InitFiles
from .lib.config import Config
from .lib.library import Catalogue
from .lib.pyShelf import InitFiles
ROOT_DIR = os.path.abspath("../..")
sys.path.append(ROOT_DIR)
config = Config(ROOT_DIR) # Get configuration settings
InitFiles(config.file_array) # Initialize file system
Catalogue = Catalogue(config) # Open the Catalogue
Catalogue.import_books() # Filter Your books
sys.path.append(os.path.abspath("."))
def execute_scan(root):
_t1 = time.time()
config = Config(root) # Get configuration settings
InitFiles(config.file_array) # Initialize file system
catalogue = Catalogue(config) # Open the Catalogue
catalogue.import_books()
_t2 = time.time()
scan_time = round(_t2 - _t1)
print("Scan Completed.")
print("Scan Time %s seconds" % scan_time)

Binary file not shown.