Mercurial > templog
comparison py/params.py @ 160:256505f98c4d
uploader works
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 03 Jan 2013 22:37:33 +0800 |
parents | 6d799bee3508 |
children | d73077e8cd67 |
comparison
equal
deleted
inserted
replaced
159:683cfd134f6a | 160:256505f98c4d |
---|---|
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 import collections | 2 import collections |
3 import json | 3 import json |
4 import signal | 4 import signal |
5 import StringIO | |
5 | 6 |
6 import gevent | 7 import gevent |
7 | 8 |
8 import config | 9 import config |
9 from utils import W,L,E,EX | 10 from utils import W,L,E,EX |
46 for k in u: | 47 for k in u: |
47 if k not in self: | 48 if k not in self: |
48 raise self.Error("Unknown parameter %s=%s in file '%s'" % (str(k), str(u[k]), getattr(f, 'name', '???'))) | 49 raise self.Error("Unknown parameter %s=%s in file '%s'" % (str(k), str(u[k]), getattr(f, 'name', '???'))) |
49 self.update(u) | 50 self.update(u) |
50 | 51 |
52 L("Loaded parameters") | |
53 L(self.save_string()) | |
54 | |
55 | |
51 def save(self, f = None): | 56 def save(self, f = None): |
52 if not f: | 57 if not f: |
53 f = file(config.PARAMS_FILE, 'w') | 58 f = file(config.PARAMS_FILE, 'w') |
54 json.dump(self, f, sort_keys=True, indent=4) | 59 json.dump(self, f, sort_keys=True, indent=4) |
55 f.write('\n') | 60 f.write('\n') |
56 f.flush() | 61 f.flush() |
57 | 62 |
63 def save_string(self): | |
64 s = StringIO.StringIO() | |
65 self.save(s) | |
66 return s.getvalue() | |
67 | |
58 def reload_signal(self): | 68 def reload_signal(self): |
59 try: | 69 try: |
60 self.load() | 70 self.load() |
61 L("Reloaded params") | 71 L("Reloaded.") |
62 except self.Error, e: | 72 except self.Error, e: |
63 W("Problem reloading: %s" % str(e)) | 73 W("Problem reloading: %s" % str(e)) |