Mercurial > code > home > repos > homeauto
annotate service/arduinoNode/pushConfig.py @ 1148:8b4eda2cf0bd
fix pushconfig
Ignore-this: 36fd12eb507fbe027b9a00dbd78f13af
darcs-hash:a89764f2ad7791417d7c68d6ba30df92be97fe2c
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Sat, 14 Apr 2018 23:46:54 -0700 |
parents | db955e7943af |
children | 12f9f1838fb5 |
rev | line source |
---|---|
1138 | 1 from __future__ import division |
1148 | 2 import sys |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
3 import etcd3 |
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
4 |
1138 | 5 from twisted.python.filepath import FilePath |
6 | |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
7 etcd = etcd3.client(host='bang6') |
1138 | 8 |
1148 | 9 prefix, = sys.argv[1:] |
10 | |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
11 def main(): |
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
12 existing = set(md.key for v, md in etcd.get_prefix(prefix)) |
1138 | 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)) | |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
19 etcd.put(key, n3) |
1138 | 20 written.add(key) |
21 print 'wrote %s' % key | |
22 for k in existing - written: | |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
23 etcd.delete(k) |
1138 | 24 print 'removed %s' % k |
25 | |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
26 main() |