From e6f70ef90d777724f48288a4dd90988036aaa8c2 Mon Sep 17 00:00:00 2001 From: Sundeep Anand Date: Mon, 27 Jun 2022 17:10:14 +0530 Subject: [PATCH 1/3] Extract package commands to a new group for adding new packages and showing stats, health etc. Update unit tests. --- tests/test_tscli.py | 22 +++++------ tscli/__init__.py | 3 +- tscli/packages/__init__.py | 0 tscli/packages/commands.py | 77 ++++++++++++++++++++++++++++++++++++++ tscli/stats/commands.py | 27 ------------- 5 files changed, 90 insertions(+), 39 deletions(-) create mode 100644 tscli/packages/__init__.py create mode 100644 tscli/packages/commands.py diff --git a/tests/test_tscli.py b/tests/test_tscli.py index af31a00..153ac63 100644 --- a/tests/test_tscli.py +++ b/tests/test_tscli.py @@ -60,7 +60,7 @@ def test_server_version(self): def test_package_status(self): """ - transtats package + transtats package stats """ from tscli import entry_point @@ -68,7 +68,7 @@ def test_package_status(self): mock_request_get.return_value = \ test_data.mock_package_status() runner = CliRunner() - result = runner.invoke(entry_point, ['package', 'systemd']) + result = runner.invoke(entry_point, ['package', 'stats', 'systemd']) self.assertEqual(result.exit_code, 0) self.assertIn('systemd', result.output) self.assertIn('Branch', result.output) @@ -76,7 +76,7 @@ def test_package_status(self): def test_package_status_exist(self): """ - transtats package --exist + transtats package --exist stats """ from tscli import entry_point @@ -84,15 +84,15 @@ def test_package_status_exist(self): mock_request_get.return_value = \ test_data.mock_package_status_exist() runner = CliRunner() - result = runner.invoke(entry_point, ['package', '--exist', - '--json', 'gnome-shell']) + result = runner.invoke(entry_point, ['package', 'stats', '--exist', + 'gnome-shell', '--json']) self.assertEqual(result.exit_code, 0) self.assertIn('gnome-shell', result.output) self.assertIn('true', result.output) def test_package_status_health(self): """ - transtats package --health + transtats package --health stats """ from tscli import entry_point @@ -100,15 +100,15 @@ def test_package_status_health(self): mock_request_get.return_value = \ test_data.mock_package_status_health() runner = CliRunner() - result = runner.invoke(entry_point, ['package', '--health', - '--json', 'abrt']) + result = runner.invoke(entry_point, ['package', 'stats', '--health', + 'abrt', '--json']) self.assertEqual(result.exit_code, 0) self.assertIn('abrt', result.output) self.assertIn('fedora-30', result.output) def test_package_status_health_in_sync(self): """ - transtats package --health + transtats package --health stats """ from tscli import entry_point @@ -116,8 +116,8 @@ def test_package_status_health_in_sync(self): mock_request_get.return_value = \ test_data.mock_package_status_health_in_sync() runner = CliRunner() - result = runner.invoke(entry_point, ['package', '--health', - '--json', 'authconfig']) + result = runner.invoke(entry_point, ['package', 'stats', '--health', + 'authconfig', '--json']) self.assertEqual(result.exit_code, 0) self.assertIn('authconfig', result.output) self.assertIn('are in sync', result.output) diff --git a/tscli/__init__.py b/tscli/__init__.py index b9248d6..9aed4fa 100644 --- a/tscli/__init__.py +++ b/tscli/__init__.py @@ -20,6 +20,7 @@ from tscli.config import get_config, get_config_item from tscli.stats import commands as trans from tscli.jobs import commands as jobs +from tscli.packages import commands as pkgs APP_VERSION = "0.5.0" @@ -50,7 +51,7 @@ def entry_point(ctx): entry_point.add_command(common.version) -entry_point.add_command(trans.package) +entry_point.add_command(pkgs.package) entry_point.add_command(trans.release) entry_point.add_command(trans.coverage) entry_point.add_command(jobs.job) diff --git a/tscli/packages/__init__.py b/tscli/packages/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tscli/packages/commands.py b/tscli/packages/commands.py new file mode 100644 index 0000000..0c75c3f --- /dev/null +++ b/tscli/packages/commands.py @@ -0,0 +1,77 @@ +# Copyright 2018 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed 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. + +import click +from tscli.restapi import ConsumeAPIs +from tscli.textoutput import TextOutputAPIs + + +@click.group() +def package(): + """Package related operations""" + + +@package.command() +@click.option( + '--server-url', envvar='TRANSTATS_SERVER', help="Transtats Server URL") +@click.option( + '--token', envvar='TOKEN', help="Transtats API token") +@click.option("--upstream-url", is_flag=False, + help="source repository url like github or gitlab") +@click.option("--transplatform-slug", is_flag=False, + help="platform slug like WLTEFED for fedora weblate") +@click.option("--release-stream", is_flag=False, + help="product like fedora") +@click.option( + '--json', is_flag=True, envvar='JSON_OUTPUT', help="Print in JSON format") +@click.argument('package_name') +@click.pass_obj +def add(app_context, server_url, token, package_name, upstream_url, + transplatform_slug, release_stream, json): + """Add a package to Transtats server.""" + api_obj = ConsumeAPIs(server_url or app_context.server_url) if json \ + else TextOutputAPIs(server_url or app_context.server_url) + + response = api_obj.add_package(package_name, upstream_url, + transplatform_slug, release_stream) + if isinstance(response, dict): + app_context.print_r(response) + + +@package.command() +@click.option( + '--server-url', envvar='TRANSTATS_SERVER', help="Transtats Server URL") +@click.option("--exist", is_flag=True, + help="Determine if the package exist in Transtats or not.") +@click.option("--health", is_flag=True, + help="Get package health") +@click.option( + '--json', is_flag=True, envvar='JSON_OUTPUT', help="Print in JSON format") +@click.argument('package-name') +@click.pass_obj +def stats(app_context, server_url, package_name, exist, health, json): + """Translation status of a package. + e.g. transtats package anaconda """ + api_obj = ConsumeAPIs(server_url or app_context.server_url) if json \ + else TextOutputAPIs(server_url or app_context.server_url) + + if exist: + response = api_obj.package_status(package_name, exist=True, health=None) + elif health: + response = api_obj.package_status(package_name, exist=None, health=True) + else: + response = api_obj.package_status(package_name, exist=None, health=None) + if isinstance(response, dict): + app_context.print_r(response) diff --git a/tscli/stats/commands.py b/tscli/stats/commands.py index 04afa7f..25370ba 100644 --- a/tscli/stats/commands.py +++ b/tscli/stats/commands.py @@ -18,33 +18,6 @@ from tscli.textoutput import TextOutputAPIs -@click.command() -@click.option( - '--server-url', envvar='TRANSTATS_SERVER', help="Transtats Server URL") -@click.option("--exist", is_flag=True, - help="Determine if the package exist in Transtats or not.") -@click.option("--health", is_flag=True, - help="Get package health") -@click.option( - '--json', is_flag=True, envvar='JSON_OUTPUT', help="Print in JSON format") -@click.argument('package-name') -@click.pass_obj -def package(app_context, server_url, package_name, exist, health, json): - """Translation status of a package. - e.g. transtats package anaconda """ - api_obj = ConsumeAPIs(server_url or app_context.server_url) if json \ - else TextOutputAPIs(server_url or app_context.server_url) - - if exist: - response = api_obj.package_status(package_name, exist=True, health=None) - elif health: - response = api_obj.package_status(package_name, exist=None, health=True) - else: - response = api_obj.package_status(package_name, exist=None, health=None) - if isinstance(response, dict): - app_context.print_r(response) - - @click.command() @click.option( '--server-url', envvar='TRANSTATS_SERVER', help="Transtats Server URL") From 278ac5fadaf56498334190a0ef7537bc6bfe3c4f Mon Sep 17 00:00:00 2001 From: Sundeep Anand Date: Wed, 29 Jun 2022 16:05:43 +0530 Subject: [PATCH 2/3] Implement add package command --- tests/test_data.py | 12 ++++++++++++ tests/test_tscli.py | 38 +++++++++++++++++++++++++++++++------- tscli/packages/commands.py | 2 +- tscli/restapi.py | 18 ++++++++++++++++-- tscli/textoutput.py | 10 ++++++++++ 5 files changed, 70 insertions(+), 10 deletions(-) diff --git a/tests/test_data.py b/tests/test_data.py index b87b4e4..b14ac31 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -100,6 +100,18 @@ def mock_package_status_health_in_sync(): return mock_rep +def mock_package_add(): + """ + package_add mock value + """ + mock_rep = Mock() + mock_rep.ok = True + mock_rep.json.return_value = { + "abrt": "Package added Successfully." + } + return mock_rep + + def mock_coverage_rule(): """ rule_coverage mock value diff --git a/tests/test_tscli.py b/tests/test_tscli.py index 153ac63..4508da1 100644 --- a/tests/test_tscli.py +++ b/tests/test_tscli.py @@ -68,7 +68,7 @@ def test_package_status(self): mock_request_get.return_value = \ test_data.mock_package_status() runner = CliRunner() - result = runner.invoke(entry_point, ['package', 'stats', 'systemd']) + result = runner.invoke(entry_point, ['package', 'status', 'systemd']) self.assertEqual(result.exit_code, 0) self.assertIn('systemd', result.output) self.assertIn('Branch', result.output) @@ -76,7 +76,7 @@ def test_package_status(self): def test_package_status_exist(self): """ - transtats package --exist stats + transtats package stats --exist """ from tscli import entry_point @@ -84,7 +84,7 @@ def test_package_status_exist(self): mock_request_get.return_value = \ test_data.mock_package_status_exist() runner = CliRunner() - result = runner.invoke(entry_point, ['package', 'stats', '--exist', + result = runner.invoke(entry_point, ['package', 'status', '--exist', 'gnome-shell', '--json']) self.assertEqual(result.exit_code, 0) self.assertIn('gnome-shell', result.output) @@ -92,7 +92,7 @@ def test_package_status_exist(self): def test_package_status_health(self): """ - transtats package --health stats + transtats package stats --health """ from tscli import entry_point @@ -100,7 +100,7 @@ def test_package_status_health(self): mock_request_get.return_value = \ test_data.mock_package_status_health() runner = CliRunner() - result = runner.invoke(entry_point, ['package', 'stats', '--health', + result = runner.invoke(entry_point, ['package', 'status', '--health', 'abrt', '--json']) self.assertEqual(result.exit_code, 0) self.assertIn('abrt', result.output) @@ -108,7 +108,7 @@ def test_package_status_health(self): def test_package_status_health_in_sync(self): """ - transtats package --health stats + transtats package stats --health """ from tscli import entry_point @@ -116,12 +116,36 @@ def test_package_status_health_in_sync(self): mock_request_get.return_value = \ test_data.mock_package_status_health_in_sync() runner = CliRunner() - result = runner.invoke(entry_point, ['package', 'stats', '--health', + result = runner.invoke(entry_point, ['package', 'status', '--health', 'authconfig', '--json']) self.assertEqual(result.exit_code, 0) self.assertIn('authconfig', result.output) self.assertIn('are in sync', result.output) + def test_package_add(self): + """ + transtats package add + --upstream-url + --transplatform-slug + --release-stream + """ + from tscli import entry_point + + with patch('requests.post') as mock_request_post: + mock_request_post.return_value = \ + test_data.mock_package_add() + runner = CliRunner() + result = runner.invoke( + entry_point, ['package', 'add', 'abrt', + '--upstream-url', 'https://github.com/abrt/abrt', + '--transplatform-slug', 'WLTEFED', + '--release-stream', 'fedora', + '--json'] + ) + self.assertEqual(result.exit_code, 0) + self.assertIn('abrt', result.output) + self.assertIn('Package added Successfully', result.output) + def test_coverage_rule(self): """ transtats coverage diff --git a/tscli/packages/commands.py b/tscli/packages/commands.py index 0c75c3f..3ea1a13 100644 --- a/tscli/packages/commands.py +++ b/tscli/packages/commands.py @@ -61,7 +61,7 @@ def add(app_context, server_url, token, package_name, upstream_url, '--json', is_flag=True, envvar='JSON_OUTPUT', help="Print in JSON format") @click.argument('package-name') @click.pass_obj -def stats(app_context, server_url, package_name, exist, health, json): +def status(app_context, server_url, package_name, exist, health, json): """Translation status of a package. e.g. transtats package anaconda """ api_obj = ConsumeAPIs(server_url or app_context.server_url) if json \ diff --git a/tscli/restapi.py b/tscli/restapi.py index 54b3318..1c60665 100644 --- a/tscli/restapi.py +++ b/tscli/restapi.py @@ -26,7 +26,7 @@ class ConsumeAPIs(object): base_URL = None middle_URL = "api" - ERR_JSON = {"Error": "Some thing unexpected happened."} + ERR_JSON = {"Error": "Something unexpected happened."} def __init__(self, base_url): """ @@ -68,7 +68,7 @@ def _send_api(self, endpoint, payload): except Exception: return self.ERR_JSON - return response.json() + return response.json() if response.ok else self.ERR_JSON @property def server_version(self): @@ -141,3 +141,17 @@ def job_run(self, job_type, package_name, build_system=None, build_tag=None, return {"pkg_error": "Given package does not exists"} return self._send_api(ENDPOINT, payload) + + def add_package(self, package_name, upstream_url, transplatform_slug, release_stream): + """ + Create a new package at Transtats Server + """ + ENDPOINT = "/package/create" + payload = { + "package_name": package_name, + "upstream_url": upstream_url or "", + "transplatform_slug": transplatform_slug or "", + "release_streams": release_stream or "" + } + + return self._send_api(ENDPOINT, payload) diff --git a/tscli/textoutput.py b/tscli/textoutput.py index 950f08d..9132fb6 100644 --- a/tscli/textoutput.py +++ b/tscli/textoutput.py @@ -386,3 +386,13 @@ def job_run(self, job_type, package_name, build_system, build_tag, print("\n".join([": ".join([key.title(), value]) for key, value in json_data.items()])) return + + def add_package(self, package_name, upstream_url, transplatform_slug, release_stream): + """ + Create a new package at Transtats Server + """ + json_data = self.raw_data.add_package(package_name, upstream_url, + transplatform_slug, release_stream) + for k, v in json_data.items(): + print("{}: {}".format(k, v)) + return From 1b691099d66a31359bafe3711e779ec3cb488a91 Mon Sep 17 00:00:00 2001 From: Parag Nemade Date: Fri, 1 Jul 2022 16:31:05 +0530 Subject: [PATCH 3/3] Prepare for 0.6.0 release Signed-off-by: Parag Nemade --- Changlog.rst => Changelog.rst | 11 ++++++++++- docs/man/transtats.1 | 28 +++++++++++++++++----------- tests/test_data.py | 2 +- tests/test_tscli.py | 2 +- tscli/__init__.py | 4 ++-- tscli/packages/commands.py | 2 +- tscli/restapi.py | 2 +- tscli/stats/commands.py | 2 +- tscli/textoutput.py | 2 +- 9 files changed, 35 insertions(+), 20 deletions(-) rename Changlog.rst => Changelog.rst (85%) diff --git a/Changlog.rst b/Changelog.rst similarity index 85% rename from Changlog.rst rename to Changelog.rst index e460cac..9fe33ec 100644 --- a/Changlog.rst +++ b/Changelog.rst @@ -1,7 +1,16 @@ Changelog ========= -0.5.0 (2020-07-12) +0.6.0 (2022-07-01) +----------------- +- transtats add --package cmd (sdp5) +- Implement add package command (sdp5) +- Extract package commands to a new group for adding new packages + and showing stats, health etc. (sdp5) +- Update unit tests (sdp5) +- Update man page (pnemade) + +0.5.0 (2021-07-12) ----------------- - Update textoutput.py (sundeep-co-in) - Add new options repo-type and repo-branch to job run command (sundeep-co-in) diff --git a/docs/man/transtats.1 b/docs/man/transtats.1 index 8858067..c938c6c 100644 --- a/docs/man/transtats.1 +++ b/docs/man/transtats.1 @@ -1,5 +1,5 @@ .\" transtats - Command line interface for transtats -.TH "TRANSTATS" "1" "12th July 2021" "transtats 0.5.0" "User Commands" +.TH "TRANSTATS" "1" "1st July 2022" "transtats 0.6.0" "User Commands" .SH "NAME" transtats \- Command line interface for transtats .SH "SYNOPSIS" @@ -30,8 +30,8 @@ Show this message and exit. Available repo-types are default, l10n, transifex, weblate .br -.I \fB * package [OPTIONS] PACKAGE_NAME - Translation status of a package. +.I \fB * package [OPTIONS] COMMAND [ARGS]... PACKAGE_NAME + Package related operations. .br .I \fB * version [OPTIONS] @@ -48,24 +48,24 @@ Show this message and exit. .PP \fBTo check the translation status of any partiular package for all the available release branches on transtats server.\fP - transtats package abrt + transtats package status abrt .PP \fBTo check the if package exists on the transtats server.\fP - transtats package --exist abrt + transtats package status --exist abrt .PP \fBTo check the translation health of any partiular package for all the available release branches on transtats server.\fP - transtats package --health abrt + transtats package status --health abrt .PP \fBTo check the translation status for available packages in any pre-defined Linux distribution release on transtats server.\fP - transtats release fedora-35 + transtats release fedora-37 .PP \fBTo check the translation status for available packages in any pre-defined Linux distribution release on transtats server.\fP \fBBut if you need to know this status categorized by individual languages then use --detail\fP - transtats release --detail fedora-35 + transtats release --detail fedora-37 .PP \fBTo know the version of this transtats client.\fP @@ -78,10 +78,16 @@ Show this message and exit. .PP \fBTo submit a job to transtats server. There are 6 types of job that users can submit.\fP Various job type command examples are given below - transtats job run --repo-type l10n --repo-branch f35 syncupstream anaconda - transtats job run --repo-type l10n --repo-branch f35 --build-system koji --build-tag f35 syncdownstream anaconda - transtats job run --repo-branch main --release-slug fedora-33 stringchange anaconda + transtats job run --repo-type l10n --repo-branch f37 syncupstream anaconda + transtats job run --repo-type l10n --repo-branch f37 --build-system koji --build-tag f37 syncdownstream anaconda + transtats job run --repo-branch main --release-slug fedora-37 stringchange anaconda +.PP + \fBTo add a package to transtats server.\fP + Various command examples are given below + transtats package add celluloid --upstream-url https://github.com/celluloid-player/celluloid --transplatform-slug WLTEPUB --release-stream Fedora + transtats package add fedora-media-writer --upstream-url https://github.com/FedoraQt/MediaWriter --transplatform-slug WLTEFED --release-stream Fedora + .SH "NOTES" These commands give output in plain text format. If you need the same output in json format then just add to every above command --json option. diff --git a/tests/test_data.py b/tests/test_data.py index b14ac31..ef9b710 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -1,4 +1,4 @@ -# Copyright 2017 Red Hat, Inc. +# Copyright 2017, 2022 Red Hat, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/tests/test_tscli.py b/tests/test_tscli.py index 4508da1..d4e9e93 100644 --- a/tests/test_tscli.py +++ b/tests/test_tscli.py @@ -1,4 +1,4 @@ -# Copyright 2017, 2018 Red Hat, Inc. +# Copyright 2017, 2018, 2022 Red Hat, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/tscli/__init__.py b/tscli/__init__.py index 9aed4fa..883e720 100644 --- a/tscli/__init__.py +++ b/tscli/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2017-2021 Red Hat, Inc. +# Copyright 2017-2022 Red Hat, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -22,7 +22,7 @@ from tscli.jobs import commands as jobs from tscli.packages import commands as pkgs -APP_VERSION = "0.5.0" +APP_VERSION = "0.6.0" class AppContext(object): diff --git a/tscli/packages/commands.py b/tscli/packages/commands.py index 3ea1a13..f5d923f 100644 --- a/tscli/packages/commands.py +++ b/tscli/packages/commands.py @@ -1,4 +1,4 @@ -# Copyright 2018 Red Hat, Inc. +# Copyright 2018, 2022 Red Hat, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/tscli/restapi.py b/tscli/restapi.py index 1c60665..7ad5126 100644 --- a/tscli/restapi.py +++ b/tscli/restapi.py @@ -1,4 +1,4 @@ -# Copyright 2017-2019 Red Hat, Inc. +# Copyright 2017-2019, 2022 Red Hat, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/tscli/stats/commands.py b/tscli/stats/commands.py index 25370ba..973f835 100644 --- a/tscli/stats/commands.py +++ b/tscli/stats/commands.py @@ -1,4 +1,4 @@ -# Copyright 2017-2019 Red Hat, Inc. +# Copyright 2017-2019, 2022 Red Hat, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/tscli/textoutput.py b/tscli/textoutput.py index 9132fb6..745232d 100644 --- a/tscli/textoutput.py +++ b/tscli/textoutput.py @@ -1,4 +1,4 @@ -# Copyright 2017-2019 Red Hat, Inc. +# Copyright 2017-2019, 2022 Red Hat, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may