From 44a376f172b3d9cf24ca7a49735e8afd2801d461 Mon Sep 17 00:00:00 2001 From: th3r00t Date: Mon, 27 Nov 2023 15:21:23 -0500 Subject: [PATCH] Refactoring Collections, and getting docker ready. --- docker/Dockerfile | 23 ++++++++++++++---- docker/README.md | 2 -- docker/config.json | 6 ++--- docker/development.docker-compose.yml | 34 ++++++++++++++------------- docker/docker-compose.yml | 28 ++++++++++++---------- pyShelf.py | 3 +-- pyproject.toml | 4 ++-- src/backend/lib/models.py | 3 +-- src/backend/lib/storage.py | 4 +++- src/frontend/lib/objects.py | 17 ++------------ 10 files changed, 63 insertions(+), 61 deletions(-) mode change 100755 => 100644 pyShelf.py diff --git a/docker/Dockerfile b/docker/Dockerfile index d178cd7..401be3f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -9,17 +9,30 @@ # docker login # docker push pyshelf/pyshelf -FROM python:3 +FROM ubuntu:latest -EXPOSE 8000 +EXPOSE 8080 EXPOSE 1337 -# RUN apt-get update -y -# RUN DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential python312 python312-dev python312-pip python312-venv python312-hatch +RUN apt-get update -y +RUN apt-get upgrade -y +RUN apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev \ +libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget \ +libbz2-dev curl -y +RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash +RUN export NVM_DIR="$HOME/.nvm" ; \ +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" ; nvm install 14 npm +WORKDIR /tmp +RUN wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz +RUN tar -xf Python-3.12.0.tgz +WORKDIR /tmp/Python-3.12.0/ +RUN ./configure --enable-optimizations +RUN make -j 4 +RUN make install COPY . /pyshelf COPY ./docker/config.json /pyshelf/config.json COPY ./docker/requirements.txt /pyshelf/requirements.txt WORKDIR /pyshelf/ -RUN python -m pip install --no-cache-dir -r requirements.txt +RUN python3 -m pip install --no-cache-dir -r requirements.txt ENTRYPOINT hatch run ./pyShelf.py diff --git a/docker/README.md b/docker/README.md index 2c6f0d1..1892116 100644 --- a/docker/README.md +++ b/docker/README.md @@ -2,5 +2,3 @@ Use `docker build -t pyshelf/pyshelf -f ./docker/Dockerfile .` in the project ro Make sure the following files are in sync: * config.json -* docker/pyshelf_nginx.conf -* uwsgi.ini \ No newline at end of file diff --git a/docker/config.json b/docker/config.json index d4be7f5..e9f4c58 100644 --- a/docker/config.json +++ b/docker/config.json @@ -2,9 +2,9 @@ "TITLE": "pyShelf E-Book Server", "VERSION": "0.8.0", "BOOKPATH": "/books", - "DB_HOST": "localhost", - "DB_PORT": "5432", - "DB_ENGINE": "psql", + "DB_HOST": "127.0.0.1", + "DB_PORT": "5433", + "DB_ENGINE": "sqlite", "DATABASE": "pyshelf", "USER": "pyshelf", "PASSWORD": "pyshelf", diff --git a/docker/development.docker-compose.yml b/docker/development.docker-compose.yml index f6d97fe..138c4a8 100644 --- a/docker/development.docker-compose.yml +++ b/docker/development.docker-compose.yml @@ -1,34 +1,36 @@ version: "3.7" -# This file is used to test the Dockerhub image. To host pyShelf yourself for -# production, please use the official pyShelf image on +# This file is used to test the Dockerhub image. To host pyShelf yourself for +# production, please use the official pyShelf image on # https://hub.docker.com/r/pyshelf/pyshelf # For development, use the following command in the root folder: -# +# # docker-compose -f ./docker/development.docker-compose.yml up --build services: - db: - image: "postgres" - environment: - - "POSTGRES_PASSWORD=pyshelf" - - "POSTGRES_USER=pyshelf" - - "POSTGRES_DB=pyshelf" - volumes: - - "db_data:/var/lib/postgresql/data/" +# db: +# image: "postgres" +# environment: +# - "POSTGRES_PASSWORD=pyshelf" +# - "POSTGRES_USER=pyshelf" +# - "POSTGRES_DB=pyshelf" +# volumes: +# - "db_data:/var/lib/postgresql/data/" +# ports: +# - "5433:5432" pyshelf: build: context: .. dockerfile: ./docker/Dockerfile - ports: + ports: - "8080:8000" - "1337:1337" volumes: - "${LOCAL_BOOK_DIR}:/books" - depends_on: - - db +# depends_on: +# - db -volumes: - db_data: +# volumes: +# db_data: diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 743bd9b..864b417 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,15 +1,17 @@ version: "3.7" services: - db: - image: "postgres" - restart: always - environment: - - "POSTGRES_PASSWORD=pyshelf" - - "POSTGRES_USER=pyshelf" - - "POSTGRES_DB=pyshelf" - volumes: - - "db_data:/var/lib/postgresql/data/" +# db: +# image: "postgres" +# restart: always +# environment: +# - "POSTGRES_PASSWORD=pyshelf" +# - "POSTGRES_USER=pyshelf" +# - "POSTGRES_DB=pyshelf" +# volumes: +# - "db_data:/var/lib/postgresql/data/" +# ports: +# - "5433:5432" pyshelf: image: "pyshelf/pyshelf" restart: always @@ -18,7 +20,7 @@ services: - "1337:1337" volumes: - "${LOCAL_BOOK_DIR}:/books" - depends_on: - - db -volumes: - db_data: +# depends_on: +# - db +#volumes: +# db_data: diff --git a/pyShelf.py b/pyShelf.py old mode 100755 new mode 100644 index d626abc..15f860e --- a/pyShelf.py +++ b/pyShelf.py @@ -6,7 +6,6 @@ from pathlib import Path from threading import Thread from src.backend.lib.config import Config from src.backend.lib.storage import Storage -from src.backend.pyShelf_MakeCollections import MakeCollections from src.backend.pyShelf_ScanLibrary import execute_scan from src.frontend.lib.FastAPIServer import FastAPIServer # import websockets @@ -23,7 +22,7 @@ def run_import(): config.logger.info("Begining book import.") execute_scan(PRG_PATH, config=config) config.logger.info("Finished book import.") - MakeCollections(PRG_PATH, config=config) + # MakeCollections(PRG_PATH, config=config) return "Import Complete" diff --git a/pyproject.toml b/pyproject.toml index fed2262..788830d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ classifiers = [ "Programming Language :: Python :: Implementation :: PyPy", ] dependencies = [ - "websockets", "loguru", "pypdf2", "bs4", "requests", "psycopg2", + "websockets", "loguru", "pypdf2", "bs4", "requests", "psycopg2-binary", "mobi-python", "lxml", "sqlalchemy", "sqlalchemy.orm", "fastapi[all]", "jinja2", "libsass", "nodejs-bin", "npm", "brotlipy", "debugpy", "pudb", "ptipython", "chardet", "pre-commit" @@ -165,4 +165,4 @@ use_parentheses = true # NOTE: the known_third_party setting is managed by # seed-isort-config and should not be modified directly. # Any changes made to this setting will be overwritten. -known_third_party = ["backend", "bs4", "django", "interface", "mobi", "prompt_toolkit", "psycopg2", "pyfiglet", "requests"] +known_third_party = ["backend", "bs4", "django", "interface", "mobi", "prompt_toolkit", "psycopg2-binary", "pyfiglet", "requests"] diff --git a/src/backend/lib/models.py b/src/backend/lib/models.py index 9258b52..6609632 100644 --- a/src/backend/lib/models.py +++ b/src/backend/lib/models.py @@ -1,6 +1,6 @@ from typing import Optional from typing_extensions import Annotated -from sqlalchemy import func, ForeignKey +from sqlalchemy import func from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column import datetime @@ -42,4 +42,3 @@ class Collection(Base): id: Mapped[int] = mapped_column(primary_key=True) collection: Mapped[str] - book_id: Mapped[int] = mapped_column(ForeignKey(Book.id)) diff --git a/src/backend/lib/storage.py b/src/backend/lib/storage.py index 259ff53..592da4f 100644 --- a/src/backend/lib/storage.py +++ b/src/backend/lib/storage.py @@ -86,7 +86,8 @@ class Storage: cover_image = None if not book[1]: pass - collections = self.parse_collections_from_path(book) + # collections = self.parse_collections_from_path(book) + # breakpoint() _book = Book( title=book[0], author=book[1], @@ -173,6 +174,7 @@ class Storage: _q = _sess.execute( select(Collection.id).where( Collection.collection == _s, + # BUG: book.id is not the correct identifier. Collection.book_id == book.id, ) ) diff --git a/src/frontend/lib/objects.py b/src/frontend/lib/objects.py index 149ff4d..55af696 100644 --- a/src/frontend/lib/objects.py +++ b/src/frontend/lib/objects.py @@ -1,6 +1,4 @@ """pyShelf's Frontend Objects.""" -from sys import exit -from shutil import which from subprocess import run from pathlib import Path from ...backend.lib.config import Config @@ -16,16 +14,5 @@ class JSInterface(): def install(self): """Install the JavaScript dependencies.""" - if which("npm"): - self.config.logger.info("Installing JavaScript dependencies...") - run(["npm", "install"], cwd=self.package_json.parent) - - else: - self.config.logger.error("npm is not installed.") - exit(1) - if which("npx"): - self.config.logger.info("Compiling TypeScript...") - run(["npx", "tsc", "static/script/pyshelf.ts"], cwd=self.package_json.parent) - else: - self.config.logger.error("npx is not installed.") - exit(1) + run(["npm", "install"], cwd=self.package_json.parent) + run(["npx", "tsc", "static/script/pyshelf.ts"], cwd=self.package_json.parent)