Mercurial > code > home > repos > homeauto
annotate service/arduinoNode/pushConfig.py @ 336:5a0dd334023e
docker and makefile for arduinoNode
Ignore-this: bdff7ca263b699f7829da324807a557
author | drewp@bigasterisk.com |
---|---|
date | Sat, 03 Mar 2018 18:01:02 -0800 |
parents | bb80182195c0 |
children | 13b2a61650c1 |
rev | line source |
---|---|
333 | 1 from __future__ import division |
2 | |
334
bb80182195c0
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents:
333
diff
changeset
|
3 import etcd3 |
bb80182195c0
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents:
333
diff
changeset
|
4 |
333 | 5 from twisted.python.filepath import FilePath |
6 | |
334
bb80182195c0
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents:
333
diff
changeset
|
7 etcd = etcd3.client(host='bang6') |
333 | 8 |
334
bb80182195c0
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents:
333
diff
changeset
|
9 def main(): |
333 | 10 prefix = b'arduino/' |
334
bb80182195c0
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents:
333
diff
changeset
|
11 existing = set(md.key for v, md in etcd.get_prefix(prefix)) |
333 | 12 written = set() |
13 root = FilePath('config') | |
14 for f in root.walk(): | |
15 if f.isfile() and f.path.endswith('.n3'): | |
16 n3 = f.getContent() | |
17 key = prefix + b'/'.join(f.segmentsFrom(root)) | |
334
bb80182195c0
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents:
333
diff
changeset
|
18 etcd.put(key, n3) |
333 | 19 written.add(key) |
20 print 'wrote %s' % key | |
21 for k in existing - written: | |
334
bb80182195c0
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents:
333
diff
changeset
|
22 etcd.delete(k) |
333 | 23 print 'removed %s' % k |
24 | |
334
bb80182195c0
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents:
333
diff
changeset
|
25 main() |