comparison service/arduinoNode/pushConfig.py @ 1138:08615804ee0e

twisted pushConfig Ignore-this: b2dc9fbdc8652d4ba7afebf51d2e0319 darcs-hash:6f5c6af01008be44222140bc4dc1b0f004877a12
author drewp <drewp@bigasterisk.com>
date Sat, 03 Mar 2018 16:18:47 -0800
parents
children bb80182195c0
comparison
equal deleted inserted replaced
1137:6ffff91eea2f 1138:08615804ee0e
1 from __future__ import division
2
3 from twisted.internet import reactor
4 from twisted.internet.task import react
5 from twisted.internet.defer import inlineCallbacks, returnValue
6 from twisted.python.filepath import FilePath
7
8 import txaioetcd
9 etcd = txaioetcd.Client(reactor, u'http://bang6:2379')
10
11 @inlineCallbacks
12 def main(*a):
13 prefix = b'arduino/'
14 existing = set(row.key for row in
15 (yield etcd.get(txaioetcd.KeySet(prefix, prefix=True))).kvs)
16 written = set()
17 root = FilePath('config')
18 for f in root.walk():
19 if f.isfile() and f.path.endswith('.n3'):
20 n3 = f.getContent()
21 key = prefix + b'/'.join(f.segmentsFrom(root))
22 yield etcd.set(key, n3)
23 written.add(key)
24 print 'wrote %s' % key
25 for k in existing - written:
26 yield etcd.delete(k)
27 print 'removed %s' % k
28
29 react(main)