Skip to content

Commit

Permalink
Merge pull request #31 from pnemade/devel
Browse files Browse the repository at this point in the history
Release of 0.6.0 version
  • Loading branch information
pnemade authored Jul 1, 2022
2 parents ba52d86 + 1b69109 commit 973305f
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 60 deletions.
11 changes: 10 additions & 1 deletion Changlog.rst → Changelog.rst
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
28 changes: 17 additions & 11 deletions docs/man/transtats.1
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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.
Expand Down
14 changes: 13 additions & 1 deletion tests/test_data.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
48 changes: 36 additions & 12 deletions tests/test_tscli.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -60,68 +60,92 @@ def test_server_version(self):

def test_package_status(self):
"""
transtats package <package>
transtats package stats <package>
"""
from tscli import entry_point

with patch('requests.get') as mock_request_get:
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', 'status', 'systemd'])
self.assertEqual(result.exit_code, 0)
self.assertIn('systemd', result.output)
self.assertIn('Branch', result.output)
self.assertIn('percentage_calculated_on', result.output)

def test_package_status_exist(self):
"""
transtats package --exist <package>
transtats package stats --exist <package>
"""
from tscli import entry_point

with patch('requests.get') as mock_request_get:
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', 'status', '--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 <package>
transtats package stats --health <package>
"""
from tscli import entry_point

with patch('requests.get') as mock_request_get:
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', 'status', '--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 <package>
transtats package stats --health <package>
"""
from tscli import entry_point

with patch('requests.get') as mock_request_get:
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', '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 <package-name>
--upstream-url <upstream-url>
--transplatform-slug <platform-slug>
--release-stream <product>
"""
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 <graph_rule>
Expand Down
7 changes: 4 additions & 3 deletions tscli/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,8 +20,9 @@
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"
APP_VERSION = "0.6.0"


class AppContext(object):
Expand Down Expand Up @@ -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)
Empty file added tscli/packages/__init__.py
Empty file.
77 changes: 77 additions & 0 deletions tscli/packages/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright 2018, 2022 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 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 \
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)
20 changes: 17 additions & 3 deletions tscli/restapi.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Loading

0 comments on commit 973305f

Please sign in to comment.