mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Began documentation rewrite.
This commit is contained in:
39
src/backend/lib/config.py
vendored
39
src/backend/lib/config.py
vendored
@@ -6,7 +6,44 @@ from loguru import logger
|
||||
|
||||
|
||||
class Config:
|
||||
"""Main System Configuration."""
|
||||
"""Main System Configuration.
|
||||
|
||||
>>> config = Config(root)
|
||||
|
||||
Parameters
|
||||
----------
|
||||
root : File system root of program
|
||||
|
||||
Attributes
|
||||
----------
|
||||
root : str() stores root.
|
||||
_fp : str() file pointer to main configuration.
|
||||
_cp : Path() object of configuration file.
|
||||
_data : dict() parsed json of _fp.
|
||||
logger : holds logging configuration from get_logger().
|
||||
book_path : directory pointer to main books folder.
|
||||
TITLE : str() Program title.
|
||||
VERSION : str() Program version.
|
||||
TITLE : str() Combines TITLE & VERSION.
|
||||
book_shelf : Deprecation TODO: Is this still in use?
|
||||
catalogue_db : str() Database Name.
|
||||
user : str() Database user name.
|
||||
password : str() Database password.
|
||||
db_host : str() Database host.
|
||||
db_port : int() Database port.
|
||||
file_array : list() copy of book_shelf TODO: See book_shelf
|
||||
auto_scan: bool() Do we auto scan on launch?
|
||||
allowed_hosts : list() Allowed host list.
|
||||
db_engine : str() Desired database engine type.
|
||||
db_user : str() Database user name. Duplication Warning.
|
||||
db_pass : str() Database password. Duplication Warning.
|
||||
build_mode : str() Production | Development mode.
|
||||
|
||||
Methods
|
||||
-------
|
||||
get_logger : Setup loguru.
|
||||
open_file : Parse configuration file.
|
||||
"""
|
||||
|
||||
def __init__(self, root):
|
||||
"""Initialize main configuration options."""
|
||||
|
||||
46
src/backend/lib/storage.py
vendored
46
src/backend/lib/storage.py
vendored
@@ -8,7 +8,25 @@ from .models import Book, Collection
|
||||
|
||||
|
||||
class Storage:
|
||||
"""Contains all methods for system storage."""
|
||||
"""Create a new Storage object.
|
||||
|
||||
>>> db = Storage(config)
|
||||
|
||||
Parameters
|
||||
----------
|
||||
config : Config()
|
||||
Main program configuration.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
config : Stores configuration
|
||||
sql : Database Name
|
||||
user : Database User Name
|
||||
password : Database Password
|
||||
db_host : Database Host
|
||||
db_port : Database Port
|
||||
engine : sqlalchemy.create_engine(url, executor, kw)
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""Initialize storage object."""
|
||||
@@ -25,6 +43,10 @@ class Storage:
|
||||
"""Get connection string.
|
||||
|
||||
Engine type references config.json:DB_ENGINE.
|
||||
|
||||
Returns
|
||||
-------
|
||||
str : sqlalchemy Connection String
|
||||
"""
|
||||
if self.config.db_engine == "sqlite":
|
||||
if os.path.exists(f"{self.config.root}/pyshelf.db"):
|
||||
@@ -49,7 +71,15 @@ class Storage:
|
||||
def insert_book(self, book):
|
||||
"""Insert a new book into the database.
|
||||
|
||||
:returns: True if succeeds False if not
|
||||
Parameters
|
||||
----------
|
||||
book: dict()
|
||||
Book object to insert.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
True on success False on failure
|
||||
"""
|
||||
with Session(self.engine) as session:
|
||||
try:
|
||||
@@ -81,14 +111,22 @@ class Storage:
|
||||
self.config.logger.error(f"{book[0][0:80]} :: {e}")
|
||||
|
||||
def book_paths_list(self):
|
||||
"""Get file paths from database for comparison to system files."""
|
||||
"""Get file paths from database for comparison to system files.
|
||||
|
||||
Returns
|
||||
-------
|
||||
_result : ScalarResult Object
|
||||
"""
|
||||
session = Session(self.engine)
|
||||
_result = session.scalars(select(Book.file_name)).fetchall()
|
||||
session.close()
|
||||
return _result
|
||||
|
||||
def make_collections(self):
|
||||
"""Make collections."""
|
||||
"""Parse book path's to determine common folder structure.
|
||||
|
||||
Stores collections based on shared paths.
|
||||
"""
|
||||
# TODO: Check this still works with the switch to sqlalchemy
|
||||
self.config.logger.info("Making collections.")
|
||||
_title_regx = re.compile(r"^[0-9][0-9]*|-|\ \B")
|
||||
|
||||
Reference in New Issue
Block a user