Mercurial > templog
comparison web/log.py @ 291:f7261dd970da
- replace ssl client certs with cookies
- remove unused ssh code
- add /set?fake=1 test mode
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 06 Jul 2019 16:32:16 +0800 |
parents | 95f704ce809d |
children | 87c20b8c5472 |
comparison
equal
deleted
inserted
replaced
290:35ae717d48f0 | 291:f7261dd970da |
---|---|
297 'nowort': True, | 297 'nowort': True, |
298 'fridge_range_lower': 3, | 298 'fridge_range_lower': 3, |
299 'fridge_range_upper': 3, | 299 'fridge_range_upper': 3, |
300 } | 300 } |
301 | 301 |
302 def fake_params(): | |
303 """ for quicker testing """ | |
304 r = [] | |
305 r.append({'name': 'going', 'value': 'true', 'kind': 'yesno', 'title': 'going'}) | |
306 r.append({'name': 'temperature', 'value': 12.5, 'kind': 'number', 'title': 'temperature', 'digits': 1, 'amount': 0.1, 'unit': '°'}) | |
307 return r | |
308 | |
302 def get_params(): | 309 def get_params(): |
303 """ Can return None if there aren't any parameters yet, | 310 """ Can return None if there aren't any parameters yet, |
304 otherwise returns the parameter list """ | 311 otherwise returns the parameter list """ |
305 | 312 |
306 r = [] | 313 r = [] |
327 n['title'] = k | 334 n['title'] = k |
328 r.append(n) | 335 r.append(n) |
329 | 336 |
330 return json.dumps(r, sort_keys=True, indent=4) | 337 return json.dumps(r, sort_keys=True, indent=4) |
331 | 338 |
332 def send_params(params): | |
333 # 'templog_receive' is ignored due to authorized_keys | |
334 # restrictions. the rpi has authorized_keys with | |
335 # command="/home/matt/templog/venv/bin/python /home/matt/templog/py/receive.py",no-pty,no-port-forwarding,no-x11-forwarding,no-agent-forwarding ssh-rsa AAAAB3NzaC.... | |
336 args = [config.SSH_PROG, '-i', config.SSH_KEYFILE, | |
337 config.SSH_HOST, 'templog_receive'] | |
338 try: | |
339 p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE) | |
340 (out, err) = p.communicate(json.dumps(params)) | |
341 except OSError, e: | |
342 print>>sys.stderr, e | |
343 return "Failed update" | |
344 | |
345 if 'Good Update' in out: | |
346 return True | |
347 | |
348 print>>sys.stderr, "Strange return from update:" | |
349 print>>sys.stderr, out | |
350 return "Unexpected update result" | |
351 | |
352 def same_type(a, b): | 339 def same_type(a, b): |
353 ta = type(a) | 340 ta = type(a) |
354 tb = type(b) | 341 tb = type(b) |
355 | 342 |
356 if ta == int: | 343 if ta == int: |