Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to python3, latest packages, latest OS! #32

Merged
merged 8 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Bionic
FROM ubuntu:18.04
FROM ubuntu:24.04
# 24.04 provides python 3.12

ENV DEBIAN_FRONTEND=noninteractive

Expand All @@ -11,14 +11,15 @@ ENV PYTHON=$VENV/bin/python

RUN mkdir $BASE

RUN apt-get update
RUN apt-get install -y nginx python-dev libjpeg62 libjpeg-dev libfreetype6 libfreetype6-dev libtiff5 libtiff5-dev libwebp6 libwebp-dev zlib1g-dev run-one
RUN apt-get install -y curl \
&& curl https://bootstrap.pypa.io/pip/2.7/get-pip.py | python \
&& pip --version
RUN pip install -U pip
RUN python -m pip install -U virtualenv
RUN virtualenv -p python2.7 $VENV
RUN apt-get update && apt-get install -y \
nginx \
run-one \
python3 \
python3-venv \
python-is-python3 \
&& rm -rf /var/lib/apt/lists/*
RUN python -m venv $VENV
RUN $PIP install --upgrade pip

WORKDIR $CODE

Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ run_production:
sudo service waznex-process-grid restart
sudo service nginx restart

DOCKER_BUILD := docker build --platform linux/amd64 -t waznexserver .
DOCKER_BUILD := docker build -t waznexserver .

.PHONY: docker_build
docker_build:
Expand All @@ -79,9 +79,13 @@ docker_build:
.PHONY: docker_dev
docker_dev:
# (re)builds the latest image and runs it
docker run --rm --platform linux/amd64 -p 8080:8080 -it $(shell $(DOCKER_BUILD) -q)
docker run --rm -p 8080:8080 -it $(shell $(DOCKER_BUILD) -q)

.PHONY: docker_dev_process
docker_dev_process:
# connects to existing docker_dev and runs the processing script
docker exec -it $(shell docker ps -q --filter ancestor=waznexserver) waznexserver/process_grid.py

.PHONY: update_deps
update_deps:
uv pip compile requirements.in -o requirements.txt
10 changes: 5 additions & 5 deletions gridsplitter/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def FindRow(dots, tlDotIndex, rowNum):

# Downsize the search space to speed things up and make the search
# more accurate
imageSearch = imageLuminance.resize(searchSize, Image.ANTIALIAS)
imageSearch = imageLuminance.resize(searchSize, Image.LANCZOS)

# Find all of the dots in the image
dots = TransformDots(FindDots(imageSearch), imageSearch, imageOriginal)
Expand Down Expand Up @@ -288,8 +288,8 @@ def FindRow(dots, tlDotIndex, rowNum):
try:# Generate a row-wide vector
rightDot = rightRowDots[row + 1]
rowVec = (dots[rightDot][0] - dots[leftDot][0], dots[rightDot][1] - dots[leftDot][1])
except:
print("rightRowDots: {}".format(rightRowDots))
except Exception:
print(f"rightRowDots: {rightRowDots}")

for col, topDot in enumerate(topColumnDots[1:-1]):
# Generate a column-wide vector
Expand Down Expand Up @@ -329,14 +329,14 @@ def FindRow(dots, tlDotIndex, rowNum):
# Parse parameters
if(len(sys.argv) <= 1 or sys.argv[1] == "--help"):
print("Usage: slice.py inputfile [color [outputdir [width height]]]")
print
print()
print("inputfile = The input image file")
print("color = The dot color to search for: 0 = Red, 1 = Green, 2 = Blue")
print("outputdir = The directory to output slices to. Defaults to")
print(" a directory with the same name as the input file.")
print("width = Desired width, in pixels, of output image.")
print("height = Desired height, in pixels, of output image.")
print
print()
print("Exit status for this script is the number of slices output.")
exit(0)

Expand Down
8 changes: 8 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Flask
Flask-SQLAlchemy
gunicorn
Jinja2
Pillow
SQLAlchemy
timeago
Werkzeug
56 changes: 40 additions & 16 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
certifi==2019.6.16
chardet==3.0.4
Click==7.0
Flask==1.1.1
Flask-SQLAlchemy==2.4.0
gunicorn==19.9.0
idna==2.8
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
Pillow==6.1.0
requests==2.22.0
SQLAlchemy==1.3.6
timeago==1.0.15
urllib3==1.25.3
Werkzeug==0.15.5
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in -o requirements.txt
blinker==1.9.0
# via flask
click==8.1.8
# via flask
flask==3.1.0
# via
# -r requirements.in
# flask-sqlalchemy
flask-sqlalchemy==3.1.1
# via -r requirements.in
gunicorn==23.0.0
# via -r requirements.in
itsdangerous==2.2.0
# via flask
jinja2==3.1.5
# via
# -r requirements.in
# flask
markupsafe==3.0.2
# via
# jinja2
# werkzeug
packaging==24.2
# via gunicorn
pillow==11.1.0
# via -r requirements.in
sqlalchemy==2.0.36
# via
# -r requirements.in
# flask-sqlalchemy
timeago==1.0.16
# via -r requirements.in
typing-extensions==4.12.2
# via sqlalchemy
werkzeug==3.1.3
# via
# -r requirements.in
# flask
1 change: 0 additions & 1 deletion waznexserver/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
5 changes: 2 additions & 3 deletions waznexserver/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import os

# Configuration
Expand All @@ -12,10 +11,10 @@
IMAGE_FOLDER = os.path.join(DATA_FOLDER, 'images')
DOWNSIZED_FOLDER = os.path.join(DATA_FOLDER, 'downsized')
THUMBNAIL_FOLDER = os.path.join(DATA_FOLDER, 'thumbnails')
ALLOWED_EXTENSIONS = set(['png', 'PNG',
ALLOWED_EXTENSIONS = {'png', 'PNG',
'jpg', 'JPG',
'jpeg', 'JPEG',
'gif', 'GIF'])
'gif', 'GIF'}
FILE_NAME_DT_FORMAT = '%Y-%m-%dT%H%M%S'
PRETTY_DT_FORMAT = '%m/%d/%Y %I:%M:%S %p'
ENABLE_GRIDSPLITTER = True
Expand Down
37 changes: 23 additions & 14 deletions waznexserver/init_data.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,55 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-


import os
import sys
import traceback

from waznexserver import db
import models
import config
import models
from models import db
from waznexserver import create_app

if __name__ == '__main__':
# Create data dirs

def create_data_dirs():
data_folders = [df for df in dir(config) if df.endswith('_FOLDER')]
for folder in data_folders:
newdir = os.path.abspath(getattr(config, folder))
print newdir
print(newdir)
if not os.path.exists(newdir): # If it doesn't exist, try to make it
try:
os.mkdir(newdir)
except OSError:
print "Unable to create data directory: " + newdir
print "Error was: %s" % (sys.exc_info()[1],)
print("Unable to create data directory: " + newdir)
traceback.print_exc()
exit(1)
if not os.path.exists(newdir): # Make sure it's there now
print "Unable to find or create data directory: " + newdir
print("Unable to find or create data directory: " + newdir)
exit(1)

# Create database

def create_database():
db.create_all()
db.session.commit()

# Find and add all of the ImageStatuses in models.py
statuses = [s for s in dir(models) if s.startswith('IMAGESTATUS_')]
for status in statuses:
id = getattr(models, status)
s = models.ImageStatus(id, status.split('_',1)[1])
db.session.add(s)

# Find and add all of the ImageLevels in models.py
levels = [l for l in dir(models) if l.startswith('IMAGELEVEL_')]
for level in levels:
id = getattr(models, level)
l = models.ImageLevel(id, level.split('_',1)[1])
db.session.add(l)

db.session.commit()


if __name__ == '__main__':
create_data_dirs()

app = create_app()
with app.app_context():
create_database()
16 changes: 10 additions & 6 deletions waznexserver/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-


import os

from flask import current_app as app # is this misleading?
from flask_sqlalchemy import SQLAlchemy
from waznexserver import app
from waznexserver import db
from sqlalchemy.orm import DeclarativeBase


class Base(DeclarativeBase):
pass

db = SQLAlchemy(model_class=Base)

# Image Levels (basic thumbnails, full grid)
IMAGELEVEL_NOTHING = -1
Expand All @@ -22,7 +26,7 @@ def __init__(self, id, desc):
self.desc = desc

def __repr__(self):
return '<id:{} {}>'.format(self.id, self.desc)
return f'<id:{self.id} {self.desc}>'


# Image Statuses
Expand All @@ -40,7 +44,7 @@ def __init__(self, id, desc):
self.desc = desc

def __repr__(self):
return '<id:{} {}>'.format(self.id, self.desc)
return f'<id:{self.id} {self.desc}>'


class GridItem(db.Model):
Expand Down
Loading