annotate service/arduinoNode/pushConfig.py @ 434:2409446ccfa2

switch to uart Ignore-this: b5285d12100bc182b970ea392f48e259
author drewp@bigasterisk.com
date Tue, 09 Apr 2019 09:05:42 -0700
parents 13b2a61650c1
children 12f9f1838fb5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
333
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
1 from __future__ import division
343
13b2a61650c1 fix pushconfig
drewp@bigasterisk.com
parents: 334
diff changeset
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
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
5 from twisted.python.filepath import FilePath
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
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
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
8
343
13b2a61650c1 fix pushconfig
drewp@bigasterisk.com
parents: 334
diff changeset
9 prefix, = sys.argv[1:]
13b2a61650c1 fix pushconfig
drewp@bigasterisk.com
parents: 334
diff changeset
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
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
13 written = set()
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
14 root = FilePath('config')
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
15 for f in root.walk():
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
16 if f.isfile() and f.path.endswith('.n3'):
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
17 n3 = f.getContent()
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
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
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
20 written.add(key)
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
21 print 'wrote %s' % key
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
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
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
24 print 'removed %s' % k
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
25
334
bb80182195c0 arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents: 333
diff changeset
26 main()