Skip to content

Commit f551045

Browse files
authored
Merge pull request #66 from noisebridge/superq/py3
Update for Python 3
2 parents 045eb32 + 904842c commit f551045

File tree

5 files changed

+52
-15
lines changed

5 files changed

+52
-15
lines changed

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM python:3.11
2+
3+
ENV PYTHONDONTWRITEBYTECODE=1
4+
ENV PYTHONUNBUFFERED=1
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
RUN apt-get update \
8+
&& apt-get install -y --no-install-recommends \
9+
libsqlite3-dev \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
WORKDIR /app
13+
14+
COPY . /app/
15+
16+
RUN pip install -r /app/requirements.txt
17+
18+
EXPOSE 8000
19+
20+
ENTRYPOINT ["/usr/bin/env", "python3", "/app/controller.py"]

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ Alpha released.
1717
6. python controller.py
1818
7. go to [localhost:5000] (http://localhost:5000) in the browser
1919

20+
##### Docker
21+
22+
Build the Docker image:
23+
24+
docker build -t library-org .
25+
26+
Run the Docker image:
27+
28+
docker run \
29+
-p 5000:5000
30+
-v /path/to/library.cfg:/app/library.cfg \
31+
-v /path/to/books.sqlite:/app/database/books.sqlite \
32+
localhost/library-org:latest
2033

2134
##### Features on-deck:
2235

controller.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@
1616

1717
import os
1818

19-
from ConfigParser import SafeConfigParser
19+
import configparser
2020

2121

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

2424
CONFIG_FILE = "library.cfg"
2525
CONFIG_PATH = os.path.join(PROJECT_ROOT, CONFIG_FILE)
26-
CONFIG = SafeConfigParser()
26+
CONFIG = configparser.ConfigParser()
2727
CONFIG.read(CONFIG_PATH)
2828

29+
# Network configuration
30+
host = CONFIG.get("config", "host")
31+
2932
# Configuration Secrets
3033
APP_SECRET_KEY = CONFIG.get("secrets", "APP_SECRET_KEY")
3134
WTF_CSRF_SECRET_KEY = CONFIG.get("secrets", "WTF_CSRF_SECRET_KEY")
@@ -378,17 +381,17 @@ def index(page=1):
378381
# do a search if you have a search term
379382
# (make this more general for an all fields search)
380383
if s:
381-
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)
384+
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)
382385

383386
# return all books, currently sort by title ascending.
384387
else:
385-
books = Book.query.order_by(Book.title.asc()).paginate(page,PAGINATE_BY_HOWMANY,False)
388+
books = Book.query.order_by(Book.title.asc()).paginate(page=page, per_page=PAGINATE_BY_HOWMANY, error_out=False)
386389

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

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

393-
app.run()
396+
app.run(host=host)
394397

library.cfg_EXAMPLE

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
1+
[config]
2+
# Use "0.0.0.0" for containers.
3+
host = "127.0.0.1"
24

35
[secrets]
46

requirements.txt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
Flask==2.2.5
2-
Flask-SQLAlchemy==2.4.0
3-
Flask-WTF==0.14.2
4-
Jinja2==2.11.3
5-
MarkupSafe==1.1.1
6-
SQLAlchemy==1.3.5
7-
WTForms==2.2.1
8-
Werkzeug==3.0.1
2+
Flask-SQLAlchemy>=2.5.1
3+
Flask-WTF==0.15.1
4+
Jinja2>=3.0
5+
MarkupSafe>=2.1.1
6+
SQLAlchemy>=2.0.0
7+
WTForms==2.3.3
8+
Werkzeug==2.3.7
99
argparse==1.4.0
10-
itsdangerous==1.1.0
10+
itsdangerous>=2.0
1111
requests==2.31.0
1212
uWSGI==2.0.22
1313
wheel==0.38.1
14-
wsgiref==0.1.2

0 commit comments

Comments
 (0)