diff --git a/README b/README --- a/README +++ b/README @@ -4,7 +4,7 @@ * add-appstream-versions/add-versions.py Run this first to add the new release version to the appstream files in your repos - * add-bugzilla-versions/add-versions.py + * add_bugzilla_versions.sh Run this to add the new release version to the bugs.kde.org versions * config diff --git a/add-bugzilla-versions/README.rst b/add-bugzilla-versions/README.rst deleted file mode 100644 --- a/add-bugzilla-versions/README.rst +++ /dev/null @@ -1,32 +0,0 @@ -Adds new project versions to the KDE Bugtracking System. - -The script does the following: - -#. For each project listed in :code:`add-bugzilla-versions/../modules.git`. - - #. Use CMake to determine the project version, as defined by CMake’s project_ - command. - - .. _project: https://cmake.org/cmake/help/latest/command/project.html#command:project - - If the variable is not found, the project is skipped. - - #. Add the variable to the target project in the KDE Bugtracking System. - -To run the script: - -#. Create, enter and prepare a Python virtual environment:: - - python3 -m venv venv - . venv/bin/activate - pip install -r requirements.txt - -#. Run the script:: - - python3 add-versions.py \ - -s \ - -e \ - -p - - .. note:: If you skip a parameter, the script prompts you for it on the - command line. diff --git a/add-bugzilla-versions/requirements.txt b/add-bugzilla-versions/requirements.txt deleted file mode 100644 --- a/add-bugzilla-versions/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -beautifulsoup4==4.6.0 -click==6.7 -GitPython==2.1.14 -requests==2.18.2 diff --git a/add_bugzilla_versions.sh b/add_bugzilla_versions.sh new file mode 100755 --- /dev/null +++ b/add_bugzilla_versions.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +"$(dirname "$(readlink -f $0)")/tools/python-kde-release/run.sh" add-bugzilla-versions $* diff --git a/add-bugzilla-versions/.gitignore b/tools/python-kde-release/.gitignore rename from add-bugzilla-versions/.gitignore rename to tools/python-kde-release/.gitignore diff --git a/tools/python-kde-release/kde_release/__init__.py b/tools/python-kde-release/kde_release/__init__.py new file mode 100644 diff --git a/add-bugzilla-versions/add-versions.py b/tools/python-kde-release/kde_release/cli.py old mode 100755 new mode 100644 rename from add-bugzilla-versions/add-versions.py rename to tools/python-kde-release/kde_release/cli.py --- a/add-bugzilla-versions/add-versions.py +++ b/tools/python-kde-release/kde_release/cli.py @@ -1,7 +1,5 @@ -#!/usr/bin/env python3 - -# Copyright 2015 Jonathan Riddell -# Copyright 2017 Adrian Chaves +# Copyright 2015 Jonathan Riddell +# Copyright 2017, 2019 Adrian Chaves # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -16,12 +14,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import sys -sys.path.append("..") - import os -from pathlib import Path import re +from os import environ +from pathlib import Path from shutil import rmtree from subprocess import run, DEVNULL, PIPE from tempfile import mkdtemp @@ -32,11 +28,11 @@ from git.exc import InvalidGitRepositoryError, NoSuchPathError from requests import RequestException, Session -import add_versions_lib - URL = 'https://bugs.kde.org' EDIT_VERSION_URL = '{}/editversions.cgi'.format(URL) +VERSION_RE = re.compile(r'(?i):\s+project\s*\(\s*\S+\s+' + r'VERSION\s+(\d+(?:\.\d+(?:\.\d+(?:\.\d+)?)?)?)') def response_error(response): @@ -63,6 +59,35 @@ exit(1) +def products_and_branches(): + modules_path = Path(environ['KDE_RELEASE_DIR']) / 'modules.git' + with modules_path.open() as modules_file: + for line in modules_file: + match = re.match(r'^(\S+)\s+(\S+)$', line) + if match: + yield match.group(1), match.group(2) + + +def cmake_trace(folder): + temp_folder = mkdtemp() + try: + cmake_command = ['cmake', '--trace-expand', folder] + execution = run( + cmake_command, cwd=temp_folder, stdout=DEVNULL, stderr=PIPE) + return execution.stderr.decode(errors='ignore') + finally: + rmtree(temp_folder) + + +def project_version(source_folder): + match = None + for match in VERSION_RE.finditer(cmake_trace(source_folder)): + pass + if not match: + return None + return match.group(1) + + def bugzilla_csrf_token(session, product): params = {'action': 'add', 'product': product} response = session.get(EDIT_VERSION_URL, params=params) @@ -97,7 +122,7 @@ @command() @option('-s', '--srcdir', prompt='Source folder', help='Folder containing local clones of the Git repositories from ' - '../modules.git') + 'modules.git') @option('-e', '--email', help='Email of your Bugzilla account') @option('-p', '--password', help='Password of your Bugzilla account') @@ -110,7 +135,17 @@ help='Clone missing Git folders.') @option('--hide-skipped', is_flag=True, help='Do not print lines for skipped products') -def main(srcdir, email, password, verbose, dry, clone, hide_skipped): +def add_bugzilla_versions(srcdir, email, password, verbose, dry, clone, + hide_skipped): + """Adds new project versions to the KDE Bugtracking System. + + Speficically, for each project listed in modules.git: + + 1. CMake is used to determine the project version, as defined by CMake’s + project command. If the version is not found, the project is skipped. + + 2. A version is added to the target project in the KDE Bugtracking System. + """ if not dry: if email is None: email = prompt('Email') @@ -207,7 +242,3 @@ except RuntimeError as error: echo('ERROR: {}'.format(error)) exit(1) - - -if __name__ == '__main__': - main() diff --git a/tools/python-kde-release/run.sh b/tools/python-kde-release/run.sh new file mode 100755 --- /dev/null +++ b/tools/python-kde-release/run.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +function finish { + deactivate &> /dev/null +} +trap finish EXIT + +deactivate &> /dev/null +dir="$(dirname "$(readlink -f $0)")" +[ ! -d "$DIR" ] && python3 -m venv "$dir/venv" +. "$dir/venv/bin/activate" +pip install --upgrade "$dir" &> /dev/null + +KDE_RELEASE_DIR="$(dirname "$(dirname "$dir")")" "$1" "${@:2}" diff --git a/tools/python-kde-release/setup.py b/tools/python-kde-release/setup.py new file mode 100644 --- /dev/null +++ b/tools/python-kde-release/setup.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +from setuptools import find_packages, setup + + +setup( + name='kde-release', + version='1.0', + description='Utilities of the KDE Release team', + packages=find_packages(), + python_requires='>=3.6', + install_requires=[ + 'beautifulsoup4 >=4.6.0, <5', + 'click >=6.7, <7', + 'GitPython >=2.1.14, <3', + 'requests >=2.18.2, <3', + ], + entry_points={ + 'console_scripts': [ + 'add-bugzilla-versions = kde_release.cli:add_bugzilla_versions', + ], + }, +)