Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: tools/remove_html_imports.py

Issue 393993002: Properly namespace ignore_patterns in remove_html_imports. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 '''Tool for removing dart:html and related imports from a library. 6 '''Tool for removing dart:html and related imports from a library.
7 7
8 Copy SOURCE to TARGET, removing any lines that import dart:html. 8 Copy SOURCE to TARGET, removing any lines that import dart:html.
9 9
10 Usage: 10 Usage:
11 python tools/remove_html_imports.py SOURCE TARGET 11 python tools/remove_html_imports.py SOURCE TARGET
12 ''' 12 '''
13 13
14 import os 14 import os
15 import re 15 import re
16 import shutil 16 import shutil
17 import sys 17 import sys
18 18
19 HTML_IMPORT = re.compile(r'''^import ["']dart:(html|html_common|indexed_db''' 19 HTML_IMPORT = re.compile(r'''^import ["']dart:(html|html_common|indexed_db'''
20 r'''|js|svg|web_(audio|gl|sql))["'];$''', 20 r'''|js|svg|web_(audio|gl|sql))["'];$''',
21 flags=re.MULTILINE) 21 flags=re.MULTILINE)
22 22
23 def main(argv): 23 def main(argv):
24 source = argv[1] 24 source = argv[1]
25 target = argv[2] 25 target = argv[2]
26 shutil.rmtree(target) 26 shutil.rmtree(target)
27 shutil.copytree(source, target, ignore=ignore_patterns('.svn')) 27 shutil.copytree(source, target, ignore=shutil.ignore_patterns('.svn'))
28 28
29 for root, subFolders, files in os.walk(target): 29 for root, subFolders, files in os.walk(target):
30 for path in files: 30 for path in files:
31 if not path.endswith('.dart'): next 31 if not path.endswith('.dart'): next
32 with open(os.path.join(root, path), 'r+') as f: 32 with open(os.path.join(root, path), 'r+') as f:
33 contents = f.read() 33 contents = f.read()
34 f.seek(0) 34 f.seek(0)
35 f.truncate() 35 f.truncate()
36 f.write(HTML_IMPORT.sub(r'// import "dart:\1";', contents)) 36 f.write(HTML_IMPORT.sub(r'// import "dart:\1";', contents))
37 37
38 if __name__ == '__main__': 38 if __name__ == '__main__':
39 sys.exit(main(sys.argv)) 39 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698