refactor application structure

This commit is contained in:
Alexander Minges 2019-02-11 13:37:26 +01:00
parent 8830e17f2f
commit 173f1ca5d1
6 changed files with 25 additions and 10 deletions

View file

@ -3,7 +3,6 @@ from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from phytopi.config import Config
# from phytopi.camera.camera_pi import Camera
app = Flask(__name__, instance_relative_config=True)
@ -11,6 +10,11 @@ app.config.from_object(Config)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
# camera = Camera(app=app)
from phytopi.errors import bp as errors_bp
from phytopi.camera import bp as camera_bp
app.register_blueprint(errors_bp)
app.register_blueprint(camera_bp)
from phytopi import routes, models

View file

@ -0,0 +1,5 @@
from flask import Blueprint
bp = Blueprint('camera', __name__)
from phytopi.camera import camera

View file

@ -8,7 +8,8 @@ import signal
from time import sleep
from enum import Enum
from PIL import Image
from phytopi import db, models, app
from phytopi import db, models
from phytopi.models import CameraSettings
class CameraActionError(Exception):
pass
@ -21,13 +22,12 @@ class CameraStatus(Enum):
SHOT = 4
class CameraWorker(object):
def __init__(self, pidfile='/tmp/raspimjpeg.pid', executable='/usr/local/bin/raspimjpeg', fifo='/dev/shm/mjpeg/FIFO', app=None):
def __init__(self, pidfile='/tmp/raspimjpeg.pid', executable='/usr/local/bin/raspimjpeg', fifo='/dev/shm/mjpeg/FIFO'):
self.pidfile = pidfile
self.executable = executable
self.fifo = fifo
self.proc = None
self.pid = None
self.app = app
self.status = CameraStatus.STOPPED
def start(self):

View file

@ -0,0 +1,5 @@
from flask import Blueprint
bp = Blueprint('errors', __name__)
from phytopi.errors import handlers

View file

View file

@ -1,6 +1,8 @@
from datetime import datetime
from phytopi import db
class Dataset(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
title = db.Column(db.String(64), index=True)
@ -29,17 +31,16 @@ class CameraSettings(db.Model):
fps = db.Column(db.Integer, default=5)
width = db.Column(db.Integer, default=3280)
height = db.Column(db.Integer, default=2464)
fix_shutter = db.Column(db.Boolean, default=False)
fix_wb = db.Column(db.Boolean, default=False)
exposure_mode = db.Column(db.String(64), default='auto')
def __init__(self, name, iso=100, fps=5, width=3280, height=2464, fix_shutter=False, fix_wb=False):
def __init__(self, name, iso=100, fps=5, width=3280, height=2464, exposure_mode='auto'):
self.name = name
self.iso = iso
self.fps = fps
self.width = width
self.height = height
self.fix_shutter = fix_shutter
self.fix_wb = fix_wb
self.exposure_mode = exposure_mode
def __repr__(self):
return '<CameraSettings {}>'.format(self.name)