Browse Source

get basic functionality working..

main
John-Mark Gurney 5 years ago
parent
commit
3a6f9c2dae
3 changed files with 18 additions and 10 deletions
  1. +4
    -0
      Makefile
  2. +6
    -1
      root/js/solardash.https.jspp
  3. +8
    -9
      solardash/__init__.py

+ 4
- 0
Makefile View File

@@ -26,6 +26,7 @@ root/js/solardash.file.js: root/js/solardash.base.js
root/js/solardash.https.js: root/js/solardash.base.js

all: $(JSFILES)
run: $(JSFILES)

.jspp.js:
cpp -Wno-invalid-pp-token -E $< | sed -e '/^#/d' > $@ || (rm "$@"; false)
@@ -39,5 +40,8 @@ test:
test-noentr:
python -m coverage run -m unittest $(PROJNAME) && coverage report --omit=p/\* -m -i

run: $(JSFILES)
python -m aiohttp.web -H localhost -P 38382 solardash:getapp p/src/raineagle/fixtures/data

env:
($(VIRTUALENV) $(VIRTUALENVARGS) p && . ./p/bin/activate && pip install -r requirements.txt)

+ 6
- 1
root/js/solardash.https.jspp View File

@@ -1,3 +1,8 @@
var socket = new WebSocket('wss://' + location.host + '/solar.ws');
// Make sure you're editing the jspp file
var wsproto = 'wss:';
if (document.location.protocol == 'http:')
wsproto = 'ws:';

var socket = new WebSocket(wsproto + '//' + location.host + '/solar.ws');

#include "solardash.base.js"

+ 8
- 9
solardash/__init__.py View File

@@ -71,13 +71,11 @@ class SolarDataWS(object):

def get_routes(self):
return [
web.get('/ws', self.websocket_handler),
web.get('/solar.ws', self.websocket_handler),
]

# XXX - how to configure this properly
sdws = SolarDataWS('./raineagle.')

def getapp(sdws):
def getapp(argv):
sdws = SolarDataWS(argv[0])
app = web.Application()
app.add_routes(sdws.get_routes())
p = os.path.join(os.path.dirname(__file__), '..', 'root')
@@ -91,7 +89,9 @@ def getapp(sdws):

return app

app = getapp(sdws)
def main():
app = getapp(sys.argv[1:])
web.run_app(app)

# https://stackoverflow.com/questions/23033939/how-to-test-python-3-4-asyncio-code
# Slightly modified to timeout and to print trace back when canceled.
@@ -124,9 +124,8 @@ class Test(unittest.TestCase):

self.rootdir = os.path.join(os.path.dirname(__file__), '..', 'root')
os.chdir(self.tempdir)
sdws = SolarDataWS(os.path.join(self.tempdir, 'raineagle'))

app = getapp(sdws)
app = getapp([ os.path.join(self.tempdir, 'raineagle') ])
self._app = app

# launch the server
@@ -173,7 +172,7 @@ class Test(unittest.TestCase):
r = []
try:
async with aiohttp.ClientSession() as session, \
session.ws_connect(self.makeurl('ws')) as ws:
session.ws_connect(self.makeurl('solar.ws')) as ws:
async for msg in ws:
r.append(msg)
if len(r) == 2:


Loading…
Cancel
Save