Skip to content

Commit

Permalink
Merge pull request #1773
Browse files Browse the repository at this point in the history
pr-tool: update LICENSE.txt
  • Loading branch information
BareosBot committed May 17, 2024
2 parents 92a44c7 + f6bee17 commit 23b19e6
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 55 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- replace https://bugs.bareos.org by https://github.com/bareos/bareos/issues/ [PR #1808]
- tools: remove perl in mtx changer [PR #1740]
- bsmtp: add fixes to be more rfc compliant [PR #1795]
- pr-tool: update LICENSE.txt [PR #1773]

### Removed
- plugins: remove old deprecated postgres plugin [PR #1606]
Expand Down Expand Up @@ -161,6 +162,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[PR #1765]: https://github.com/bareos/bareos/pull/1765
[PR #1767]: https://github.com/bareos/bareos/pull/1767
[PR #1772]: https://github.com/bareos/bareos/pull/1772
[PR #1773]: https://github.com/bareos/bareos/pull/1773
[PR #1786]: https://github.com/bareos/bareos/pull/1786
[PR #1788]: https://github.com/bareos/bareos/pull/1788
[PR #1795]: https://github.com/bareos/bareos/pull/1795
Expand Down
1 change: 1 addition & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,7 @@ License: Bareos
.
===========================================


Files: core/src/lib/bmtio.h
Copyright: 1982,1986,1993 The Regents of the University of California
License: permissive
Expand Down
24 changes: 24 additions & 0 deletions devtools/pip-tools/license_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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.

"""
license util module.
"""

from .update_license import LICENSE_FILENAME, LICENSE_TEMPLATE, generate_license_file
125 changes: 125 additions & 0 deletions devtools/pip-tools/license_utils/update_license.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/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.

"""
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
import os
import re
import sys

from git import Repo

LICENSE_FILENAME = "LICENSE.txt"
LICENSE_TEMPLATE = "devtools/template/LICENSE.txt"


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=" "):
"""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:
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):
"""Reads the template file,
replaces the variables
and returns the resulting text.
"""
base_dir = Repo(template_filename, search_parent_directories=True).working_dir
translations = {
"year": date.today().year,
}
translations['include("core/LICENSE")'] = get_include_file_content(
os.path.join(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:
sys.stdout.write(template.format_map(translations))


def main():
args = parse_cmdline_args()

if "/" in args.template:
template_filename = args.template
else:
template_filename = f"{os.path.curdir}/{args.template}"

if args.out == "-" or "/" in args.out:
target_filename = args.out
else:
target_filename = f"{os.path.curdir}/{args.out}"

try:
generate_license_file(template_filename, target_filename)
except FileNotFoundError:
print(f"Could not find file {template_filename}", file=sys.stderr)
return 2
return 0


if __name__ == "__main__":
sys.exit(main())
46 changes: 43 additions & 3 deletions devtools/pip-tools/pr_tool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import re

from argparse import ArgumentParser, Namespace, ArgumentTypeError
from os import environ, chdir
from os import environ, chdir, path
from pprint import pprint
from sys import stdout, stderr
from time import sleep
Expand All @@ -38,6 +38,7 @@
update_links,
guess_section,
)
from license_utils import LICENSE_FILENAME, LICENSE_TEMPLATE, generate_license_file

from check_sources.main import main_program as check_sources
from . import backport
Expand Down Expand Up @@ -173,11 +174,15 @@ def check_commit(self, commit):
issues.extend(self._check_headline(headline))
issues.extend(self._check_body("\n".join(messageBody)))

if LICENSE_FILENAME in commit.stats.files:
issues.append(
f"don't modify '{LICENSE_FILENAME}'. Make changes to '{LICENSE_FILENAME}' instead"
)

if len(issues) > 0:
self._record_issues(commit, headline, issues)
return False
else:
return True
return True

@classmethod
def _check_headline(cls, text):
Expand Down Expand Up @@ -348,6 +353,28 @@ def get_plain_label_list(label_list):
return [x["name"].lower() for x in label_list]


def get_git_file_modified(repo, path):
for item in repo.index.diff(None):
if path == item.b_path:
return True
return False


def update_license_file(repo):
"""Update license file from template."""
license_file_path = f"{repo.working_tree_dir}/{LICENSE_FILENAME}"
license_template_path = f"{repo.working_tree_dir}/{LICENSE_TEMPLATE}"
if not path.isfile(license_template_path):
print(f"skipped, template file '{LICENSE_TEMPLATE}' not found.")
return None
generate_license_file(license_template_path, license_file_path)
if get_git_file_modified(repo, LICENSE_FILENAME):
print(f"Updating {LICENSE_FILENAME}")
repo.git.commit("-m", f"Update {LICENSE_FILENAME}", LICENSE_FILENAME)
return True
return None


def get_changelog_section(pr):
labels = get_plain_label_list(pr["labels"])
if "documentation" in labels:
Expand Down Expand Up @@ -411,6 +438,7 @@ def parse_cmdline_args():
help="ignore (required) github status checks",
)
changelog_parser = subparsers.add_parser("add-changelog")
license_parser = subparsers.add_parser("update-license")
merge_parser = subparsers.add_parser("merge")
merge_parser.add_argument(
"--skip-merge",
Expand Down Expand Up @@ -509,12 +537,18 @@ def merge_pr(

original_commit = repo.head.commit
try:
git_modified = False
if update_license_file(repo):
git_modified = True
if check_changelog_entry(repo, pr):
print("Keeping existing changelog entry.")
else:
print("Adding changelog entry")
if not add_changelog_entry(repo, pr):
raise Exception("Adding changelog failed")
git_modified = True

if git_modified:
repo.git.push()

if check_merge_is_possible(repo, pr):
Expand Down Expand Up @@ -542,6 +576,7 @@ def merge_pr(
repo.git.rebase("--abort")
raise e

update_license_file(repo)
print("Adding changelog entry again")
if not add_changelog_entry(repo, pr):
raise Exception("Adding changelog failed")
Expand Down Expand Up @@ -698,6 +733,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
3 changes: 2 additions & 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 Expand Up @@ -34,6 +34,7 @@
"pr-tool=pr_tool.main:main",
"update-changelog-links=changelog_utils.update_links:main",
"add-changelog-entry=changelog_utils.add_entry:main",
"update-license=license_utils.update_license:main",
]
},
)
6 changes: 3 additions & 3 deletions LICENSE.template → devtools/template/LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ Comment: BAREOS is a fork of the Bacula source code.


Files: *
Copyright: 2012-${YEAR} Bareos GmbH & Co. KG
Copyright: 2012-{year} Bareos GmbH & Co. KG
License: AGPL-3.0-only


Files: core/* docs/manuals/source/*
Copyright: 2000-2012 Free Software Foundation Europe e.V.
2010-2017 Planets Communications B.V.
2012-${YEAR} Bareos GmbH & Co. KG
2012-{year} Bareos GmbH & Co. KG
License: Bareos
This is basically AGPL-3.0 with Bacula and other exceptions.
This section is the reformatted version of
https://github.com/bareos/bareos/blob/master/core/LICENSE
.
@include("core/LICENSE")
{include("core/LICENSE")}

Files: core/src/lib/bmtio.h
Copyright: 1982,1986,1993 The Regents of the University of California
Expand Down
47 changes: 0 additions & 47 deletions devtools/update-license-file.sh

This file was deleted.

3 changes: 2 additions & 1 deletion third-party/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Each Library will be put into its own subdirectory with `git subtree` and will h
A typical git subtree command would look like this : `git subtree add --prefix destination/path https://www.yourgithost.com/your/repo yourbranch(usuallymaster) --squash`

Make sure the library license is covert by `LICENSE.txt`. At best, the library is also licensed as AGPL-3. If it is not already covered, a section needs to be added for it in `LICENSE.template`.
Also execute `devtools/update-license-file.sh` to update `LICENSE.txt`, and commit new version.
Executing `pr-tool update-license` will renew the `LICENSE.txt` file.
This will also happen automatically when merging the PR.

### What to add?

Expand Down

0 comments on commit 23b19e6

Please sign in to comment.