Skip to content

Commit

Permalink
Merge pull request #66 from noisebridge/superq/py3
Browse files Browse the repository at this point in the history
Update for Python 3
  • Loading branch information
SuperQ authored Oct 27, 2023
2 parents 045eb32 + 904842c commit f551045
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 15 deletions.
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.11

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libsqlite3-dev \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY . /app/

RUN pip install -r /app/requirements.txt

EXPOSE 8000

ENTRYPOINT ["/usr/bin/env", "python3", "/app/controller.py"]
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ Alpha released.
6. python controller.py
7. go to [localhost:5000] (http://localhost:5000) in the browser

##### Docker

Build the Docker image:

docker build -t library-org .

Run the Docker image:

docker run \
-p 5000:5000
-v /path/to/library.cfg:/app/library.cfg \
-v /path/to/books.sqlite:/app/database/books.sqlite \
localhost/library-org:latest

##### Features on-deck:

Expand Down
13 changes: 8 additions & 5 deletions controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@

import os

from ConfigParser import SafeConfigParser
import configparser


PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))

CONFIG_FILE = "library.cfg"
CONFIG_PATH = os.path.join(PROJECT_ROOT, CONFIG_FILE)
CONFIG = SafeConfigParser()
CONFIG = configparser.ConfigParser()
CONFIG.read(CONFIG_PATH)

# Network configuration
host = CONFIG.get("config", "host")

# Configuration Secrets
APP_SECRET_KEY = CONFIG.get("secrets", "APP_SECRET_KEY")
WTF_CSRF_SECRET_KEY = CONFIG.get("secrets", "WTF_CSRF_SECRET_KEY")
Expand Down Expand Up @@ -378,17 +381,17 @@ def index(page=1):
# do a search if you have a search term
# (make this more general for an all fields search)
if s:
books = Book.query.order_by(Book.title.asc()).filter(or_(Book.title.contains(s), Book.authors.contains(s), Book.subjects.contains(s))).paginate(page,PAGINATE_BY_HOWMANY,False)
books = Book.query.order_by(Book.title.asc()).filter(or_(Book.title.contains(s), Book.authors.contains(s), Book.subjects.contains(s))).paginate(page=page, per_page=PAGINATE_BY_HOWMANY, error_out=False)

# return all books, currently sort by title ascending.
else:
books = Book.query.order_by(Book.title.asc()).paginate(page,PAGINATE_BY_HOWMANY,False)
books = Book.query.order_by(Book.title.asc()).paginate(page=page, per_page=PAGINATE_BY_HOWMANY, error_out=False)

return render_template('index.html', books=books, s=s)

if __name__ == "__main__":
# flask can execute arbitrary python if you do this.
# app.run(host='0.0.0.0') # listens on all public IPs.

app.run()
app.run(host=host)

4 changes: 3 additions & 1 deletion library.cfg_EXAMPLE
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

[config]
# Use "0.0.0.0" for containers.
host = "127.0.0.1"

[secrets]

Expand Down
17 changes: 8 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
Flask==2.2.5
Flask-SQLAlchemy==2.4.0
Flask-WTF==0.14.2
Jinja2==2.11.3
MarkupSafe==1.1.1
SQLAlchemy==1.3.5
WTForms==2.2.1
Werkzeug==3.0.1
Flask-SQLAlchemy>=2.5.1
Flask-WTF==0.15.1
Jinja2>=3.0
MarkupSafe>=2.1.1
SQLAlchemy>=2.0.0
WTForms==2.3.3
Werkzeug==2.3.7
argparse==1.4.0
itsdangerous==1.1.0
itsdangerous>=2.0
requests==2.31.0
uWSGI==2.0.22
wheel==0.38.1
wsgiref==0.1.2

0 comments on commit f551045

Please sign in to comment.