From 1ad708ad10f7ea743ff5d567b82bfd0d9b428198 Mon Sep 17 00:00:00 2001 From: th3r00t Date: Mon, 28 Nov 2022 23:01:27 -0500 Subject: [PATCH] Began documentation rewrite. --- src/backend/lib/config.py | 39 +++++++++++++++++++++++++++++++- src/backend/lib/storage.py | 46 ++++++++++++++++++++++++++++++++++---- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/src/backend/lib/config.py b/src/backend/lib/config.py index 261f1d4..7daef9e 100755 --- a/src/backend/lib/config.py +++ b/src/backend/lib/config.py @@ -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.""" diff --git a/src/backend/lib/storage.py b/src/backend/lib/storage.py index 951045d..a073dee 100644 --- a/src/backend/lib/storage.py +++ b/src/backend/lib/storage.py @@ -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")