diff --git a/.gitignore b/.gitignore index dac41a8..5dd18a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.pyc __pycache__/ -rqlite* +rqlite/ xppl/cover/** xppl/uploads/** .tox diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..71559ef --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +RQLITE_DIR := rqlite +RQLITE_TAR := rqlite-v4.3.0-linux-amd64.tar.gz +RQLITE_UNTAR := rqlite-v4.3.0-linux-amd64 +RQLITE_URL := https://github.com/rqlite/rqlite/releases/download/v4.3.0/rqlite-v4.3.0-linux-amd64.tar.gz + +install-rqlite: + @mkdir -p $(RQLITE_DIR) + @sudo apt update && sudo apt install -y curl + @curl -L $(RQLITE_URL) -o $(RQLITE_DIR)/$(RQLITE_TAR) + @tar xvfz $(RQLITE_DIR)/$(RQLITE_TAR) -C $(RQLITE_DIR) + +rqlited: + @./$(RQLITE_DIR)/$(RQLITE_UNTAR)/rqlited $(RQLITE_DIR)/node.1 +.PHONY: rqlited + +rqlite: + @./$(RQLITE_DIR)/$(RQLITE_UNTAR)/rqlite +.PHONY: rqlite diff --git a/README.md b/README.md index 41d3991..8888ff5 100644 --- a/README.md +++ b/README.md @@ -9,20 +9,29 @@ The [XPUB] library living at [Varia]. # Hack It -You'll need to run an [RQLite] database first. It's easy with Docker: +You'll need to run an [RQLite] database first: ``` -$ curl -sSL https://get.docker.com/ | sh -$ docker run -p 4001:4001 -p 4002:4002 -d rqlite/rqlite +$ apt update && apt install -y make +$ make install-rqlite +$ make rqlited ``` Then get [Pipenv] and run the development server with: ```bash $ pipenv install --dev --three -$ pipenv run dev +$ pipenv run devserver ``` +If you need to check the database contents, run: + +```bash +$ make rqlite +``` + +And then run `.help` for which commands are available. + [Pipenv]: https://pipenv.readthedocs.io/en/latest/install/#pragmatic-installation-of-pipenv [RQLite]: https://github.com/rqlite/rqlite diff --git a/xppl/app.py b/xppl/app.py index 23b7cf8..31b60bb 100644 --- a/xppl/app.py +++ b/xppl/app.py @@ -1,5 +1,8 @@ """Main application factory.""" +from os import makedirs +from os.path import exists + from dotenv import find_dotenv, load_dotenv from flask import Flask from sqlalchemy.dialects import registry @@ -14,6 +17,7 @@ def create_app(config): configure_pyrqlite() configure_socketio(app) configure_sqlalchemy(app) + configure_uploads(app) with app.app_context(): from xppl import views # noqa @@ -55,3 +59,14 @@ def configure_socketio(app): from xppl.socketio import socketio socketio.init_app(app) + + +def configure_uploads(app): + """Setup the uploads folder.""" + upload_paths = [ + app.config['UPLOAD_FOLDER'], + app.config['UPLOAD_FOLDER_COVER'], + ] + for path in upload_paths: + if not exists(path): + makedirs(path) diff --git a/xppl/config.py b/xppl/config.py index acc3e0c..2cba99b 100644 --- a/xppl/config.py +++ b/xppl/config.py @@ -1,20 +1,15 @@ """The Application settings.""" -from os import environ, urandom +from os import urandom from os.path import abspath, dirname, isdir, join +BASEDIR = abspath(dirname(__file__)) + class Base(): """The base configuration.""" - BASEDIR = abspath(dirname(__file__)) - - UPLOAD_FOLDER_COVER = join(BASEDIR, 'cover') - UPLOAD_FOLDER = join(BASEDIR, 'uploads') - LIGHT = isdir(UPLOAD_FOLDER) - DEBUG = False TESTING = False - SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_DATABASE_URI = 'rqlite+pyrqlite://localhost:4001/' @@ -31,7 +26,7 @@ class Development(Base): DEBUG = True TESTING = True DOMAIN = 'http://localhost' - SECRET_KEY = environ.get( - 'XPPL_SECRET_KEY', - urandom(24).hex() - ) + SECRET_KEY = urandom(24).hex() + UPLOAD_FOLDER_COVER = join(BASEDIR, 'cover') + UPLOAD_FOLDER = join(BASEDIR, 'uploads') + LIGHT = not isdir(UPLOAD_FOLDER) diff --git a/xppl/cover.py b/xppl/cover.py index 2da1bb0..37d17d3 100755 --- a/xppl/cover.py +++ b/xppl/cover.py @@ -52,7 +52,7 @@ def get_cover(file_path, filename): # Convert each page to a png image. for page in pages: - big_filename = "app/cover/"+page["filename"] + "_cover.jpeg" + big_filename = "xppl/cover/"+page["filename"] + "_cover.jpeg" img = pdf_page_to_png(src_pdf, pagenum=page["pagenum"], resolution=130) diff --git a/xppl/extractText.py b/xppl/extractText.py index 91f6987..d0bb9cb 100644 --- a/xppl/extractText.py +++ b/xppl/extractText.py @@ -3,7 +3,7 @@ import PyPDF2 def get_text(file_path, filename): read_pdf = file_path - write_txt = "app/uploads/" + filename + '.txt' + write_txt = "xppl/uploads/" + filename + '.txt' with open(read_pdf, 'rb') as pdf_file, open(write_txt, 'w') as text_file: read_pdf = PyPDF2.PdfFileReader(pdf_file) diff --git a/xppl/views.py b/xppl/views.py index 530082f..24603e0 100755 --- a/xppl/views.py +++ b/xppl/views.py @@ -467,7 +467,7 @@ def add_book(): pbooks=pbooks ) html = HTML(string=html_string) - html.write_pdf(target='app/uploads/potential.pdf') + html.write_pdf(target='xppl/uploads/potential.pdf') book = Book( title,