Mercurial > templog
comparison web/log.py @ 301:47c259458160
merge
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 06 Jul 2019 19:17:21 +0800 |
parents | f7261dd970da |
children | 87c20b8c5472 |
comparison
equal
deleted
inserted
replaced
300:65a6b56fd18a | 301:47c259458160 |
---|---|
219 def debug_file(mode='r'): | 219 def debug_file(mode='r'): |
220 return open('%s/debug.log' % config.DATA_PATH, mode) | 220 return open('%s/debug.log' % config.DATA_PATH, mode) |
221 | 221 |
222 def record_debug(params): | 222 def record_debug(params): |
223 f = debug_file('a+') | 223 f = debug_file('a+') |
224 f.write('===== %s =====\n' % time.strftime('%a, %d %b %Y %H:%M:%S')) | 224 f.write('===== start %s =====\n' % time.strftime('%a, %d %b %Y %H:%M:%S')) |
225 json.dump(params, f, sort_keys=True, indent=4) | 225 json.dump(params, f, sort_keys=True, indent=4) |
226 f.write('===== end %s =====\n' % time.strftime('%a, %d %b %Y %H:%M:%S')) | |
226 f.flush() | 227 f.flush() |
227 return f | 228 return f |
228 | 229 |
229 def tail_debug_log(): | 230 def tail_debug_log(): |
230 f = debug_file() | 231 f = debug_file() |
295 'disabled': False, | 296 'disabled': False, |
296 'nowort': True, | 297 'nowort': True, |
297 'fridge_range_lower': 3, | 298 'fridge_range_lower': 3, |
298 'fridge_range_upper': 3, | 299 'fridge_range_upper': 3, |
299 } | 300 } |
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 | |
300 | 308 |
301 def get_params(): | 309 def get_params(): |
302 """ Can return None if there aren't any parameters yet, | 310 """ Can return None if there aren't any parameters yet, |
303 otherwise returns the parameter list """ | 311 otherwise returns the parameter list """ |
304 | 312 |
326 n['title'] = k | 334 n['title'] = k |
327 r.append(n) | 335 r.append(n) |
328 | 336 |
329 return json.dumps(r, sort_keys=True, indent=4) | 337 return json.dumps(r, sort_keys=True, indent=4) |
330 | 338 |
331 def send_params(params): | |
332 # 'templog_receive' is ignored due to authorized_keys | |
333 # restrictions. the rpi has authorized_keys with | |
334 # 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.... | |
335 args = [config.SSH_PROG, '-i', config.SSH_KEYFILE, | |
336 config.SSH_HOST, 'templog_receive'] | |
337 try: | |
338 p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE) | |
339 (out, err) = p.communicate(json.dumps(params)) | |
340 except OSError, e: | |
341 print>>sys.stderr, e | |
342 return "Failed update" | |
343 | |
344 if 'Good Update' in out: | |
345 return True | |
346 | |
347 print>>sys.stderr, "Strange return from update:" | |
348 print>>sys.stderr, out | |
349 return "Unexpected update result" | |
350 | |
351 def same_type(a, b): | 339 def same_type(a, b): |
352 ta = type(a) | 340 ta = type(a) |
353 tb = type(b) | 341 tb = type(b) |
354 | 342 |
355 if ta == int: | 343 if ta == int: |