Changeset 180844 in webkit


Ignore:
Timestamp:
Feb 28, 2015 2:47:40 PM (9 years ago)
Author:
youenn.fablet@crf.canon.fr
Message:

W3C importer should use filesystem instead of shutil/host
https://bugs.webkit.org/show_bug.cgi?id=142012

Reviewed by Bem Jones-Bey.

Removed direct use of python shutil and os, except for os.walk which will require its own fix.

  • Scripts/webkitpy/w3c/test_importer.py:

(main):
(TestImporter.do_import):
(TestImporter.find_importable_tests):
(TestImporter.import_tests):
(TestImporter.remove_deleted_files):
(TestImporter.write_import_log):

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r180830 r180844  
     12015-02-28  Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        W3C importer should use filesystem instead of shutil/host
     4        https://bugs.webkit.org/show_bug.cgi?id=142012
     5
     6        Reviewed by Bem Jones-Bey.
     7
     8        Removed direct use of python shutil and os, except for os.walk which will require its own fix.
     9
     10        * Scripts/webkitpy/w3c/test_importer.py:
     11        (main):
     12        (TestImporter.do_import):
     13        (TestImporter.find_importable_tests):
     14        (TestImporter.import_tests):
     15        (TestImporter.remove_deleted_files):
     16        (TestImporter.write_import_log):
     17
    1182015-02-28  Youenn Fablet  <youenn.fablet@crf.canon.fr>
    219
  • trunk/Tools/Scripts/webkitpy/w3c/test_importer.py

    r180830 r180844  
    6969"""
    7070
    71 # FIXME: Change this file to use the Host abstractions rather that os, sys, shutils, etc.
    72 
    7371import argparse
    7472import datetime
     
    7674import mimetypes
    7775import os
    78 import shutil
    7976import sys
    8077
    8178from webkitpy.common.host import Host
     79from webkitpy.common.system.filesystem import FileSystem
    8280from webkitpy.common.webkit_finder import WebKitFinder
    8381from webkitpy.common.system.executive import ScriptError
     
    9391    options, args = parse_args(_argv)
    9492    import_dir = args[0]
    95 
    96     if not os.path.exists(import_dir):
     93    filesystem = FileSystem()
     94    if not filesystem.exists(import_dir):
    9795        sys.exit('Source directory %s not found!' % import_dir)
    9896
     
    161159        else:
    162160            for test_path in self.options.test_paths:
    163                 self.find_importable_tests(os.path.join(self.source_directory, test_path))
     161                self.find_importable_tests(self.filesystem.join(self.source_directory, test_path))
    164162        self.import_tests()
    165163
     
    195193                    continue
    196194
    197                 fullpath = os.path.join(root, filename)
     195                fullpath = self.filesystem.join(root, filename)
    198196
    199197                mimetype = mimetypes.guess_type(fullpath)
     
    206204                if test_info is None:
    207205                    # If html file is in a "resources" folder, it should be copied anyway
    208                     if os.path.basename(os.path.dirname(fullpath)) == "resources":
     206                    if self.filesystem.basename(self.filesystem.dirname(fullpath)) == "resources":
    209207                        copy_list.append({'src': fullpath, 'dest': filename})
    210208                    continue
     
    213211                    reftests += 1
    214212                    total_tests += 1
    215                     test_basename = os.path.basename(test_info['test'])
     213                    test_basename = self.filesystem.basename(test_info['test'])
    216214
    217215                    # Add the ref file, following WebKit style.
     
    220218                    # Using a naming convention creates duplicate copies of the
    221219                    # reference files.
    222                     ref_file = os.path.splitext(test_basename)[0] + '-expected'
    223                     ref_file += os.path.splitext(test_basename)[1]
     220                    ref_file = self.filesystem.splitext(test_basename)[0] + '-expected'
     221                    ref_file += self.filesystem.splitext(test_basename)[1]
    224222
    225223                    copy_list.append({'src': test_info['reference'], 'dest': ref_file, 'reference_support_info': test_info['reference_support_info']})
     
    261259            orig_path = dir_to_copy['dirname']
    262260
    263             subpath = os.path.relpath(orig_path, self.source_directory)
    264             new_path = os.path.join(self.destination_directory, subpath)
    265 
    266             if not(os.path.exists(new_path)):
    267                 os.makedirs(new_path)
     261            subpath = self.filesystem.relpath(orig_path, self.source_directory)
     262            new_path = self.filesystem.join(self.destination_directory, subpath)
     263
     264            if not(self.filesystem.exists(new_path)):
     265                self.filesystem.maybe_make_directory(new_path)
    268266
    269267            copied_files = []
     
    271269            for file_to_copy in dir_to_copy['copy_list']:
    272270                # FIXME: Split this block into a separate function.
    273                 orig_filepath = os.path.normpath(file_to_copy['src'])
    274 
    275                 if os.path.isdir(orig_filepath):
     271                orig_filepath = self.filesystem.normpath(file_to_copy['src'])
     272
     273                if self.filesystem.isdir(orig_filepath):
    276274                    # FIXME: Figure out what is triggering this and what to do about it.
    277275                    _log.error('%s refers to a directory' % orig_filepath)
    278276                    continue
    279277
    280                 if not(os.path.exists(orig_filepath)):
     278                if not(self.filesystem.exists(orig_filepath)):
    281279                    _log.warning('%s not found. Possible error in the test.', orig_filepath)
    282280                    continue
    283281
    284                 new_filepath = os.path.join(new_path, file_to_copy['dest'])
     282                new_filepath = self.filesystem.join(new_path, file_to_copy['dest'])
    285283                if 'reference_support_info' in file_to_copy.keys() and file_to_copy['reference_support_info'] != {}:
    286284                    reference_support_info = file_to_copy['reference_support_info']
     
    288286                    reference_support_info = None
    289287
    290                 if not(os.path.exists(os.path.dirname(new_filepath))):
    291                     os.makedirs(os.path.dirname(new_filepath))
    292 
    293                 if not self.options.overwrite and os.path.exists(new_filepath):
     288                if not(self.filesystem.exists(self.filesystem.dirname(new_filepath))):
     289                    self.filesystem.maybe_make_directory(self.filesystem.dirname(new_filepath))
     290
     291                if not self.options.overwrite and self.filesystem.exists(new_filepath):
    294292                    _log.info('Skipping import of existing file ' + new_filepath)
    295293                else:
     
    312310
    313311                    if not converted_file:
    314                         shutil.copyfile(orig_filepath, new_filepath)  # The file was unmodified.
     312                        self.filesystem.copyfile(orig_filepath, new_filepath)  # The file was unmodified.
    315313                    else:
    316314                        for prefixed_property in converted_file[0]:
     
    331329                    self.filesystem.write_text_file(new_filepath, '# This file is required for Python to search this directory for modules.')
    332330                else:
    333                     shutil.copyfile(orig_filepath, new_filepath)
     331                    self.filesystem.copyfile(orig_filepath, new_filepath)
    334332
    335333                copied_files.append(new_filepath.replace(self._webkit_root, ''))
     
    362360        previous_file_list = []
    363361
    364         import_log_file = os.path.join(import_directory, 'w3c-import.log')
    365         if not os.path.exists(import_log_file):
     362        import_log_file = self.filesystem.join(import_directory, 'w3c-import.log')
     363        if not self.filesystem.exists(import_log_file):
    366364            return
    367365
     
    375373        for deleted_file in deleted_files:
    376374            _log.info('Deleting file removed from the W3C repo: %s', deleted_file)
    377             deleted_file = os.path.join(self._webkit_root, deleted_file)
    378             os.remove(deleted_file)
     375            deleted_file = self.filesystem.join(self._webkit_root, deleted_file)
     376            self.filesystem.remove(deleted_file)
    379377
    380378    def write_import_log(self, import_directory, file_list, prop_list, property_values_list):
Note: See TracChangeset for help on using the changeset viewer.