diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-03-30 11:28:51 -0400 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-02 10:38:21 -0400 |
commit | 4b75d2b98036195b78d339210ab8d7512d9f2164 (patch) | |
tree | f7de0e91372f760ab8972c5e280023d57abb6b91 /common.py | |
parent | cb0dda981282df08c544e235f0fefb077268272c (diff) |
Added option to ignore environment issues and rewrote part of the generation scripts for easier generator creation.
Diffstat (limited to 'common.py')
-rw-r--r-- | common.py | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -50,6 +50,12 @@ def get_config_option(option): | |||
50 | else: | 50 | else: |
51 | raise IOError("No config file exists!") | 51 | raise IOError("No config file exists!") |
52 | 52 | ||
53 | def try_get_config_option(option, default): | ||
54 | try: | ||
55 | get_config_option(option) | ||
56 | except: | ||
57 | return default | ||
58 | |||
53 | def recordtype(typename, field_names, default=0): | 59 | def recordtype(typename, field_names, default=0): |
54 | ''' Mutable namedtuple. Recipe from George Sakkis of MIT.''' | 60 | ''' Mutable namedtuple. Recipe from George Sakkis of MIT.''' |
55 | field_names = tuple(map(str, field_names)) | 61 | field_names = tuple(map(str, field_names)) |
@@ -127,10 +133,7 @@ def load_params(fname): | |||
127 | with open(fname, 'r') as f: | 133 | with open(fname, 'r') as f: |
128 | data = f.read() | 134 | data = f.read() |
129 | try: | 135 | try: |
130 | parsed = eval(data) | 136 | params = eval(data) |
131 | # Convert to defaultdict | ||
132 | for k in parsed: | ||
133 | params[k] = str(parsed[k]) | ||
134 | except Exception as e: | 137 | except Exception as e: |
135 | raise IOError("Invalid param file: %s\n%s" % (fname, e)) | 138 | raise IOError("Invalid param file: %s\n%s" % (fname, e)) |
136 | 139 | ||