Skip to content

Commit

Permalink
devtools update-license: applied change requests
Browse files Browse the repository at this point in the history
  • Loading branch information
joergsteffens authored and BareosBot committed May 17, 2024
1 parent a3eac86 commit b0af62b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
6 changes: 5 additions & 1 deletion devtools/pip-tools/license_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 202-2024 Bareos GmbH & Co. KG
# 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
Expand All @@ -17,4 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

"""
license util module.
"""

from .update_license import generate_license_file
22 changes: 18 additions & 4 deletions devtools/pip-tools/license_utils/update_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

"""
Create a license file from a license template.
The format of the license file is according to
https://www.debian.org/doc/packaging-manuals/copyright-format/
"""

from argparse import ArgumentParser
from datetime import date
from os.path import dirname, curdir
import re
from sys import stdout, stderr
import sys


def parse_cmdline_args():
Expand All @@ -44,6 +50,10 @@ def parse_cmdline_args():


def get_include_file_content(path, indent=" "):
"""Reads a file a transforms it as section
in Debian packaging copyright-format
(indented and empty lines replaced by ".").
"""
emptyline = re.compile(r"^\s*$")
content = ""
with open(path, "r", encoding="utf-8") as file:
Expand All @@ -61,6 +71,10 @@ def get_file_content(filename):


def get_translations(template_filename):
"""Reads the template file,
replaces the variables
and returns the resulting text.
"""
base_dir = dirname(template_filename)
translations = {
"year": date.today().year,
Expand All @@ -78,7 +92,7 @@ def generate_license_file(template_filename, 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))
sys.stdout.write(template.format_map(translations))


def main():
Expand All @@ -97,10 +111,10 @@ def main():
try:
generate_license_file(template_filename, target_filename)
except FileNotFoundError:
print(f"Could not find file {template_filename}", file=stderr)
print(f"Could not find file {template_filename}", file=sys.stderr)
return 2
return 0


if __name__ == "__main__":
exit(main())
sys.exit(main())
10 changes: 5 additions & 5 deletions devtools/pip-tools/pr_tool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,11 @@ def main():
return 1
return 2

if args.subcommand == "update-license":
if update_license_file(repo) not in [None, True]:
return 1
return 0

pr_data = get_current_pr_data()
pr_data["_repo"] = repo
pr_data["_base_branch"] = "{}/{}".format(git_remote, pr_data["baseRefName"])
Expand Down Expand Up @@ -775,11 +780,6 @@ def main():
ret = False

handle_ret(ret)
elif args.subcommand == "update-license":
if update_license_file(repo) in [None, True]:
exit(0)
else:
exit(1)
elif args.subcommand == "add-changelog":
if check_changelog_entry(repo, pr_data):
print("Already have Changelog for this PR")
Expand Down
2 changes: 1 addition & 1 deletion devtools/pip-tools/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2020-2022 Bareos GmbH & Co. KG
# Copyright (C) 2020-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
Expand Down

0 comments on commit b0af62b

Please sign in to comment.