-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devtools: add update-license (sub-)command
Add update-license subcommand to the pr-tool. It will be called automatically when merging a PR.
- Loading branch information
1 parent
92a44c7
commit a3eac86
Showing
8 changed files
with
171 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# BAREOS® - Backup Archiving REcovery Open Sourced | ||
# | ||
# Copyright (C) 202-2024 Bareos GmbH & Co. KG | ||
# | ||
# This program is Free Software; you can redistribute it and/or | ||
# modify it under the terms of version three of the GNU Affero General Public | ||
# License as published by the Free Software Foundation and included | ||
# in the file LICENSE. | ||
# | ||
# This program is distributed in the hope that it will be useful, but | ||
# WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
# 02110-1301, USA. | ||
|
||
from .update_license import generate_license_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# BAREOS® - Backup Archiving REcovery Open Sourced | ||
# | ||
# Copyright (C) 2024-2024 Bareos GmbH & Co. KG | ||
# | ||
# This program is Free Software; you can redistribute it and/or | ||
# modify it under the terms of version three of the GNU Affero General Public | ||
# License as published by the Free Software Foundation and included | ||
# in the file LICENSE. | ||
# | ||
# This program is distributed in the hope that it will be useful, but | ||
# WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
# 02110-1301, USA. | ||
|
||
from argparse import ArgumentParser | ||
from datetime import date | ||
from os.path import dirname, curdir | ||
import re | ||
from sys import stdout, stderr | ||
|
||
|
||
def parse_cmdline_args(): | ||
parser = ArgumentParser() | ||
parser.add_argument( | ||
"--template", | ||
"-t", | ||
default="LICENSE.template", | ||
help="License file template. Default: %(default)s", | ||
) | ||
parser.add_argument( | ||
"--out", | ||
"-o", | ||
default="-", | ||
help="Target file name. Default: stdout", | ||
) | ||
return parser.parse_args() | ||
|
||
|
||
def get_include_file_content(path, indent=" "): | ||
emptyline = re.compile(r"^\s*$") | ||
content = "" | ||
with open(path, "r", encoding="utf-8") as file: | ||
for line in file: | ||
if emptyline.fullmatch(line): | ||
line = ".\n" | ||
content += indent + line | ||
return content | ||
|
||
|
||
def get_file_content(filename): | ||
with open(filename, "r", encoding="utf-8") as file: | ||
content = file.read() | ||
return content | ||
|
||
|
||
def get_translations(template_filename): | ||
base_dir = dirname(template_filename) | ||
translations = { | ||
"year": date.today().year, | ||
} | ||
translations['include("core/LICENSE")'] = get_include_file_content( | ||
f"{base_dir}/core/LICENSE" | ||
) | ||
return translations | ||
|
||
|
||
def generate_license_file(template_filename, target_filename): | ||
template = get_file_content(template_filename) | ||
translations = get_translations(template_filename) | ||
if target_filename != "-": | ||
with open(target_filename, "w", encoding="utf-8") as file: | ||
file.write(template.format_map(translations)) | ||
else: | ||
stdout.write(template.format_map(translations)) | ||
|
||
|
||
def main(): | ||
args = parse_cmdline_args() | ||
|
||
if "/" in args.template: | ||
template_filename = args.template | ||
else: | ||
template_filename = f"{curdir}/{args.template}" | ||
|
||
if args.out == "-" or "/" in args.out: | ||
target_filename = args.out | ||
else: | ||
target_filename = f"{curdir}/{args.out}" | ||
|
||
try: | ||
generate_license_file(template_filename, target_filename) | ||
except FileNotFoundError: | ||
print(f"Could not find file {template_filename}", file=stderr) | ||
return 2 | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters