mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Ready for alpha?
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"""
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user