Mercurial > code > home > repos > homeauto
annotate service/arduinoNode/pushConfig.py @ 1147:ef494fe0499f
forgot devices_shared.py
Ignore-this: 210e7777d9d4d11f148bb7e63f5de65a
darcs-hash:8dd34afc9d00fe796f94da254519e22ca1fa7d03
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Wed, 04 Apr 2018 14:58:27 -0700 |
parents | db955e7943af |
children | 13b2a61650c1 |
rev | line source |
---|---|
1138 | 1 from __future__ import division |
2 | |
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 |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
9 def main(): |
1138 | 10 prefix = b'arduino/' |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
11 existing = set(md.key for v, md in etcd.get_prefix(prefix)) |
1138 | 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)) | |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
18 etcd.put(key, n3) |
1138 | 19 written.add(key) |
20 print 'wrote %s' % key | |
21 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
|
22 etcd.delete(k) |
1138 | 23 print 'removed %s' % k |
24 | |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
25 main() |