Remove docker, just us plain RQLite.
Also a number of small changes to get this all to work.
This commit is contained in:
parent
5c56aeca09
commit
6bea76accb
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,6 +1,6 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
__pycache__/
|
__pycache__/
|
||||||
rqlite*
|
rqlite/
|
||||||
xppl/cover/**
|
xppl/cover/**
|
||||||
xppl/uploads/**
|
xppl/uploads/**
|
||||||
.tox
|
.tox
|
||||||
|
18
Makefile
Normal file
18
Makefile
Normal file
@ -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
|
17
README.md
17
README.md
@ -9,20 +9,29 @@ The [XPUB] library living at [Varia].
|
|||||||
|
|
||||||
# Hack It
|
# 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
|
$ apt update && apt install -y make
|
||||||
$ docker run -p 4001:4001 -p 4002:4002 -d rqlite/rqlite
|
$ make install-rqlite
|
||||||
|
$ make rqlited
|
||||||
```
|
```
|
||||||
|
|
||||||
Then get [Pipenv] and run the development server with:
|
Then get [Pipenv] and run the development server with:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ pipenv install --dev --three
|
$ 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
|
[Pipenv]: https://pipenv.readthedocs.io/en/latest/install/#pragmatic-installation-of-pipenv
|
||||||
[RQLite]: https://github.com/rqlite/rqlite
|
[RQLite]: https://github.com/rqlite/rqlite
|
||||||
|
|
||||||
|
15
xppl/app.py
15
xppl/app.py
@ -1,5 +1,8 @@
|
|||||||
"""Main application factory."""
|
"""Main application factory."""
|
||||||
|
|
||||||
|
from os import makedirs
|
||||||
|
from os.path import exists
|
||||||
|
|
||||||
from dotenv import find_dotenv, load_dotenv
|
from dotenv import find_dotenv, load_dotenv
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from sqlalchemy.dialects import registry
|
from sqlalchemy.dialects import registry
|
||||||
@ -14,6 +17,7 @@ def create_app(config):
|
|||||||
configure_pyrqlite()
|
configure_pyrqlite()
|
||||||
configure_socketio(app)
|
configure_socketio(app)
|
||||||
configure_sqlalchemy(app)
|
configure_sqlalchemy(app)
|
||||||
|
configure_uploads(app)
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
from xppl import views # noqa
|
from xppl import views # noqa
|
||||||
@ -55,3 +59,14 @@ def configure_socketio(app):
|
|||||||
from xppl.socketio import socketio
|
from xppl.socketio import socketio
|
||||||
|
|
||||||
socketio.init_app(app)
|
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)
|
||||||
|
@ -1,20 +1,15 @@
|
|||||||
"""The Application settings."""
|
"""The Application settings."""
|
||||||
|
|
||||||
from os import environ, urandom
|
from os import urandom
|
||||||
from os.path import abspath, dirname, isdir, join
|
from os.path import abspath, dirname, isdir, join
|
||||||
|
|
||||||
|
BASEDIR = abspath(dirname(__file__))
|
||||||
|
|
||||||
|
|
||||||
class Base():
|
class Base():
|
||||||
"""The base configuration."""
|
"""The base configuration."""
|
||||||
BASEDIR = abspath(dirname(__file__))
|
|
||||||
|
|
||||||
UPLOAD_FOLDER_COVER = join(BASEDIR, 'cover')
|
|
||||||
UPLOAD_FOLDER = join(BASEDIR, 'uploads')
|
|
||||||
LIGHT = isdir(UPLOAD_FOLDER)
|
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
TESTING = False
|
TESTING = False
|
||||||
|
|
||||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
SQLALCHEMY_DATABASE_URI = 'rqlite+pyrqlite://localhost:4001/'
|
SQLALCHEMY_DATABASE_URI = 'rqlite+pyrqlite://localhost:4001/'
|
||||||
|
|
||||||
@ -31,7 +26,7 @@ class Development(Base):
|
|||||||
DEBUG = True
|
DEBUG = True
|
||||||
TESTING = True
|
TESTING = True
|
||||||
DOMAIN = 'http://localhost'
|
DOMAIN = 'http://localhost'
|
||||||
SECRET_KEY = environ.get(
|
SECRET_KEY = urandom(24).hex()
|
||||||
'XPPL_SECRET_KEY',
|
UPLOAD_FOLDER_COVER = join(BASEDIR, 'cover')
|
||||||
urandom(24).hex()
|
UPLOAD_FOLDER = join(BASEDIR, 'uploads')
|
||||||
)
|
LIGHT = not isdir(UPLOAD_FOLDER)
|
||||||
|
@ -52,7 +52,7 @@ def get_cover(file_path, filename):
|
|||||||
|
|
||||||
# Convert each page to a png image.
|
# Convert each page to a png image.
|
||||||
for page in pages:
|
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)
|
img = pdf_page_to_png(src_pdf, pagenum=page["pagenum"], resolution=130)
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import PyPDF2
|
|||||||
|
|
||||||
def get_text(file_path, filename):
|
def get_text(file_path, filename):
|
||||||
read_pdf = file_path
|
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:
|
with open(read_pdf, 'rb') as pdf_file, open(write_txt, 'w') as text_file:
|
||||||
read_pdf = PyPDF2.PdfFileReader(pdf_file)
|
read_pdf = PyPDF2.PdfFileReader(pdf_file)
|
||||||
|
@ -467,7 +467,7 @@ def add_book():
|
|||||||
pbooks=pbooks
|
pbooks=pbooks
|
||||||
)
|
)
|
||||||
html = HTML(string=html_string)
|
html = HTML(string=html_string)
|
||||||
html.write_pdf(target='app/uploads/potential.pdf')
|
html.write_pdf(target='xppl/uploads/potential.pdf')
|
||||||
|
|
||||||
book = Book(
|
book = Book(
|
||||||
title,
|
title,
|
||||||
|
Loading…
Reference in New Issue
Block a user