4 Commits

Author SHA1 Message Date
Patrick McDonagh
cf49309391 Moves files around 2016-12-06 17:13:15 -06:00
Patrick McDonagh
b0b964c45a also install hp_webserver.datalogger 2016-12-06 16:39:33 -06:00
Patrick McDonagh
5de541fc59 fix package importing for __init__.py 2016-12-06 16:33:56 -06:00
Patrick McDonagh
43f9ed378b changes app folder to hp_webserver to match package name 2016-12-06 16:26:44 -06:00
100 changed files with 49 additions and 47 deletions

1
.gitignore vendored
View File

@@ -5,3 +5,4 @@ sails/.tmp
.remote-sync.json .remote-sync.json
database.db database.db
venv/ venv/
Henry_Pump_WebServer.egg-info/

View File

@@ -1,4 +1,5 @@
# app/__init__.py # app/__init__.py
import os import os
from flask import Flask from flask import Flask
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
@@ -8,17 +9,17 @@ from flask_sqlalchemy import SQLAlchemy
UPLOAD_FOLDER = os.path.join(os.getcwd(), 'app', 'docs') UPLOAD_FOLDER = os.path.join(os.getcwd(), 'app', 'docs')
app = Flask('app', static_url_path='') app = Flask('app', static_url_path='', static_folder="hp_webserver/static")
app.config.update( app.config.update(
DEBUG=True, DEBUG=True,
# SQLALCHEMY_DATABASE_URI='mysql+mysqlconnector://website:henrypump@127.0.0.1/poconsole' # SQLALCHEMY_DATABASE_URI='mysql+mysqlconnector://website:henrypump@127.0.0.1/poconsole'
SQLALCHEMY_DATABASE_URI='sqlite:///../database.db', SQLALCHEMY_DATABASE_URI='sqlite:///./database.db',
) )
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
app.secret_key = 'henry_pump' app.secret_key = 'henry_pump'
db = SQLAlchemy(app) db = SQLAlchemy(app)
from datalogger import views from hp_webserver.datalogger import views
from datalogger import api from hp_webserver.datalogger import api
from datalogger.models import * from hp_webserver.datalogger.models import *

1
hp_webserver/__main__.py Normal file
View File

@@ -0,0 +1 @@
print("MAIN IN hp_datalogger")

View File

@@ -0,0 +1 @@
print("THIS IS THE MAIN FROM datalogger")

View File

@@ -2,8 +2,8 @@ from pycomm.ab_comm.clx import Driver as ClxDriver
import traceback import traceback
import math import math
from app.datalogger.models import Device from hp_webserver.datalogger.models import Device
from app import db from hp_webserver import db
def getMainPLC(): def getMainPLC():

View File

@@ -7,9 +7,9 @@ from sqlalchemy import and_, desc
from sqlalchemy.sql import func from sqlalchemy.sql import func
from datetime import datetime from datetime import datetime
from app import app, db from hp_webserver import app, db
from app.datalogger.models import * from hp_webserver.datalogger.models import *
from app.datalogger.getDailyTotals import getTotals from hp_webserver.datalogger.getDailyTotals import getTotals
from pycomm_helper.utils import readTag, writeTag from pycomm_helper.utils import readTag, writeTag
from random import random from random import random
@@ -52,6 +52,7 @@ def tagsattime_to_obj(tup):
@app.route('/', defaults={'path': ''}) @app.route('/', defaults={'path': ''})
@app.route('/<path:path>') @app.route('/<path:path>')
def catch_all(path): def catch_all(path):
print("caught something!")
return app.send_static_file('index.html') return app.send_static_file('index.html')

View File

Before

Width:  |  Height:  |  Size: 357 KiB

After

Width:  |  Height:  |  Size: 357 KiB

View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View File

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

View File

Before

Width:  |  Height:  |  Size: 130 KiB

After

Width:  |  Height:  |  Size: 130 KiB

8
run.py
View File

