pep8 cleanup
This commit is contained in:
parent
f739cc05d4
commit
03056cd397
@ -1,7 +1,9 @@
|
||||
import datetime
|
||||
import json
|
||||
|
||||
from repeated_timer import RepeatedTimer
|
||||
|
||||
|
||||
class DashieSampler:
|
||||
def __init__(self, app, interval):
|
||||
self._app = app
|
||||
|
@ -1,10 +1,18 @@
|
||||
from example_samplers import *
|
||||
from example_samplers import (
|
||||
SynergySampler,
|
||||
HotnessSampler,
|
||||
BuzzwordsSampler,
|
||||
ConvergenceSampler,
|
||||
ProgressBarsSampler,
|
||||
UsageGaugeSampler,
|
||||
)
|
||||
|
||||
|
||||
def run(app, xyzzy):
|
||||
samplers = [
|
||||
SynergySampler(xyzzy, 3),
|
||||
HotnessSampler(xyzzy, 3),
|
||||
BuzzwordsSampler(xyzzy, 2), # 10
|
||||
BuzzwordsSampler(xyzzy, 2), # 10
|
||||
ConvergenceSampler(xyzzy, 1),
|
||||
ProgressBarsSampler(xyzzy, 5),
|
||||
UsageGaugeSampler(xyzzy, 3),
|
||||
@ -21,7 +29,7 @@ def run(app, xyzzy):
|
||||
finally:
|
||||
print "Disconnecting clients"
|
||||
xyzzy.stopped = True
|
||||
|
||||
|
||||
print "Stopping %d timers" % len(samplers)
|
||||
for (i, sampler) in enumerate(samplers):
|
||||
sampler.stop()
|
||||
|
@ -1,7 +1,8 @@
|
||||
import collections
|
||||
import random
|
||||
|
||||
from dashie_sampler import DashieSampler
|
||||
|
||||
import random
|
||||
import collections
|
||||
|
||||
class SynergySampler(DashieSampler):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -18,6 +19,7 @@ class SynergySampler(DashieSampler):
|
||||
self._last = s['current']
|
||||
return s
|
||||
|
||||
|
||||
class HotnessSampler(DashieSampler):
|
||||
def __init__(self, *args, **kwargs):
|
||||
DashieSampler.__init__(self, *args, **kwargs)
|
||||
@ -33,6 +35,7 @@ class HotnessSampler(DashieSampler):
|
||||
self._last = s['current']
|
||||
return s
|
||||
|
||||
|
||||
class BuzzwordsSampler(DashieSampler):
|
||||
def name(self):
|
||||
return 'buzzwords'
|
||||
@ -47,7 +50,8 @@ class BuzzwordsSampler(DashieSampler):
|
||||
'Skydancer']
|
||||
items = [{'label': pony_name, 'value': random.randint(0, 20)} for pony_name in my_little_pony_names]
|
||||
random.shuffle(items)
|
||||
return {'items':items}
|
||||
return {'items': items}
|
||||
|
||||
|
||||
class ConvergenceSampler(DashieSampler):
|
||||
def name(self):
|
||||
@ -60,26 +64,27 @@ class ConvergenceSampler(DashieSampler):
|
||||
|
||||
def sample(self):
|
||||
self.items.append({'x': self.seedX,
|
||||
'y': random.randint(0,20)})
|
||||
'y': random.randint(0, 20)})
|
||||
self.seedX += 1
|
||||
if len(self.items) > 10:
|
||||
self.items.popleft()
|
||||
|
||||
return {'points': list(self.items)}
|
||||
|
||||
|
||||
class ProgressBarsSampler(DashieSampler):
|
||||
def __init__(self, *args, **kwargs):
|
||||
DashieSampler.__init__(self, *args, **kwargs)
|
||||
|
||||
|
||||
def name(self):
|
||||
return 'progress_bars'
|
||||
|
||||
def sample(self):
|
||||
random_progress = []
|
||||
|
||||
|
||||
for i in range(5):
|
||||
random_progress.append({'name': "Project %d" % i, 'progress': random.randint(0, 100)})
|
||||
|
||||
|
||||
return {'title': "Progress Bars Title", 'progress_items': random_progress}
|
||||
|
||||
|
||||
|
@ -1,6 +1,15 @@
|
||||
import os
|
||||
import logging
|
||||
from flask import Flask, render_template, Response, send_from_directory, request, current_app
|
||||
import os
|
||||
import Queue
|
||||
|
||||
from flask import (
|
||||
current_app,
|
||||
Flask,
|
||||
render_template,
|
||||
Response,
|
||||
send_from_directory,
|
||||
request,
|
||||
)
|
||||
|
||||
app = Flask(__name__)
|
||||
logging.basicConfig()
|
||||
@ -10,10 +19,12 @@ log = logging.getLogger(__name__)
|
||||
@app.route("/")
|
||||
def main():
|
||||
return render_template('main.html', title='pyDashie')
|
||||
|
||||
|
||||
|
||||
@app.route("/dashboard/<dashlayout>/")
|
||||
def custom_layout(dashlayout):
|
||||
return render_template('%s.html'%dashlayout, title='pyDashie')
|
||||
return render_template('{}.html'.format(dashlayout), title='pyDashie')
|
||||
|
||||
|
||||
@app.route("/assets/application.js")
|
||||
def javascripts():
|
||||
@ -30,14 +41,14 @@ def javascripts():
|
||||
'assets/javascripts/jquery.gridster.js',
|
||||
'assets/javascripts/jquery.leanModal.min.js',
|
||||
|
||||
#'assets/javascripts/dashing.coffee',
|
||||
# 'assets/javascripts/dashing.coffee',
|
||||
'assets/javascripts/dashing.gridster.coffee',
|
||||
|
||||
'assets/javascripts/jquery.knob.js',
|
||||
'assets/javascripts/rickshaw.min.js',
|
||||
#'assets/javascripts/application.coffee',
|
||||
# 'assets/javascripts/application.coffee',
|
||||
'assets/javascripts/app.js',
|
||||
#'widgets/clock/clock.coffee',
|
||||
# 'widgets/clock/clock.coffee',
|
||||
'widgets/number/number.coffee',
|
||||
'widgets/hotness/hotness.coffee',
|
||||
'widgets/progress_bars/progress_bars.coffee',
|
||||
@ -49,7 +60,7 @@ def javascripts():
|
||||
|
||||
output = []
|
||||
for path in scripts:
|
||||
path = '{1}/{0}'.format(path,os.path.dirname(os.path.realpath(__file__)))
|
||||
path = '{1}/{0}'.format(path, os.path.dirname(os.path.realpath(__file__)))
|
||||
output.append('// JS: %s\n' % path)
|
||||
if '.coffee' in path:
|
||||
log.info('Compiling Coffee for %s ' % path)
|
||||
@ -73,10 +84,10 @@ def javascripts():
|
||||
current_app.javascripts = output
|
||||
else:
|
||||
current_app.javascripts = ''.join(output)
|
||||
|
||||
|
||||
return Response(current_app.javascripts, mimetype='application/javascript')
|
||||
|
||||
|
||||
@app.route('/assets/application.css')
|
||||
def application_css():
|
||||
scripts = [
|
||||
@ -84,29 +95,32 @@ def application_css():
|
||||
]
|
||||
output = ''
|
||||
for path in scripts:
|
||||
path = '{1}/{0}'.format(path,os.path.dirname(os.path.realpath(__file__)))
|
||||
path = '{1}/{0}'.format(path, os.path.dirname(os.path.realpath(__file__)))
|
||||
output = output + open(path).read()
|
||||
return Response(output, mimetype='text/css')
|
||||
|
||||
|
||||
@app.route('/assets/images/<path:filename>')
|
||||
def send_static_img(filename):
|
||||
directory = os.path.join('assets', 'images')
|
||||
return send_from_directory(directory, filename)
|
||||
|
||||
|
||||
@app.route('/views/<widget_name>.html')
|
||||
def widget_html(widget_name):
|
||||
html = '%s.html' % widget_name
|
||||
path = os.path.join(os.path.dirname(os.path.realpath(__file__)),'widgets', widget_name, html)
|
||||
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'widgets', widget_name, html)
|
||||
if os.path.isfile(path):
|
||||
f = open(path)
|
||||
contents = f.read()
|
||||
f.close()
|
||||
return contents
|
||||
|
||||
import Queue
|
||||
|
||||
class Z:
|
||||
pass
|
||||
|
||||
|
||||
xyzzy = Z()
|
||||
xyzzy.events_queue = {}
|
||||
xyzzy.last_events = {}
|
||||
@ -114,6 +128,7 @@ xyzzy.using_events = True
|
||||
xyzzy.MAX_QUEUE_LENGTH = 20
|
||||
xyzzy.stopped = False
|
||||
|
||||
|
||||
@app.route('/events')
|
||||
def events():
|
||||
if xyzzy.using_events:
|
||||
@ -123,29 +138,34 @@ def events():
|
||||
current_app.logger.info('New Client %s connected. Total Clients: %s' %
|
||||
(event_stream_port, len(xyzzy.events_queue)))
|
||||
|
||||
#Start the newly connected client off by pushing the current last events
|
||||
# Start the newly connected client off by pushing the current last events
|
||||
for event in xyzzy.last_events.values():
|
||||
current_event_queue.put(event)
|
||||
return Response(pop_queue(current_event_queue), mimetype='text/event-stream')
|
||||
|
||||
return Response(xyzzy.last_events.values(), mimetype='text/event-stream')
|
||||
|
||||
|
||||
def pop_queue(current_event_queue):
|
||||
while not xyzzy.stopped:
|
||||
try:
|
||||
data = current_event_queue.get(timeout=0.1)
|
||||
yield data
|
||||
except Queue.Empty:
|
||||
#this makes the server quit nicely - previously the queue threads would block and never exit. This makes it keep checking for dead application
|
||||
# this makes the server quit nicely - previously the queue
|
||||
# threads would block and never exit. This makes it keep
|
||||
# checking for dead application
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def purge_streams():
|
||||
big_queues = [port for port, queue in xyzzy.events_queue if len(queue) > xyzzy.MAX_QUEUE_LENGTH]
|
||||
for big_queue in big_queues:
|
||||
current_app.logger.info('Client %s is stale. Disconnecting. Total Clients: %s' %
|
||||
(big_queue, len(xyzzy.events_queue)))
|
||||
del queue[big_queue]
|
||||
|
||||
|
||||
|
||||
def close_stream(*args, **kwargs):
|
||||
event_stream_port = args[2][1]
|
||||
del xyzzy.events_queue[event_stream_port]
|
||||
|
@ -1,12 +1,14 @@
|
||||
from threading import Timer
|
||||
|
||||
|
||||
class RepeatedTimer(object):
|
||||
|
||||
def __init__(self, interval, function, *args, **kwargs):
|
||||
self._timer = None
|
||||
self.interval = interval
|
||||
self.function = function
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
self._timer = None
|
||||
self.interval = interval
|
||||
self.function = function
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
self.is_running = False
|
||||
self.start()
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import trello
|
||||
|
||||
from pydashie.dashie_sampler import DashieSampler
|
||||
|
||||
import random
|
||||
import trello
|
||||
|
||||
class TrelloSampler(DashieSampler):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -9,7 +9,7 @@ class TrelloSampler(DashieSampler):
|
||||
self._last = 0
|
||||
self.key = '0667001bfafc26b53864fd08124159f0'
|
||||
self.secret = 'cb6a56444019998b879015c53a17f695700e6dd2f6f147870f27aff89e156c2b'
|
||||
self.token= 'b4c5cdbfcda87de13c3a8b487d4c24b0ad9536672e24675d50aa1e08d9d89c67'
|
||||
self.token = 'b4c5cdbfcda87de13c3a8b487d4c24b0ad9536672e24675d50aa1e08d9d89c67'
|
||||
self.api = trello.TrelloApi
|
||||
|
||||
def name(self):
|
||||
@ -20,4 +20,4 @@ class TrelloSampler(DashieSampler):
|
||||
'current': 2,
|
||||
'last': self._last}
|
||||
self._last = s['current']
|
||||
return s
|
||||
return s
|
||||
|
@ -1,6 +1,7 @@
|
||||
import requests
|
||||
|
||||
from pydashie.dashie_sampler import DashieSampler
|
||||
|
||||
import requests
|
||||
|
||||
class WebsiteUpSampler(DashieSampler):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -15,8 +16,8 @@ class WebsiteUpSampler(DashieSampler):
|
||||
try:
|
||||
r = requests.get(self.page)
|
||||
assert r.status_code == 200
|
||||
up='UP'
|
||||
up = 'UP'
|
||||
except:
|
||||
up='DOWN'
|
||||
s = {'text':up}
|
||||
return s
|
||||
up = 'DOWN'
|
||||
|
||||
return {'text': up}
|
||||
|
Loading…
x
Reference in New Issue
Block a user