2020-09-17 20:55:15 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
2021-04-09 18:35:47 +02:00
|
|
|
import re
|
2020-09-17 20:55:15 +02:00
|
|
|
import sys
|
|
|
|
|
|
|
|
apache = r"""
|
|
|
|
/****************************************************************************
|
|
|
|
* PATH
|
|
|
|
*
|
2024-09-10 14:15:58 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2020-09-17 20:55:15 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/"""
|
|
|
|
|
2021-04-05 02:09:12 +02:00
|
|
|
|
2020-09-17 20:55:15 +02:00
|
|
|
def apachize(path, header):
|
2021-04-05 02:09:12 +02:00
|
|
|
relpath = os.path.relpath(path, os.environ["TOPDIR"])
|
|
|
|
header = re.sub("PATH", relpath, header)
|
2020-09-17 20:55:15 +02:00
|
|
|
|
|
|
|
with open(path) as f:
|
|
|
|
s = f.read()
|
2021-04-05 02:09:12 +02:00
|
|
|
s = re.sub("(?i)/\*\*\*.+?(?:Copyright).+?\*\*\*+/", header, s, 1, re.DOTALL)
|
2020-09-17 20:55:15 +02:00
|
|
|
print(s)
|
|
|
|
|
2021-04-05 02:09:12 +02:00
|
|
|
|
|
|
|
if len(sys.argv) != 2:
|
|
|
|
print("Usage: ./apachize.py <file>", file=sys.stderr)
|
|
|
|
print(
|
|
|
|
"This will replace the license header of the passed file to that of Apache 2.0 and print it to stdout",
|
2021-04-09 18:35:47 +02:00
|
|
|
file=sys.stderr,
|
2021-04-05 02:09:12 +02:00
|
|
|
)
|
2020-09-17 20:55:15 +02:00
|
|
|
sys.exit(2)
|
|
|
|
|
2021-04-09 18:35:47 +02:00
|
|
|
if "TOPDIR" not in os.environ:
|
2021-04-05 02:09:12 +02:00
|
|
|
print(
|
|
|
|
"Please define the TOPDIR environment variable to the full path to nuttx/ root",
|
|
|
|
file=sys.stderr,
|
|
|
|
)
|
2020-09-17 20:55:15 +02:00
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
apachize(sys.argv[1], apache)
|