Mercurial > code > home > repos > homeauto
comparison service/arduinoNode/pushConfig.py @ 334:bb80182195c0
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
Ignore-this: 3155d873bb30ca82b48ace7531a550e5
author | drewp@bigasterisk.com |
---|---|
date | Sat, 03 Mar 2018 17:53:37 -0800 |
parents | 90b469f43944 |
children | 13b2a61650c1 |
comparison
equal
deleted
inserted
replaced
333:90b469f43944 | 334:bb80182195c0 |
---|---|
1 from __future__ import division | 1 from __future__ import division |
2 | 2 |
3 from twisted.internet import reactor | 3 import etcd3 |
4 from twisted.internet.task import react | 4 |
5 from twisted.internet.defer import inlineCallbacks, returnValue | |
6 from twisted.python.filepath import FilePath | 5 from twisted.python.filepath import FilePath |
7 | 6 |
8 import txaioetcd | 7 etcd = etcd3.client(host='bang6') |
9 etcd = txaioetcd.Client(reactor, u'http://bang6:2379') | |
10 | 8 |
11 @inlineCallbacks | 9 def main(): |
12 def main(*a): | |
13 prefix = b'arduino/' | 10 prefix = b'arduino/' |
14 existing = set(row.key for row in | 11 existing = set(md.key for v, md in etcd.get_prefix(prefix)) |
15 (yield etcd.get(txaioetcd.KeySet(prefix, prefix=True))).kvs) | |
16 written = set() | 12 written = set() |
17 root = FilePath('config') | 13 root = FilePath('config') |
18 for f in root.walk(): | 14 for f in root.walk(): |
19 if f.isfile() and f.path.endswith('.n3'): | 15 if f.isfile() and f.path.endswith('.n3'): |
20 n3 = f.getContent() | 16 n3 = f.getContent() |
21 key = prefix + b'/'.join(f.segmentsFrom(root)) | 17 key = prefix + b'/'.join(f.segmentsFrom(root)) |
22 yield etcd.set(key, n3) | 18 etcd.put(key, n3) |
23 written.add(key) | 19 written.add(key) |
24 print 'wrote %s' % key | 20 print 'wrote %s' % key |
25 for k in existing - written: | 21 for k in existing - written: |
26 yield etcd.delete(k) | 22 etcd.delete(k) |
27 print 'removed %s' % k | 23 print 'removed %s' % k |
28 | 24 |
29 react(main) | 25 main() |