From 9c0e7385f377df201e61abf0bd37a1d0d9642250 Mon Sep 17 00:00:00 2001 From: Sundeep Anand Date: Fri, 23 Apr 2021 15:38:42 +0530 Subject: [PATCH 1/6] Add new options repo-type and repo-branch to job run command. --- tests/test_data.py | 42 ++++++++++++++++++++++++++++-------------- tests/test_tscli.py | 24 ++++++++++++++++++++++-- tscli/jobs/commands.py | 8 ++++++-- tscli/restapi.py | 7 ++++--- tscli/textoutput.py | 4 ++-- 5 files changed, 62 insertions(+), 23 deletions(-) diff --git a/tests/test_data.py b/tests/test_data.py index 25c28e1..b87b4e4 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -70,20 +70,20 @@ def mock_package_status_health(): mock_rep = Mock() mock_rep.ok = True mock_rep.json.return_value = { - "abrt": { - "fedora-30": { - "Arabic": 2, - "Basque": 3, - "Esperanto": 7, - "Friulian": 24, - "Serbian": 14, - "Turkish": 13, - "Urdu": 3 - }, - "fedora-31": { - "Friulian": 24 + "abrt": { + "fedora-30": { + "Arabic": 2, + "Basque": 3, + "Esperanto": 7, + "Friulian": 24, + "Serbian": 14, + "Turkish": 13, + "Urdu": 3 + }, + "fedora-31": { + "Friulian": 24 + } } - } } return mock_rep @@ -257,7 +257,21 @@ def mock_package_exists(): return mock_rep -def mock_job_run(): +def mock_job_run_syncupstream(): + """ + job_run mock value + """ + mock_rep = Mock() + mock_rep.ok = True + mock_rep.json.return_value = { + "Success": "Job created and logged. " + "URL: http://localhost:8080/jobs/log/e41ee603-9bdc-4640-83f3-aa8c82263831/detail", + "job_id": "e41ee603-9bdc-4640-83f3-aa8c82263831" + } + return mock_rep + + +def mock_job_run_stringchange(): """ job_run mock value """ diff --git a/tests/test_tscli.py b/tests/test_tscli.py index 4d8a06d..fc7934f 100644 --- a/tests/test_tscli.py +++ b/tests/test_tscli.py @@ -203,7 +203,27 @@ def test_release_status_by_locale(self): self.assertIn('Calculated on', result.output) self.assertIn('Locale', result.output) - def test_job_run(self): + def test_job_run_upstream(self): + """ + transtats job run --repo-type= --repo-branch= + """ + from tscli import entry_point + + with patch('requests.get') as mock_request_get: + with patch('requests.post') as mock_request_post: + mock_request_get.return_value = \ + test_data.mock_package_exists() + mock_request_post.return_value = \ + test_data.mock_job_run_syncupstream() + runner = CliRunner() + result = runner.invoke(entry_point, + ['job', 'run', '--repo-type', 'l10n', + '--repo-branch', 'master', 'syncupstream', 'iok']) + self.assertEqual(result.exit_code, 0) + self.assertIn('Success', result.output) + self.assertIn('Job_Id', result.output) + + def test_job_run_stringchange(self): """ transtats job run --release-slug """ @@ -214,7 +234,7 @@ def test_job_run(self): mock_request_get.return_value = \ test_data.mock_package_exists() mock_request_post.return_value = \ - test_data.mock_job_run() + test_data.mock_job_run_stringchange() runner = CliRunner() result = runner.invoke(entry_point, ['job', 'run', 'stringchange', 'iok', diff --git a/tscli/jobs/commands.py b/tscli/jobs/commands.py index bfe2f42..6c3d2db 100644 --- a/tscli/jobs/commands.py +++ b/tscli/jobs/commands.py @@ -34,20 +34,24 @@ def job(): help="build tag like f29") @click.option("--release-slug", is_flag=False, help="release name like fedora-29") +@click.option("--repo-type", is_flag=False, + help="repo type like default or l10n") +@click.option("--repo-branch", is_flag=False, + help="repository branch like master") @click.option( '--json', is_flag=True, envvar='JSON_OUTPUT', help="Print in JSON format") @click.argument('job_type') @click.argument('package_name') @click.pass_obj def run(app_context, server_url, token, job_type, package_name, build_system, - build_tag, release_slug, json): + build_tag, release_slug, repo_type, repo_branch, json): """Runs a job and/or show the job log. Available job-types are syncupstream, syncdownstream, stringchange.""" api_obj = ConsumeAPIs(server_url or app_context.server_url) if json \ else TextOutputAPIs(server_url or app_context.server_url) response = api_obj.job_run(job_type, package_name, build_system, - build_tag, release_slug) + build_tag, release_slug, repo_type, repo_branch) if isinstance(response, dict): app_context.print_r(response) diff --git a/tscli/restapi.py b/tscli/restapi.py index fcec232..54b3318 100644 --- a/tscli/restapi.py +++ b/tscli/restapi.py @@ -116,8 +116,8 @@ def job_log(self, job_id): ENDPOINT = "/job/" + job_id + "/log" return self._call_api(ENDPOINT) - def job_run(self, job_type, package_name, build_system=None, - build_tag=None, release_slug=None): + def job_run(self, job_type, package_name, build_system=None, build_tag=None, + release_slug=None, repo_type=None, repo_branch=None): """ Submit the job for the given job type and package name """ @@ -126,7 +126,8 @@ def job_run(self, job_type, package_name, build_system=None, pkg_exists = self._call_api(_ENDPOINT) if list(pkg_exists.values())[0]: if job_type == "syncupstream": - payload = {'job_type': job_type, 'package_name': package_name} + payload = {'job_type': job_type, 'package_name': package_name, + 'repo_type': repo_type, 'repo_branch': repo_branch} elif job_type == "syncdownstream": payload = {'job_type': job_type, 'package_name': package_name, 'build_system': build_system, diff --git a/tscli/textoutput.py b/tscli/textoutput.py index ee8799e..6e74d87 100644 --- a/tscli/textoutput.py +++ b/tscli/textoutput.py @@ -336,13 +336,13 @@ def job_log(self, job_id): return def job_run(self, job_type, package_name, build_system, build_tag, - release_slug): + release_slug, repo_type, repo_branch): """ Submit the job for the given job type and package name """ json_data = self.raw_data.job_run(job_type, package_name, build_system, - build_tag, release_slug) + build_tag, release_slug, repo_type, repo_branch) first_key = list(json_data.keys())[0] if first_key == "detail": From c779e8b18be95aa48cf41b22d67024cd2fa41e4e Mon Sep 17 00:00:00 2001 From: Sundeep Anand Date: Fri, 11 Jun 2021 19:02:15 +0530 Subject: [PATCH 2/6] Update textoutput.py Nested for statement uses loop variable 'key' of enclosing for statement. --- tscli/textoutput.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tscli/textoutput.py b/tscli/textoutput.py index 6e74d87..950f08d 100644 --- a/tscli/textoutput.py +++ b/tscli/textoutput.py @@ -324,8 +324,8 @@ def job_log(self, job_id): if log_key == 'Clone Repository': crepo = log_out[log_key] print("\nClone Repository: ") - for key, value in crepo.items(): - print("{0} {1}".format(key, value)) + for k, v in crepo.items(): + print("{0} {1}".format(k, v)) if log_key == 'Filter PO files': filter_po_files = log_out[log_key] print("Filter PO files: ") From da78f74d531712654c455e3e6e6048228fe33683 Mon Sep 17 00:00:00 2001 From: Sundeep Anand Date: Fri, 11 Jun 2021 19:04:39 +0530 Subject: [PATCH 3/6] Update README.md Add lgtm.com badges --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 0d55e45..4b1fd9b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ [![Build Status](https://travis-ci.org/transtats/transtats-cli.svg?branch=devel)](https://travis-ci.org/transtats/transtats-cli) +[![Total alerts](https://img.shields.io/lgtm/alerts/g/transtats/transtats-cli.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/transtats/transtats-cli/alerts/) +[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/transtats/transtats-cli.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/transtats/transtats-cli/context:python) # transtats-cli Transtats command line interface to query transtats server. From 0835257b9a362f4b35c52984246480757d20752e Mon Sep 17 00:00:00 2001 From: Parag Nemade Date: Tue, 13 Jul 2021 10:58:44 +0530 Subject: [PATCH 4/6] Update transtats man page --- docs/man/transtats.1 | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/docs/man/transtats.1 b/docs/man/transtats.1 index 2fcf4d7..98d2045 100644 --- a/docs/man/transtats.1 +++ b/docs/man/transtats.1 @@ -1,5 +1,5 @@ .\" transtats - Command line interface for transtats -.TH "TRANSTATS" "1" "9th June 2020" "transtats 0.4.0" "User Commands" +.TH "TRANSTATS" "1" "12th July 2021" "transtats 0.5.0" "User Commands" .SH "NAME" transtats \- Command line interface for transtats .SH "SYNOPSIS" @@ -16,6 +16,19 @@ Show this message and exit. .I \fB * coverage [OPTIONS] GRAPH_RULE Translation coverage as per graph rule. +.br +.I \fB * job [OPTIONS] COMMAND [ARGS].... + Job related operations. There are two sub-commands used with this job command. + + 1) transtats job log [OPTIONS] JOB_ID + Show the log for a given job id. + + 2) transtats job run [OPTIONS] REPO_TYPE REPO_BRANCH JOB_TYPE PACKAGE_NAME + Runs a job and/or show the job log. + Available job-types are syncupstream, syncdownstream, stringchange, + pushtrans, dpushtrans, pulltrans + Available repo-types are default, l10n, transifex, weblate + .br .I \fB * package [OPTIONS] PACKAGE_NAME Translation status of a package. @@ -28,16 +41,6 @@ Show this message and exit. .I \fB * release [OPTIONS] RELEASE_SLUG Translation status of a release slug(branch). -.br -.I \fB * job [OPTIONS] COMMAND [ARGS].... - Job related operations. There are two sub-commands used with this job command. - - 1) transtats job log [OPTIONS] JOB_ID - Show the log for a given job id. - - 2) transtats job run [OPTIONS] JOB_TYPE PACKAGE_NAME - Runs a job and/or show the job log. Available job-types are syncupstream, syncdownstream, stringchange. - .SH "EXAMPLES" .PP \fBTo check the translation coverage as per predefined graph rule on transtats server.\fP @@ -57,12 +60,12 @@ Show this message and exit. .PP \fBTo check the translation status for available packages in any pre-defined Linux distribution release on transtats server.\fP - transtats release fedora-33 + transtats release fedora-35 .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-33 + transtats release --detail fedora-35 .PP \fBTo know the version of this transtats client.\fP @@ -73,12 +76,11 @@ Show this message and exit. transtats version --server .PP - \fBTo submit a job to transtats server. There are 3 types of job that users can submit.\fP - These job types are syncupstream, syncdownstream, stringchange. + \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 stringchange anaconda - transtats job run syncdownstream anaconda --build-system koji --build-tag f33 - transtats job run stringchange anaconda --release-slug fedora-33 + 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 master --release-slug fedora-33 stringchange anaconda .SH "NOTES" These commands give output in plain text format. If you need the same output From 1660d0f40fc204e9c05ffdf0485b92458a7fa136 Mon Sep 17 00:00:00 2001 From: Parag Nemade Date: Tue, 13 Jul 2021 11:17:39 +0530 Subject: [PATCH 5/6] Change Problematic language in code Signed-off-by: Parag Nemade --- README.md | 2 +- docs/man/transtats.1 | 2 +- tests/test_tscli.py | 2 +- tscli/jobs/commands.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4b1fd9b..e6fbfcd 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Commands: * Fork [transtats-cli repo](https://github.com/transtats/transtats-cli) to your username and clone repository locally. * Setup development environment `pip install -r requirements.txt` * The *devel* branch is the release actively under development. -* The *master* branch corresponds to the latest stable release. +* The *main* branch corresponds to the latest stable release. * If you find any bug/issue or got an idea, open a [github issue](https://github.com/transtats/transtats-cli/issues/new). * [travis](https://travis-ci.org/transtats/transtats-cli) runs flake8 and tests `python setup.py flake8 test` * Feel free to submit feature requests and/or bug fixes on *devel* branch. diff --git a/docs/man/transtats.1 b/docs/man/transtats.1 index 98d2045..8858067 100644 --- a/docs/man/transtats.1 +++ b/docs/man/transtats.1 @@ -80,7 +80,7 @@ Show this message and exit. 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 master --release-slug fedora-33 stringchange anaconda + transtats job run --repo-branch main --release-slug fedora-33 stringchange anaconda .SH "NOTES" These commands give output in plain text format. If you need the same output diff --git a/tests/test_tscli.py b/tests/test_tscli.py index fc7934f..af31a00 100644 --- a/tests/test_tscli.py +++ b/tests/test_tscli.py @@ -218,7 +218,7 @@ def test_job_run_upstream(self): runner = CliRunner() result = runner.invoke(entry_point, ['job', 'run', '--repo-type', 'l10n', - '--repo-branch', 'master', 'syncupstream', 'iok']) + '--repo-branch', 'main', 'syncupstream', 'iok']) self.assertEqual(result.exit_code, 0) self.assertIn('Success', result.output) self.assertIn('Job_Id', result.output) diff --git a/tscli/jobs/commands.py b/tscli/jobs/commands.py index 6c3d2db..f0fbc85 100644 --- a/tscli/jobs/commands.py +++ b/tscli/jobs/commands.py @@ -37,7 +37,7 @@ def job(): @click.option("--repo-type", is_flag=False, help="repo type like default or l10n") @click.option("--repo-branch", is_flag=False, - help="repository branch like master") + help="repository branch like main") @click.option( '--json', is_flag=True, envvar='JSON_OUTPUT', help="Print in JSON format") @click.argument('job_type') From 10dc67897db30b520078eb0b6de8dc85ea8bc2a5 Mon Sep 17 00:00:00 2001 From: Parag Nemade Date: Tue, 13 Jul 2021 11:37:44 +0530 Subject: [PATCH 6/6] Prepare for 0.5.0 release Signed-off-by: Parag Nemade --- Changlog.rst | 7 +++++++ setup.py | 2 +- tscli/__init__.py | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Changlog.rst b/Changlog.rst index 405ae4d..e460cac 100644 --- a/Changlog.rst +++ b/Changlog.rst @@ -1,6 +1,13 @@ Changelog ========= +0.5.0 (2020-07-12) +----------------- +- Update textoutput.py (sundeep-co-in) +- Add new options repo-type and repo-branch to job run command (sundeep-co-in) +- Update man page (pnemade) +- Change Problematic language in code (pnemade) + 0.4.0 (2020-07-09) ----------------- - Dropping flake8 dependency (pnemade) diff --git a/setup.py b/setup.py index c4b72bc..87d5ade 100644 --- a/setup.py +++ b/setup.py @@ -38,8 +38,8 @@ 'Intended Audience :: Developers', 'Programming Language :: Python', 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', ], ) diff --git a/tscli/__init__.py b/tscli/__init__.py index b906eda..b9248d6 100644 --- a/tscli/__init__.py +++ b/tscli/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2017-2020 Red Hat, Inc. +# Copyright 2017-2021 Red Hat, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -21,7 +21,7 @@ from tscli.stats import commands as trans from tscli.jobs import commands as jobs -APP_VERSION = "0.4.0" +APP_VERSION = "0.5.0" class AppContext(object):