annotate service/arduinoNode/pushConfig.py @ 333:90b469f43944

twisted pushConfig Ignore-this: b2dc9fbdc8652d4ba7afebf51d2e0319
author drewp@bigasterisk.com
date Sat, 03 Mar 2018 16:18:47 -0800
parents
children bb80182195c0
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
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
2
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
3 from twisted.internet import reactor
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
4 from twisted.internet.task import react
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
5 from twisted.internet.defer import inlineCallbacks, returnValue
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
6 from twisted.python.filepath import FilePath
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
7
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
8 import txaioetcd
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
9 etcd = txaioetcd.Client(reactor, u'http://bang6:2379')
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
10
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
11 @inlineCallbacks
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
12 def main(*a):
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
13 prefix = b'arduino/'
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
14 existing = set(row.key for row in
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
15 (yield etcd.get(txaioetcd.KeySet(prefix, prefix=True))).kvs)
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
16 written = set()
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
17 root = FilePath('config')
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
18 for f in root.walk():
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
19 if f.isfile() and f.path.endswith('.n3'):
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
20 n3 = f.getContent()
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
21 key = prefix + b'/'.join(f.segmentsFrom(root))
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
22 yield etcd.set(key, n3)
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
23 written.add(key)
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
24 print 'wrote %s' % key
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
25 for k in existing - written:
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
26 yield etcd.delete(k)
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
27 print 'removed %s' % k
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
28
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
29 react(main)