Mercurial > code > home > repos > homeauto
diff service/arduinoNode/pushConfig.py @ 1139:db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
Ignore-this: 3155d873bb30ca82b48ace7531a550e5
darcs-hash:0b2be13fbb4dc2571bb1bb8ac97f6a1350f36e77
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Sat, 03 Mar 2018 17:53:37 -0800 |
parents | 08615804ee0e |
children | 13b2a61650c1 |
line wrap: on
line diff
--- a/service/arduinoNode/pushConfig.py Sat Mar 03 16:18:47 2018 -0800 +++ b/service/arduinoNode/pushConfig.py Sat Mar 03 17:53:37 2018 -0800 @@ -1,29 +1,25 @@ from __future__ import division -from twisted.internet import reactor -from twisted.internet.task import react -from twisted.internet.defer import inlineCallbacks, returnValue +import etcd3 + from twisted.python.filepath import FilePath -import txaioetcd -etcd = txaioetcd.Client(reactor, u'http://bang6:2379') +etcd = etcd3.client(host='bang6') -@inlineCallbacks -def main(*a): +def main(): prefix = b'arduino/' - existing = set(row.key for row in - (yield etcd.get(txaioetcd.KeySet(prefix, prefix=True))).kvs) + existing = set(md.key for v, md in etcd.get_prefix(prefix)) written = set() root = FilePath('config') for f in root.walk(): if f.isfile() and f.path.endswith('.n3'): n3 = f.getContent() key = prefix + b'/'.join(f.segmentsFrom(root)) - yield etcd.set(key, n3) + etcd.put(key, n3) written.add(key) print 'wrote %s' % key for k in existing - written: - yield etcd.delete(k) + etcd.delete(k) print 'removed %s' % k -react(main) +main()