Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / tools / telemetry / catapult_base / refactor / module.py
blobd8b6fb86ae51652b56580efca0353a3cbe9f6605
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 from catapult_base.refactor import annotated_symbol
8 class Module(object):
9 def __init__(self, file_path):
10 self._file_path = file_path
12 with open(self._file_path, 'r') as f:
13 self._snippet = annotated_symbol.Annotate(f)
15 @property
16 def file_path(self):
17 return self._file_path
19 @property
20 def modified(self):
21 return self._snippet.modified
23 def FindAll(self, snippet_type):
24 return self._snippet.FindAll(snippet_type)
26 def FindChildren(self, snippet_type):
27 return self._snippet.FindChildren(snippet_type)
29 def Write(self):
30 """Write modifications to the file."""
31 if not self.modified:
32 return
34 # Stringify before opening the file for writing.
35 # If we fail, we won't truncate the file.
36 string = str(self._snippet)
37 with open(self._file_path, 'w') as f:
38 f.write(string)