Mercurial > templog
annotate py/receive.py @ 505:ad846b9bdd10
key fingerprints are case- and whitespace-insensitive.
add some comments
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 26 Jun 2014 23:02:23 +0800 |
parents | 905bbab632f7 |
children | 185621f47040 |
rev | line source |
---|---|
493 | 1 #!/usr/bin/env python |
2 | |
3 import params | |
4 import json | |
5 import sys | |
6 import tempfile | |
7 import signal | |
8 import os | |
9 | |
10 import config | |
11 | |
12 | |
13 def same_type(a, b): | |
14 ta = type(a) | |
15 tb = type(b) | |
16 | |
17 if ta == int: | |
18 ta = float | |
19 if tb == int: | |
20 tb = float | |
21 | |
22 return (ta == tb) | |
23 | |
24 def main(): | |
25 | |
26 i = sys.stdin.read() | |
27 new_params = json.loads(i) | |
28 | |
29 def_params = params.Params() | |
30 | |
31 if def_params.viewkeys() != new_params.viewkeys(): | |
32 diff = def_params.viewkeys() ^ new_params.viewkeys() | |
33 return "Mismatching params, %s" % str(diff) | |
34 | |
35 for k, v in new_params.items(): | |
36 if not same_type(v, def_params[k]): | |
37 return "Bad type for %s" % k | |
38 | |
39 dir = os.path.dirname(config.PARAMS_FILE) | |
40 | |
41 try: | |
42 t = tempfile.NamedTemporaryFile(prefix='config', | |
43 dir = dir, | |
44 delete = False) | |
45 | |
46 t.write(json.dumps(new_params, sort_keys=True, indent=4)+'\n') | |
495
905bbab632f7
Make sure we close descriptor before rename
Matt Johnston <matt@ucc.asn.au>
parents:
493
diff
changeset
|
47 name = t.name |
905bbab632f7
Make sure we close descriptor before rename
Matt Johnston <matt@ucc.asn.au>
parents:
493
diff
changeset
|
48 t.close() |
493 | 49 |
495
905bbab632f7
Make sure we close descriptor before rename
Matt Johnston <matt@ucc.asn.au>
parents:
493
diff
changeset
|
50 os.rename(name, config.PARAMS_FILE) |
493 | 51 except Exception, e: |
52 return "Problem: %s" % e | |
53 | |
54 try: | |
55 pid = int(open('%s/tempserver.pid' % dir, 'r').read()) | |
56 if pid < 2: | |
57 return "Bad pid %d" % pid | |
58 os.kill(pid, signal.SIGHUP) | |
59 except Exception, e: | |
60 return "HUP problem: %s" % e | |
61 | |
62 return 'Good Update' | |
63 | |
64 if __name__ == '__main__': | |
65 print main() | |
66 |