| 218 | |
| 219 | |
| 220 | def LoadPythonDictionary(path): |
| 221 | file_string = open(path).read() |
| 222 | try: |
| 223 | file_data = eval(file_string, {'__builtins__': None}, None) |
| 224 | except SyntaxError as e: |
| 225 | e.filename = path |
| 226 | raise |
| 227 | except Exception as e: |
| 228 | raise Exception("Unexpected error while reading %s: %s" % (path, str(e))) |
| 229 | |
| 230 | assert isinstance(file_data, dict), "%s does not eval to a dictionary" % path |
| 231 | |
| 232 | # Flatten any variables to the top level. |
| 233 | if 'variables' in file_data: |
| 234 | file_data.update(file_data['variables']) |
| 235 | del file_data['variables'] |
| 236 | |
| 237 | # Strip all elements that this script can't process. |
| 238 | elements_to_strip = [ |
| 239 | 'conditions', |
| 240 | 'direct_dependent_settings', |
| 241 | 'target_conditions', |
| 242 | 'target_defaults', |
| 243 | 'targets', |
| 244 | 'includes', |
| 245 | 'actions', |
| 246 | ] |
| 247 | for element in elements_to_strip: |
| 248 | if element in file_data: |
| 249 | del file_data[element] |
| 250 | |
| 251 | return file_data |
| 252 | |
| 253 | |
| 254 | def ReplaceSubstrings(values, search_for, replace_with): |