2024-01-29 10:00:22 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
import glob
|
|
|
|
|
import os
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
2025-05-17 08:26:02 -04:00
|
|
|
|
2024-01-29 10:00:22 -05:00
|
|
|
class Copyright:
|
|
|
|
|
NOTICE = """Licensed to the Software Freedom Conservancy (SFC) under one
|
|
|
|
|
or more contributor license agreements. See the NOTICE file
|
|
|
|
|
distributed with this work for additional information
|
|
|
|
|
regarding copyright ownership. The SFC licenses this file
|
|
|
|
|
to you under the Apache License, Version 2.0 (the
|
|
|
|
|
"License"); you may not use this file except in compliance
|
|
|
|
|
with the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing,
|
|
|
|
|
software distributed under the License is distributed on an
|
|
|
|
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
KIND, either express or implied. See the License for the
|
|
|
|
|
specific language governing permissions and limitations
|
|
|
|
|
under the License."""
|
|
|
|
|
|
2025-05-17 08:26:02 -04:00
|
|
|
def __init__(self, comment_characters="//", prefix=None):
|
2024-01-29 10:00:22 -05:00
|
|
|
self._comment_characters = comment_characters
|
|
|
|
|
self._prefix = prefix or []
|
|
|
|
|
|
|
|
|
|
def update(self, files):
|
|
|
|
|
for file in files:
|
2025-05-17 08:26:02 -04:00
|
|
|
with open(file, "r", encoding="utf-8-sig") as f:
|
2024-01-29 10:00:22 -05:00
|
|
|
lines = f.readlines()
|
|
|
|
|
|
|
|
|
|
index = -1
|
|
|
|
|
for i, line in enumerate(lines):
|
2025-05-17 08:26:02 -04:00
|
|
|
if line.startswith(
|
|
|
|
|
self._comment_characters
|
|
|
|
|
) or self.valid_copyright_notice_line(line, index, file):
|
2024-01-29 10:00:22 -05:00
|
|
|
index += 1
|
|
|
|
|
else:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
if index == -1:
|
|
|
|
|
self.write_update_notice(file, lines)
|
|
|
|
|
else:
|
2025-05-17 08:26:02 -04:00
|
|
|
current = "".join(lines[: index + 1])
|
2024-11-07 14:43:49 -08:00
|
|
|
if current != self.copyright_notice(file):
|
2025-05-17 08:26:02 -04:00
|
|
|
self.write_update_notice(file, lines[index + 1 :])
|
2024-01-29 10:00:22 -05:00
|
|
|
|
2024-11-07 14:43:49 -08:00
|
|
|
def valid_copyright_notice_line(self, line, index, file):
|
2025-05-17 08:26:02 -04:00
|
|
|
return index + 1 < len(self.copyright_notice_lines(file)) and line.startswith(
|
|
|
|
|
self.copyright_notice_lines(file)[index + 1]
|
|
|
|
|
)
|
2024-01-29 10:00:22 -05:00
|
|
|
|
2024-11-07 14:43:49 -08:00
|
|
|
def copyright_notice(self, file):
|
2025-05-17 08:26:02 -04:00
|
|
|
return "".join(self.copyright_notice_lines(file))
|
2024-01-29 10:00:22 -05:00
|
|
|
|
2024-11-07 14:43:49 -08:00
|
|
|
def copyright_notice_lines(self, file):
|
2025-05-17 08:26:02 -04:00
|
|
|
return (
|
|
|
|
|
self.dotnet(file)
|
|
|
|
|
if file.endswith("cs")
|
|
|
|
|
else self._prefix + self.commented_notice_lines
|
|
|
|
|
)
|
2024-11-07 14:43:49 -08:00
|
|
|
|
|
|
|
|
def dotnet(self, file):
|
|
|
|
|
file_name = os.path.basename(file)
|
2025-05-17 08:26:02 -04:00
|
|
|
first = f'{self._comment_characters} <copyright file="{file_name}" company="Selenium Committers">\n'
|
2024-11-07 14:43:49 -08:00
|
|
|
last = f"{self._comment_characters} </copyright>"
|
|
|
|
|
return [first] + self.commented_notice_lines + [last]
|
2024-01-29 10:00:22 -05:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def commented_notice_lines(self):
|
2025-05-17 08:26:02 -04:00
|
|
|
return [
|
|
|
|
|
f"{self._comment_characters} {line}".rstrip() + "\n"
|
|
|
|
|
for line in self.NOTICE.split("\n")
|
|
|
|
|
]
|
2024-01-29 10:00:22 -05:00
|
|
|
|
|
|
|
|
def write_update_notice(self, file, lines):
|
|
|
|
|
print(f"Adding notice to {file}")
|
2025-05-17 08:26:02 -04:00
|
|
|
with open(file, "w") as f:
|
2024-11-07 14:43:49 -08:00
|
|
|
f.write(self.copyright_notice(file) + "\n")
|
|
|
|
|
if lines and lines[0] != "\n":
|
|
|
|
|
f.write("\n")
|
|
|
|
|
trimmed_lines = [line.rstrip() + "\n" for line in lines]
|
|
|
|
|
f.writelines(trimmed_lines)
|
2024-01-29 10:00:22 -05:00
|
|
|
|
2025-05-17 08:26:02 -04:00
|
|
|
|
2024-01-29 10:00:22 -05:00
|
|
|
ROOT = Path(os.path.realpath(__file__)).parent.parent
|
|
|
|
|
|
|
|
|
|
JS_EXCLUSIONS = [
|
|
|
|
|
f"{ROOT}/javascript/atoms/test/jquery.min.js",
|
|
|
|
|
f"{ROOT}/javascript/jsunit/**/*.js",
|
2025-03-25 14:28:37 +01:00
|
|
|
f"{ROOT}/javascript/selenium-webdriver/node_modules/**/*.js",
|
2024-01-29 10:00:22 -05:00
|
|
|
f"{ROOT}/javascript/selenium-core/lib/**/*.js",
|
|
|
|
|
f"{ROOT}/javascript/selenium-core/scripts/ui-element.js",
|
|
|
|
|
f"{ROOT}/javascript/selenium-core/scripts/ui-map-sample.js",
|
|
|
|
|
f"{ROOT}/javascript/selenium-core/scripts/user-extensions.js",
|
|
|
|
|
f"{ROOT}/javascript/selenium-core/scripts/xmlextras.js",
|
|
|
|
|
f"{ROOT}/javascript/selenium-core/xpath/**/*.js",
|
2025-05-17 08:26:02 -04:00
|
|
|
f"{ROOT}/javascript/grid-ui/node_modules/**/*.js",
|
2025-06-28 23:44:16 +02:00
|
|
|
f"{ROOT}/javascript/node/selenium-webdriver/node_modules/**/*.js",
|
2024-01-29 10:00:22 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
PY_EXCLUSIONS = [
|
|
|
|
|
f"{ROOT}/py/selenium/webdriver/common/bidi/cdp.py",
|
|
|
|
|
f"{ROOT}/py/generate.py",
|
|
|
|
|
f"{ROOT}/py/selenium/webdriver/common/devtools/**/*",
|
2025-05-17 08:26:02 -04:00
|
|
|
f"{ROOT}/py/venv/**/*",
|
2024-01-29 10:00:22 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2025-05-17 08:26:02 -04:00
|
|
|
def update_files(file_pattern, exclusions, comment_characters="//", prefix=None):
|
2024-01-29 10:00:22 -05:00
|
|
|
included = set(glob.glob(file_pattern, recursive=True))
|
|
|
|
|
excluded = set()
|
|
|
|
|
for pattern in exclusions:
|
|
|
|
|
excluded.update(glob.glob(pattern, recursive=True))
|
|
|
|
|
files = included - excluded
|
|
|
|
|
|
|
|
|
|
copyright = Copyright(comment_characters, prefix)
|
|
|
|
|
copyright.update(files)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
update_files(f"{ROOT}/javascript/**/*.js", JS_EXCLUSIONS)
|
|
|
|
|
update_files(f"{ROOT}/javascript/**/*.tsx", [])
|
|
|
|
|
update_files(f"{ROOT}/py/**/*.py", PY_EXCLUSIONS, comment_characters="#")
|
2025-05-17 08:26:02 -04:00
|
|
|
update_files(
|
|
|
|
|
f"{ROOT}/rb/**/*.rb",
|
|
|
|
|
[],
|
|
|
|
|
comment_characters="#",
|
|
|
|
|
prefix=["# frozen_string_literal: true\n", "\n"],
|
|
|
|
|
)
|
2024-01-29 10:00:22 -05:00
|
|
|
update_files(f"{ROOT}/java/**/*.java", [])
|
|
|
|
|
update_files(f"{ROOT}/rust/**/*.rs", [])
|
2024-11-07 14:43:49 -08:00
|
|
|
update_files(f"{ROOT}/dotnet/**/*.cs", [])
|