@@ -1,8 +1,8 @@
from app import app from hp_webserver import app
import ssl import ssl
# context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLSv1_2) def run_app():
# context.load_cert_chain('/Users/patrickjmcd/Henry_Pump/tagserver/web_db/flask/app/hplumberjack.crt', '/Users/patrickjmcd/Henry_Pump/tagserver/web_db/flask/app/hplumberjack.key') app.run(host="0.0.0.0", debug=True, ssl_context='adhoc')
if __name__ == '__main__': if __name__ == '__main__':
app.run(host="0.0.0.0", debug=True, ssl_context='adhoc') run_app()

18
setup.py Normal file
View File

@@ -0,0 +1,18 @@
from setuptools import setup
setup(
name='Henry Pump WebServer',
version='2.0',
long_description=__doc__,
packages=['hp_webserver', 'hp_webserver.datalogger'],
include_package_data=True,
zip_safe=False,
install_requires=[
'Flask>=0.11.1',
'Flask-Restless>=0.17.0',
'Flask-SQLAlchemy>=2.1',
'pyOpenSSL>=16.2.0',
'requests>=2.12.1',
'Twisted>=16.6.0',
]
)

View File

@@ -1,18 +1,20 @@
import sys import sys
# the sqlalchemy db object # the sqlalchemy db object
from app import db from hp_webserver import db
# we have to import the models so that sqlalchemy can detect them and create the db # we have to import the models so that sqlalchemy can detect them and create the db
# how else would it know what to create ? # how else would it know what to create ?
from app.datalogger.models import * from hp_webserver.datalogger.models import *
def main(): def setupdb(seed=False):
# creates the database # creates the database
db.create_all() db.create_all()
# after the last command you should now be able to see database.db file # after the last command you should now be able to see database.db file
# in the project folder # in the project folder
if seed:
seed()
def seed(): def seed():
@@ -138,11 +140,15 @@ def seed():
db.session.commit() db.session.commit()
if __name__ == '__main__': if __name__ == '__main__':
main()
try: try:
if sys.argv[1] == "seed": if sys.argv[1] == "seed":
seed() setupdb(seed=True)
print("Created database.db file and seeded data.") print("Created database.db file and seeded data.")
else:
setupdb()
except Exception as e: except Exception as e:
setupdb()
print("Created database.db file. To seed data, run 'python setupdb.py seed'") print("Created database.db file. To seed data, run 'python setupdb.py seed'")

View File

@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
OLDDIR=$PWD OLDDIR=$PWD
cd /root/www cd /root/www
twistd --pidfile=/root/webserver.pid web --https=5000 --wsgi app.app -c /root/ssl/poconsole.crt -k /root/ssl/poconsole.key twistd --pidfile=/root/webserver.pid web --https=5000 --wsgi hp_webserver.app -c /root/ssl/poconsole.crt -k /root/ssl/poconsole.key
cd $OLDDIR cd $OLDDIR

View File

@@ -1,27 +0,0 @@
import sys
# the sqlalchemy db object
from app import db
# we have to import the models so that sqlalchemy can detect them and create the db
# how else would it know what to create ?
from app.datalogger.models import *
num_tapers = BackupRestore(tag="Card_Current.Params.Num_Tapers", device_id=1)
taper_length = [BackupRestore(tag="Taper.Taper[{}].Setup.Length".format(i), device_id=1) for i in range(1, 10)]
taper_diameter = [BackupRestore(tag="Taper.Taper[{}].Setup.Diameter".format(i), device_id=1) for i in range(1, 10)]
taper_material = [BackupRestore(tag="Taper.Taper[{}].Setup.Material".format(i), device_id=1) for i in range(1, 10)]
pump_diameter = BackupRestore(tag='UnitConfig.Pump_Diameter', device_id=1)
db.session.add(num_tapers)
for i in range(0, len(taper_length)):
db.session.add(taper_length[i])
for i in range(0, len(taper_diameter)):
db.session.add(taper_diameter[i])
for i in range(0, len(taper_material)):
db.session.add(taper_material[i])
db.session.add(pump_diameter)
db.session.commit()