diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/service/arduinoNode/pushConfig.py	Sat Mar 03 16:18:47 2018 -0800
@@ -0,0 +1,29 @@
+from __future__ import division
+
+from twisted.internet import reactor
+from twisted.internet.task import react
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.python.filepath import FilePath
+
+import txaioetcd
+etcd = txaioetcd.Client(reactor, u'http://bang6:2379')
+
+@inlineCallbacks
+def main(*a):
+    prefix = b'arduino/'
+    existing = set(row.key for row in
+                   (yield etcd.get(txaioetcd.KeySet(prefix, prefix=True))).kvs)
+    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)
+            written.add(key)
+            print 'wrote %s' % key
+    for k in existing - written:
+        yield etcd.delete(k)
+        print 'removed %s' % k
+
+react(main)