Mercurial > code > home > repos > homeauto
annotate service/arduinoNode/pushConfig.py @ 1754:92999dfbf321 default tip
add shelly support
author | drewp@bigasterisk.com |
---|---|
date | Tue, 04 Jun 2024 13:03:43 -0700 |
parents | 6b80a6c58907 |
children |
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 | |
1685 | 7 etcd = etcd3.client(host='etcd-homeauto', port=9022) |
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') | |
456
12f9f1838fb5
arduinoNode: build updates, stats support, etc
drewp@bigasterisk.com
parents:
343
diff
changeset
|
15 print 'reading at %s' % root |
333 | 16 for f in root.walk(): |
17 if f.isfile() and f.path.endswith('.n3'): | |
18 n3 = f.getContent() | |
19 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
|
20 etcd.put(key, n3) |
333 | 21 written.add(key) |
22 print 'wrote %s' % key | |
23 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
|
24 etcd.delete(k) |
333 | 25 print 'removed %s' % k |
26 | |
334
bb80182195c0
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents:
333
diff
changeset
|
27 main() |