comparison py/params.py @ 529:5201f441bf4a

run 2to3
author Matt Johnston <matt@ucc.asn.au>
date Fri, 10 Apr 2015 23:59:16 +0800
parents dd8895652485
children e39ed85d87a5
comparison
equal deleted inserted replaced
528:61e61de49a50 529:5201f441bf4a
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 import io
6 6
7 import config 7 import config
8 from utils import W,L,E,EX 8 from utils import W,L,E,EX
9 9
10 _FIELD_DEFAULTS = { 10 _FIELD_DEFAULTS = {
35 35
36 def load(self, f = None): 36 def load(self, f = None):
37 if not f: 37 if not f:
38 try: 38 try:
39 f = file(config.PARAMS_FILE, 'r') 39 f = file(config.PARAMS_FILE, 'r')
40 except IOError, e: 40 except IOError as e:
41 W("Missing parameter file, using defaults. %s", e) 41 W("Missing parameter file, using defaults. %s", e)
42 return 42 return
43 try: 43 try:
44 u = json.load(f) 44 u = json.load(f)
45 except Exception, e: 45 except Exception as e:
46 raise self.Error(e) 46 raise self.Error(e)
47 47
48 for k in u: 48 for k in u:
49 if k.startswith('_'): 49 if k.startswith('_'):
50 continue 50 continue
62 json.dump(self, f, sort_keys=True, indent=4) 62 json.dump(self, f, sort_keys=True, indent=4)
63 f.write('\n') 63 f.write('\n')
64 f.flush() 64 f.flush()
65 65
66 def save_string(self): 66 def save_string(self):
67 s = StringIO.StringIO() 67 s = io.StringIO()
68 self.save(s) 68 self.save(s)
69 return s.getvalue() 69 return s.getvalue()