Mercurial > code > home > repos > homeauto
annotate service/arduinoNode/pushConfig.py @ 343:13b2a61650c1
fix pushconfig
Ignore-this: 36fd12eb507fbe027b9a00dbd78f13af
author | drewp@bigasterisk.com |
---|---|
date | Sat, 14 Apr 2018 23:46:54 -0700 |
parents | bb80182195c0 |
children | 12f9f1838fb5 |
rev | line source |
---|---|
333 | 1 from __future__ import division |
343 | 2 import sys |
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 |
343 | 9 prefix, = sys.argv[1:] |
10 | |
334
bb80182195c0
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents:
333
diff
changeset
|
11 def main(): |
bb80182195c0
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents:
333
diff
changeset
|
12 existing = set(md.key for v, md in etcd.get_prefix(prefix)) |
333 | 13 written = set() |
14 root = FilePath('config') | |
15 for f in root.walk(): | |
16 if f.isfile() and f.path.endswith('.n3'): | |
17 n3 = f.getContent() | |
18 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
|
19 etcd.put(key, n3) |
333 | 20 written.add(key) |
21 print 'wrote %s' % key | |
22 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
|
23 etcd.delete(k) |
333 | 24 print 'removed %s' % k |
25 | |
334
bb80182195c0
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents:
333
diff
changeset
|
26 main() |