OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
3 # for details. All rights reserved. Use of this source code is governed by a | |
4 # BSD-style license that can be found in the LICENSE file. | |
5 | |
6 '''Tool for removing dart:html and related imports from a library. | |
7 | |
8 Copy SOURCE to TARGET, removing any lines that import dart:html. | |
9 | |
10 Usage: | |
11 python tools/remove_html_imports.py SOURCE TARGET | |
12 ''' | |
13 | |
14 import os | |
15 import re | |
16 import shutil | |
17 import sys | |
18 | |
19 HTML_IMPORT = re.compile(r'import ["' "'" r']dart:(html|html_common|indexed_db' | |
floitsch
2014/07/15 20:15:58
use long-strings. (''') this way the ['"] gets eas
nweiz
2014/07/15 20:27:48
Done.
| |
20 r'|js|svg|web_(audio|gl|sql))["' "'" r'];') | |
21 | |
22 def main(argv): | |
23 source = argv[1] | |
24 target = argv[2] | |
25 shutil.rmtree(target) | |
26 shutil.copytree(source, target) | |
27 | |
28 for root, subFolders, files in os.walk(target): | |
29 for path in files: | |
30 if not path.endswith('.dart'): next | |
31 with open(os.path.join(root, path), 'r+') as f: | |
32 contents = f.read() | |
33 f.seek(0) | |
34 f.truncate() | |
35 f.write(HTML_IMPORT.sub(r'// import "dart:\1";', contents)) | |
36 | |
37 if __name__ == '__main__': | |
38 sys.exit(main(sys.argv)) | |
OLD | NEW |