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

Side by Side Diff: Tools/Scripts/webkitpy/w3c/test_importer.py

Issue 15901008: Modify w3c import script to be able to run over a whole repo. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: add more FIXME comments for error handling Created 7 years, 6 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 3 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
4 # 4 #
5 # Redistribution and use in source and binary forms, with or without 5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions 6 # modification, are permitted provided that the following conditions
7 # are met: 7 # are met:
8 # 8 #
9 # 1. Redistributions of source code must retain the above 9 # 1. Redistributions of source code must retain the above
10 # copyright notice, this list of conditions and the following 10 # copyright notice, this list of conditions and the following
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 TEST_STATUS_UNKNOWN = 'unknown' 104 TEST_STATUS_UNKNOWN = 'unknown'
105 TEST_STATUS_APPROVED = 'approved' 105 TEST_STATUS_APPROVED = 'approved'
106 TEST_STATUS_SUBMITTED = 'submitted' 106 TEST_STATUS_SUBMITTED = 'submitted'
107 107
108 CHANGESET_NOT_AVAILABLE = 'Not Available' 108 CHANGESET_NOT_AVAILABLE = 'Not Available'
109 109
110 110
111 def main(_argv, _stdout, _stderr): 111 def main(_argv, _stdout, _stderr):
112 options, args = parse_args() 112 options, args = parse_args()
113 import_dir = validate_import_directory(args[0]) 113 import_dir = args[0]
114 test_importer = TestImporter(Host(), import_dir, options) 114 if len(args) == 1:
115 repo_dir = os.path.dirname(import_dir)
116 else:
117 repo_dir = args[1]
118
119 if not os.path.exists(import_dir):
120 sys.exit('Source directory %s not found!' % import_dir)
121
122 if not os.path.exists(repo_dir):
123 sys.exit('Repository directory %s not found!' % repo_dir)
124 if not repo_dir in import_dir:
125 sys.exit('Repository directory %s must be a parent of %s' % (repo_dir, i mport_dir))
126
127 test_importer = TestImporter(Host(), import_dir, repo_dir, options)
115 test_importer.do_import() 128 test_importer.do_import()
116 129
117 130
118 def parse_args(): 131 def parse_args():
119 parser = optparse.OptionParser(usage='usage: %prog [options] w3c_test_direct ory') 132 parser = optparse.OptionParser(usage='usage: %prog [options] w3c_test_direct ory [repo_directory]')
120 parser.add_option('-n', '--no-overwrite', dest='overwrite', action='store_fa lse', default=True, 133 parser.add_option('-n', '--no-overwrite', dest='overwrite', action='store_fa lse', default=True,
121 help='Flag to prevent duplicate test files from overwriting existing tes ts. By default, they will be overwritten') 134 help='Flag to prevent duplicate test files from overwriting existing tes ts. By default, they will be overwritten')
122 parser.add_option('-a', '--all', action='store_true', default=False, 135 parser.add_option('-a', '--all', action='store_true', default=False,
123 help='Import all tests including reftests, JS tests, and manual/pixel te sts. By default, only reftests and JS tests are imported') 136 help='Import all tests including reftests, JS tests, and manual/pixel te sts. By default, only reftests and JS tests are imported')
124 137
125 options, args = parser.parse_args() 138 options, args = parser.parse_args()
126 if len(args) != 1: 139 if len(args) not in (1, 2):
127 parser.error('Incorrect number of arguments') 140 parser.error('Incorrect number of arguments')
128 return options, args 141 return options, args
129 142
130 143
131 def validate_import_directory(import_dir):
132 if not os.path.exists(import_dir):
133 sys.exit('Source directory %s not found!' % import_dir)
134
135 # Make sure the tests are officially submitted to the W3C, either approved o r
136 # submitted following their directory naming conventions
137 if import_dir.find('approved') == -1 and import_dir.find('submitted') == -1:
138 # If not pointed directly to the approved directory or to any submitted
139 # directory, check for a submitted subdirectory and go with that
140 import_dir = os.path.join(import_dir, 'submitted')
141 if not os.path.exists(os.path.join(import_dir)):
142 sys.exit('Unable to import tests that aren\'t approved or submitted to the W3C')
143
144 return import_dir
145
146
147 class TestImporter(object): 144 class TestImporter(object):
148 145
149 def __init__(self, host, source_directory, options): 146 def __init__(self, host, source_directory, repo_dir, options):
150 self.host = host 147 self.host = host
151 self.source_directory = source_directory 148 self.source_directory = source_directory
152 self.options = options 149 self.options = options
153 150
154 self.filesystem = self.host.filesystem 151 self.filesystem = self.host.filesystem
152
155 self._webkit_root = __file__.split(self.filesystem.sep + 'Tools')[0] 153 self._webkit_root = __file__.split(self.filesystem.sep + 'Tools')[0]
154 self.repo_dir = repo_dir
155 subdirs = os.path.dirname(os.path.relpath(source_directory, repo_dir))
156 156
157 self.destination_directory = self.path_from_webkit_root("LayoutTests", " csswg") 157 self.destination_directory = os.path.join(self.path_from_webkit_root("La youtTests"), 'w3c', subdirs)
158 158
159 self.changeset = CHANGESET_NOT_AVAILABLE 159 self.changeset = CHANGESET_NOT_AVAILABLE
160 self.test_status = TEST_STATUS_UNKNOWN 160 self.test_status = TEST_STATUS_UNKNOWN
161 161
162 self.import_list = [] 162 self.import_list = []
163 163
164 def path_from_webkit_root(self, *comps): 164 def path_from_webkit_root(self, *comps):
165 return self.filesystem.abspath(self.filesystem.join(self._webkit_root, * comps)) 165 return self.filesystem.abspath(self.filesystem.join(self._webkit_root, * comps))
166 166
167 def do_import(self): 167 def do_import(self):
(...skipping 10 matching lines...) Expand all
178 178
179 def find_importable_tests(self, directory): 179 def find_importable_tests(self, directory):
180 # FIXME: use filesystem 180 # FIXME: use filesystem
181 for root, dirs, files in os.walk(directory): 181 for root, dirs, files in os.walk(directory):
182 print 'Scanning ' + root + '...' 182 print 'Scanning ' + root + '...'
183 total_tests = 0 183 total_tests = 0
184 reftests = 0 184 reftests = 0
185 jstests = 0 185 jstests = 0
186 186
187 # "archive" and "data" dirs are internal csswg things that live in e very approved directory. 187 # "archive" and "data" dirs are internal csswg things that live in e very approved directory.
188 DIRS_TO_SKIP = ('.git', '.hg', 'data', 'archive') 188 # FIXME: skip 'incoming' tests for now, but we should rework the 'te st_status' concept and
189 # support reading them as well.
190 DIRS_TO_SKIP = ('.git', '.hg', 'data', 'archive', 'incoming')
189 for d in DIRS_TO_SKIP: 191 for d in DIRS_TO_SKIP:
190 if d in dirs: 192 if d in dirs:
191 dirs.remove(d) 193 dirs.remove(d)
192 194
193 copy_list = [] 195 copy_list = []
194 196
195 for filename in files: 197 for filename in files:
196 # FIXME: This block should really be a separate function, but th e early-continues make that difficult. 198 # FIXME: This block should really be a separate function, but th e early-continues make that difficult.
197 199
198 if filename.startswith('.') or filename.endswith('.pl'): 200 if filename.startswith('.') or filename.endswith('.pl'):
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 # We can skip the support directory if no tests were found. 252 # We can skip the support directory if no tests were found.
251 if 'support' in dirs: 253 if 'support' in dirs:
252 dirs.remove('support') 254 dirs.remove('support')
253 255
254 if copy_list: 256 if copy_list:
255 # Only add this directory to the list if there's something to im port 257 # Only add this directory to the list if there's something to im port
256 self.import_list.append({'dirname': root, 'copy_list': copy_list , 258 self.import_list.append({'dirname': root, 'copy_list': copy_list ,
257 'reftests': reftests, 'jstests': jstests, 'total_tests': tot al_tests}) 259 'reftests': reftests, 'jstests': jstests, 'total_tests': tot al_tests})
258 260
259 def import_tests(self): 261 def import_tests(self):
260 if self.import_list:
261 self.setup_destination_directory()
262
263 converter = W3CTestConverter() 262 converter = W3CTestConverter()
264 total_imported_tests = 0 263 total_imported_tests = 0
265 total_imported_reftests = 0 264 total_imported_reftests = 0
266 total_imported_jstests = 0 265 total_imported_jstests = 0
267 total_prefixed_properties = {} 266 total_prefixed_properties = {}
268 267
269 for dir_to_copy in self.import_list: 268 for dir_to_copy in self.import_list:
270
271 total_imported_tests += dir_to_copy['total_tests'] 269 total_imported_tests += dir_to_copy['total_tests']
272 total_imported_reftests += dir_to_copy['reftests'] 270 total_imported_reftests += dir_to_copy['reftests']
273 total_imported_jstests += dir_to_copy['jstests'] 271 total_imported_jstests += dir_to_copy['jstests']
274 272
275 prefixed_properties = [] 273 prefixed_properties = []
276 274
277 if not dir_to_copy['copy_list']: 275 if not dir_to_copy['copy_list']:
278 continue 276 continue
279 277
280 # Build the subpath starting with the approved/submitted directory
281 orig_path = dir_to_copy['dirname'] 278 orig_path = dir_to_copy['dirname']
282 start = orig_path.find(self.test_status)
283 new_subpath = orig_path[start:len(orig_path)]
284 279
285 # Append the new subpath to the destination_directory 280 subpath = os.path.relpath(orig_path, self.repo_dir)
286 new_path = os.path.join(self.destination_directory, new_subpath) 281 new_path = os.path.join(self.destination_directory, subpath)
287 282
288 # Create the destination subdirectories if not there
289 if not(os.path.exists(new_path)): 283 if not(os.path.exists(new_path)):
290 os.makedirs(new_path) 284 os.makedirs(new_path)
291 285
292 copied_files = [] 286 copied_files = []
293 287
294 for file_to_copy in dir_to_copy['copy_list']: 288 for file_to_copy in dir_to_copy['copy_list']:
295 # FIXME: Split this block into a separate function. 289 # FIXME: Split this block into a separate function.
296 orig_filepath = os.path.normpath(file_to_copy['src']) 290 orig_filepath = os.path.normpath(file_to_copy['src'])
297 291
298 assert(not os.path.isdir(orig_filepath)) 292 if os.path.isdir(orig_filepath):
293 # FIXME: Figure out what is triggering this and what to do a bout it.
294 print 'Error: %s refers to a directory' % orig_filepath
295 continue
299 296
300 if not(os.path.exists(orig_filepath)): 297 if not(os.path.exists(orig_filepath)):
301 print 'Warning: ' + orig_filepath + ' not found. Possible er ror in the test.' 298 print 'Warning: ' + orig_filepath + ' not found. Possible er ror in the test.'
302 continue 299 continue
303 300
304 new_filepath = os.path.join(new_path, file_to_copy['dest']) 301 new_filepath = os.path.join(new_path, file_to_copy['dest'])
305 302
306 if not(os.path.exists(os.path.dirname(new_filepath))): 303 if not(os.path.exists(os.path.dirname(new_filepath))):
307 os.makedirs(os.path.dirname(new_filepath)) 304 os.makedirs(os.path.dirname(new_filepath))
308 305
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 print "Properties needing prefixes (by count):" 347 print "Properties needing prefixes (by count):"
351 for prefixed_property in sorted(total_prefixed_properties, key=lambda p: total_prefixed_properties[p]): 348 for prefixed_property in sorted(total_prefixed_properties, key=lambda p: total_prefixed_properties[p]):
352 print " %s: %s" % (prefixed_property, total_prefixed_properties[pre fixed_property]) 349 print " %s: %s" % (prefixed_property, total_prefixed_properties[pre fixed_property])
353 350
354 def setup_destination_directory(self): 351 def setup_destination_directory(self):
355 """ Creates a destination directory that mirrors that of the source appr oved or submitted directory """ 352 """ Creates a destination directory that mirrors that of the source appr oved or submitted directory """
356 353
357 self.update_test_status() 354 self.update_test_status()
358 355
359 start = self.source_directory.find(self.test_status) 356 start = self.source_directory.find(self.test_status)
360 new_subpath = self.source_directory[start:len(self.source_directory)] 357 new_subpath = self.source_directory[len(self.repo_dir):]
361 358
362 destination_directory = os.path.join(self.destination_directory, new_sub path) 359 destination_directory = os.path.join(self.destination_directory, new_sub path)
363 360
364 if not os.path.exists(destination_directory): 361 if not os.path.exists(destination_directory):
365 os.makedirs(destination_directory) 362 os.makedirs(destination_directory)
366 363
367 print 'Tests will be imported into: ' + destination_directory 364 print 'Tests will be imported into: ' + destination_directory
368 365
369 def update_test_status(self): 366 def update_test_status(self):
370 """ Sets the test status to either 'approved' or 'submitted' """ 367 """ Sets the test status to either 'approved' or 'submitted' """
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 for prop in prop_list: 420 for prop in prop_list:
424 import_log.write(prop + '\n') 421 import_log.write(prop + '\n')
425 else: 422 else:
426 import_log.write('None\n') 423 import_log.write('None\n')
427 import_log.write('------------------------------------------------------ ------------------\n') 424 import_log.write('------------------------------------------------------ ------------------\n')
428 import_log.write('List of files:\n') 425 import_log.write('List of files:\n')
429 for item in file_list: 426 for item in file_list:
430 import_log.write(item + '\n') 427 import_log.write(item + '\n')
431 428
432 import_log.close() 429 import_log.close()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698