|
|
|
@ -1,18 +1,17 @@
|
|
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
|
import json
|
|
|
|
|
import logging
|
|
|
|
|
import signal
|
|
|
|
|
|
|
|
|
|
import gevent
|
|
|
|
|
import gevent.backdoor
|
|
|
|
|
from gevent.pywsgi import WSGIServer
|
|
|
|
|
import flask
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import common
|
|
|
|
|
from common import database
|
|
|
|
|
#from stats import stats, after_request
|
|
|
|
|
|
|
|
|
|
app = flask.Flask('thrimshim')
|
|
|
|
|
#app.after_request(after_request)
|
|
|
|
|
|
|
|
|
|
def cors(app):
|
|
|
|
|
"""WSGI middleware that sets CORS headers"""
|
|
|
|
@ -30,22 +29,19 @@ def cors(app):
|
|
|
|
|
return app(environ, _start_response)
|
|
|
|
|
return handle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/thrimshim/<uuid:key>', methods=['GET', 'POST'])
|
|
|
|
|
def thrimshim(key):
|
|
|
|
|
if flask.request.method == 'POST':
|
|
|
|
|
row = flask.request.json
|
|
|
|
|
update_row(row)
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
get_row(key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def date_handler(obj):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_row(ident):
|
|
|
|
|
conn = flask.g.db_manager.get_conn()
|
|
|
|
|
conn = app.db_manager.get_conn()
|
|
|
|
|
with database.transaction(conn):
|
|
|
|
|
result = database.query(conn, 'SELECT * FROM events WHERE id = %s;', ident
|
|
|
|
|
results = database.query(conn, 'SELECT * FROM events WHERE id = %s;', ident)
|
|
|
|
|
row = results[0]
|
|
|
|
|
assert row.id == ident
|
|
|
|
|
response = row._asdict()
|
|
|
|
@ -53,53 +49,50 @@ def get_row(ident):
|
|
|
|
|
return json.dump(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_row(ident):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def query_database(ident):
|
|
|
|
|
|
|
|
|
|
select start, end, catagory, description, notes, video_title, video_description, video_start, video_end, state, error
|
|
|
|
|
from database where id is ident
|
|
|
|
|
|
|
|
|
|
def set_row(data):
|
|
|
|
|
to_update = unjson(data)
|
|
|
|
|
|
|
|
|
|
update_database(to_update)
|
|
|
|
|
|
|
|
|
|
def update_database(ident, to_update):
|
|
|
|
|
|
|
|
|
|
if state not in ['UNEDITED, EDITED, CLAIMED']:
|
|
|
|
|
return 'Video already published'
|
|
|
|
|
|
|
|
|
|
insert video_title, video_description, video_start, video_end
|
|
|
|
|
#allow_holes, uploader_whitelist, upload_location
|
|
|
|
|
into database where id == indent
|
|
|
|
|
|
|
|
|
|
set error to NULL
|
|
|
|
|
set uploader to NULL
|
|
|
|
|
|
|
|
|
|
if upload_location:
|
|
|
|
|
set state to 'DONE'
|
|
|
|
|
|
|
|
|
|
if publish:
|
|
|
|
|
set state to 'EDITED'
|
|
|
|
|
else:
|
|
|
|
|
set state to 'UNEDITED'
|
|
|
|
|
#def query_database(ident):
|
|
|
|
|
#
|
|
|
|
|
# select start, end, catagory, description, notes, video_title, video_description, video_start, video_end, state, error
|
|
|
|
|
# from database where id is ident
|
|
|
|
|
#
|
|
|
|
|
#def set_row(data):
|
|
|
|
|
# to_update = unjson(data)
|
|
|
|
|
#
|
|
|
|
|
# update_database(to_update)
|
|
|
|
|
#
|
|
|
|
|
#def update_database(ident, to_update):
|
|
|
|
|
#
|
|
|
|
|
# if state not in ['UNEDITED, EDITED, CLAIMED']:
|
|
|
|
|
# return 'Video already published'
|
|
|
|
|
#
|
|
|
|
|
# insert video_title, video_description, video_start, video_end
|
|
|
|
|
# #allow_holes, uploader_whitelist, upload_location
|
|
|
|
|
# into database where id == indent
|
|
|
|
|
#
|
|
|
|
|
# set error to NULL
|
|
|
|
|
# set uploader to NULL
|
|
|
|
|
#
|
|
|
|
|
# if upload_location:
|
|
|
|
|
# set state to 'DONE'
|
|
|
|
|
#
|
|
|
|
|
# if publish:
|
|
|
|
|
# set state to 'EDITED'
|
|
|
|
|
# else:
|
|
|
|
|
# set state to 'UNEDITED'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(host='0.0.0.0', port=8005, connection_string='', backdoor_port=False):
|
|
|
|
|
def main(host='0.0.0.0', port=8005, connection_string='', backdoor_port=0):
|
|
|
|
|
|
|
|
|
|
flask.g.db_manager = database.DBManager(dsn=connection_string)
|
|
|
|
|
server = WSGIServer((host, port), cors(app))
|
|
|
|
|
app.db_manager = database.DBManager(dsn=connection_string)
|
|
|
|
|
|
|
|
|
|
def stop():
|
|
|
|
|
logging.info("Shutting down")
|
|
|
|
|
server.stop()
|
|
|
|
|
gevent.signal(signal.SIGTERM, stop)
|
|
|
|
|
|
|
|
|
|
PromLogCountsHandler.install()
|
|
|
|
|
install_stacksampler()
|
|
|
|
|
common.PromLogCountsHandler.install()
|
|
|
|
|
common.install_stacksampler()
|
|
|
|
|
|
|
|
|
|
if backdoor_port:
|
|
|
|
|
gevent.backdoor.BackdoorServer(('127.0.0.1', backdoor_port), locals=locals()).start()
|
|
|
|
|