Skip to content

Instantly share code, notes, and snippets.

@Hexcles
Created July 20, 2017 21:28
Show Gist options
  • Save Hexcles/ce7110a8d07bf81378e254914ae8cbb2 to your computer and use it in GitHub Desktop.
Save Hexcles/ce7110a8d07bf81378e254914ae8cbb2 to your computer and use it in GitHub Desktop.
[chromium] Convert W3CImportExpectations to OWNERS files
#!/usr/bin/env vpython
# To be placed in and run from //src/third_party/WebKit/Tools/Scripts/
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import re
from webkitpy.common.path_finder import PathFinder
from webkitpy.common.system.filesystem import FileSystem
class DirectoryOwnersConverter(object):
def __init__(self):
self.filesystem = FileSystem()
self.finder = PathFinder(self.filesystem)
def convert(self):
input_path = self.finder.path_from_layout_tests('W3CImportExpectations')
input_contents = self.filesystem.read_text_file(input_path)
self.process_lines(input_contents.splitlines())
def process_lines(self, lines):
"""Returns a dict mapping directories to owners.
Args:
lines: Lines in W3CImportExpectations.
"""
current_owners = []
for line in lines:
owners = self.extract_owners(line)
if owners:
current_owners = owners
directory = self.extract_directory(line)
if not owners and not directory:
current_owners = []
if current_owners and directory:
self.write_owners(current_owners, directory)
def write_owners(self, owners, directory):
print "%s >> %s/OWNERS" % (','.join(owners), directory)
owners_file = self.filesystem.join(self.finder.path_from_layout_tests(directory), 'OWNERS')
#print owners_file
with open(owners_file, 'a') as f:
f.write('\n'.join(owners) + '\n')
@staticmethod
def extract_owners(line):
"""Extracts owner email addresses listed on a line."""
match = re.match(r'##? Owners?: (?P<addresses>.*)', line)
if not match or not match.group('addresses'):
return None
email_part = match.group('addresses')
addresses = [email_part] if ',' not in email_part else re.split(r',\s*', email_part)
addresses = [s for s in addresses if re.match(r'\S+@\S+', s)]
return addresses or None
@staticmethod
def extract_directory(line):
"""Extracts the directory substring for an enabled directory."""
match = re.match(r'# ?(?P<directory>\S+) \[ (Pass|Skip) \]', line)
if match and match.group('directory'):
return match.group('directory')
match = re.match(r'(?P<directory>\S+) \[ Pass \]', line)
if match and match.group('directory'):
return match.group('directory')
return None
def main():
converter = DirectoryOwnersConverter()
converter.convert()
if __name__ == '__main__':
main()
// Copyright 2015 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment