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

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

Issue 2598743002: When importing w3c repos, convert CRLF line endings. (Closed)
Patch Set: Created 3 years, 12 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
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_importer_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions 4 # modification, are permitted provided that the following conditions
5 # are met: 5 # are met:
6 # 6 #
7 # 1. Redistributions of source code must retain the above 7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following 8 # copyright notice, this list of conditions and the following
9 # disclaimer. 9 # disclaimer.
10 # 2. Redistributions in binary form must reproduce the above 10 # 2. Redistributions in binary form must reproduce the above
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 host=self.host) 412 host=self.host)
413 for prefixed_property in converted_file[0]: 413 for prefixed_property in converted_file[0]:
414 self._prefixed_properties.setdefault(prefixed_property, 0) 414 self._prefixed_properties.setdefault(prefixed_property, 0)
415 self._prefixed_properties[prefixed_property] += 1 415 self._prefixed_properties[prefixed_property] += 1
416 416
417 if not self.options.dry_run: 417 if not self.options.dry_run:
418 self.filesystem.write_text_file(dest_path, converted_file[1]) 418 self.filesystem.write_text_file(dest_path, converted_file[1])
419 else: 419 else:
420 if not self.import_in_place and not self.options.dry_run: 420 if not self.import_in_place and not self.options.dry_run:
421 self.filesystem.copyfile(source_path, dest_path) 421 self.filesystem.copyfile(source_path, dest_path)
422 if self.filesystem.read_binary_file(source_path)[:2] == '#!': 422 self._transform_for_presubmit(dest_path)
423 self.filesystem.make_executable(dest_path)
424 423
425 return dest_path.replace(self._webkit_root, '') 424 return dest_path.replace(self._webkit_root, '')
426 425
426 def _transform_for_presubmit(self, path):
427 """Changes a file in order to pass the Chromium top-level presubmit.
428
429 This should only transform text files; if the Chromium presubmit is
430 changed to ignore imported files, then this would be unnecessary.
431 """
432 # There may be some text files that are encoded with utf-16 or other
433 # encodings, but these are rare.
434 try:
435 text = self.filesystem.read_text_file(path)
436 except UnicodeDecodeError:
437 return
438 if text[:2] == '#!':
439 self.filesystem.make_executable(path)
440 if '\r\n' in text:
441 _log.warning('File %s has CRLF line endings.', path)
442 self.filesystem.write_text_file(path, text.replace('\r\n', '\n'))
443
427 @staticmethod 444 @staticmethod
428 def should_try_to_convert(file_to_copy, source_path, dest_dir): 445 def should_try_to_convert(file_to_copy, source_path, dest_dir):
429 """Checks whether we should try to modify the file when importing.""" 446 """Checks whether we should try to modify the file when importing."""
430 if file_to_copy.get('is_jstest', False): 447 if file_to_copy.get('is_jstest', False):
431 return False 448 return False
432 449
433 # Conversion is not necessary for any tests in wpt now; see http://crbug .com/654081. 450 # Conversion is not necessary for any tests in wpt now; see http://crbug .com/654081.
434 # Note, we want to move away from converting files, see http://crbug.com /663773. 451 # Note, we want to move away from converting files, see http://crbug.com /663773.
435 if re.search(r'[/\\]imported[/\\]wpt[/\\]', dest_dir): 452 if re.search(r'[/\\]imported[/\\]wpt[/\\]', dest_dir):
436 return False 453 return False
437 454
438 # Only HTML, XHTML and CSS files should be converted. 455 # Only HTML, XHTML and CSS files should be converted.
439 mimetype, _ = mimetypes.guess_type(source_path) 456 mimetype, _ = mimetypes.guess_type(source_path)
440 return mimetype in ('text/html', 'application/xhtml+xml', 'text/css') 457 return mimetype in ('text/html', 'application/xhtml+xml', 'text/css')
441 458
442 def path_too_long(self, source_path): 459 def path_too_long(self, source_path):
443 """Checks whether a source path is too long to import. 460 """Checks whether a source path is too long to import.
444 461
445 Args: 462 Args:
446 Absolute path of file to be imported. 463 Absolute path of file to be imported.
447 464
448 Returns: 465 Returns:
449 True if the path is too long to import, False if it's OK. 466 True if the path is too long to import, False if it's OK.
450 """ 467 """
451 path_from_repo_base = os.path.relpath(source_path, self.source_repo_path ) 468 path_from_repo_base = os.path.relpath(source_path, self.source_repo_path )
452 return len(path_from_repo_base) > MAX_PATH_LENGTH 469 return len(path_from_repo_base) > MAX_PATH_LENGTH
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_importer_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698