Skip to content

Commit 666e5ee

Browse files
authored
Merge pull request #19 from transtats/devel
merge devel to master branch for 0.2.0 release
2 parents 604f34e + 7c34534 commit 666e5ee

File tree

17 files changed

+642
-26
lines changed

17 files changed

+642
-26
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
sudo: true
3-
dist: trusty
42
language: python
53
python:
64
- "2.7"
5+
- "3.4"
6+
- "3.5"
77
- "3.6"
88

99
addons:

Changlog.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
Changelog
22
=========
33

4+
0.2.0 (2018-08-04)
5+
-----------------
6+
- Add partial bash-completion support for job command (pnemade)
7+
- Test fixes (sundeep-co-in)
8+
- Added transtats job command.
9+
Added run and log as subcommands to job command.
10+
Updated man page. (pnemade)
11+
12+
- Added Makefile for this project (pnemade)
13+
- Added locale option to release command.
14+
This option is available for text as well as json output.
15+
Supporting test case also added in this commit. (pnemade)
16+
17+
- Remove trailing slash from the endpoint (sundeep-co-in)
18+
- Added bash completion for transtats commands (pnemade)
19+
420
0.1.2 (2018-02-27)
5-
----------------
21+
-----------------
622
- Fix the plain text output from the tables by sorting list data - (sundeep-co-in)
723
- Fix some cosmetic changes in the code - (sundeep-co-in)
824
- Add plain text output for the transtats commands - #11 (pnemade)

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
.PHONY: clean-pyc
3+
clean-pyc:
4+
find . -name '*.pyc' -exec rm -f {} +
5+
find . -name '*.pyo' -exec rm -f {} +
6+
find . -name '*~' -exec rm -f {} +
7+
8+
.PHONY: devel
9+
devel:
10+
pip3 install -r requirements.txt
11+
12+
.PHONY: env-info
13+
env-info:
14+
uname -a
15+
pip list
16+
17+
.PHONY: lint
18+
lint:
19+
flake8 --exclude=.eggs --ignore=E501,F401,F403,F405 .
20+
21+
.PHONY: test
22+
test:
23+
python3 setup.py test

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
# transtats-cli
44
Transtats command line interface to query transtats server.
55

6+
#### Configuration
7+
68
`transtats.conf` should be placed inside `~/.config/` directory.
9+
Transtats server url and API token can be added as
10+
```shell
11+
[server]
12+
server_url = http://app.server.transtats.org
13+
token = <API-token-from-server>
14+
```
15+
16+
#### Commands
717

818
```shell
919
Usage: transtats [OPTIONS] COMMAND [ARGS]...
@@ -15,6 +25,7 @@ Options:
1525

1626
Commands:
1727
coverage Translation coverage as per graph rule.
28+
job Runs a job and/or show the job log.
1829
package Translation status of a package.
1930
release Translation status of a release branch.
2031
version Display the current version.
@@ -30,3 +41,7 @@ Commands:
3041
* If you find any bug/issue or got an idea, open a [github issue](https://github.com/transtats/transtats-cli/issues/new).
3142
* [travis](https://travis-ci.org/transtats/transtats-cli) runs flake8 and tests `python setup.py flake8 test`
3243
* Feel free to submit feature requests and/or bug fixes on *devel* branch.
44+
45+
### License
46+
47+
[Apache License](http://www.apache.org/licenses/LICENSE-2.0), Version 2.0
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# transtats bash completion
2+
3+
_transtats()
4+
{
5+
COMPREPLY=()
6+
7+
in_array()
8+
{
9+
local i
10+
for i in $2; do
11+
[[ $i = $1 ]] && return 0
12+
done
13+
return 1
14+
}
15+
16+
local cur prev
17+
cur="${COMP_WORDS[COMP_CWORD]}"
18+
prev="${COMP_WORDS[COMP_CWORD-1]}"
19+
20+
# global options
21+
local options="--help"
22+
local options_value=
23+
local commands="coverage job package release version"
24+
25+
# parse main options and get command
26+
local command=
27+
local command_first=
28+
local path=
29+
30+
local i w
31+
for (( i = 0; i < ${#COMP_WORDS[*]} - 1; i++ )); do
32+
w="${COMP_WORDS[$i]}"
33+
# option
34+
if [[ ${w:0:1} = - ]]; then
35+
if in_array "$w" "$options_value"; then
36+
((i++))
37+
[[ "$w" = --path ]] && path="${COMP_WORDS[$i]}"
38+
fi
39+
# command
40+
elif in_array "$w" "$commands"; then
41+
command="$w"
42+
command_first=$((i+1))
43+
break
44+
fi
45+
done
46+
47+
# complete base options
48+
if [[ -z $command ]]; then
49+
if [[ $cur == -* ]]; then
50+
COMPREPLY=( $(compgen -W "$options $options_value" -- "$cur") )
51+
return 0
52+
fi
53+
54+
case "$prev" in
55+
*)
56+
COMPREPLY=( $(compgen -W "$commands" -- "$cur") )
57+
;;
58+
esac
59+
60+
return 0
61+
fi
62+
63+
# parse command specific options
64+
local options="--json --server-url --help"
65+
local options_release= options_version= options_job=
66+
local after= after_more=
67+
68+
case $command in
69+
job)
70+
options_job="--build-tag --build-system --release-slug"
71+
;;
72+
release)
73+
options_release="--detail --locale"
74+
;;
75+
version)
76+
options_version="--server"
77+
;;
78+
esac
79+
80+
local all_options="--help $options"
81+
local all_options_value="$options_release $options_version $options_job"
82+
83+
# count non-option parameters
84+
local i w
85+
local last_option=
86+
local after_counter=0
87+
for (( i = $command_first; i < ${#COMP_WORDS[*]} - 1; i++)); do
88+
w="${COMP_WORDS[$i]}"
89+
if [[ ${w:0:1} = - ]]; then
90+
if in_array "$w" "$all_options"; then
91+
last_option="$w"
92+
continue
93+
elif in_array "$w" "$all_options_value"; then
94+
last_option="$w"
95+
((i++))
96+
continue
97+
fi
98+
fi
99+
in_array "$last_option" "$options_arches" || ((after_counter++))
100+
done
101+
102+
# completion
103+
if [[ -n $options_release ]] && in_array "$prev" "$options_release"; then
104+
COMPREPLY=( )
105+
elif [[ -n $options_version ]] && in_array "$prev" "$options_version"; then
106+
COMPREPLY=( )
107+
elif [[ -n $options_job ]] && in_array "$prev" "$options_job"; then
108+
COMPREPLY=( )
109+
else
110+
local after_options=
111+
112+
if [[ $cur != -* ]]; then
113+
all_options=
114+
all_options_value=
115+
fi
116+
117+
COMPREPLY+=( $(compgen -W "$all_options $all_options_value $after_options" -- "$cur" ) )
118+
fi
119+
120+
return 0
121+
} &&
122+
complete -F _transtats transtats
123+

docs/man/transtats.1

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.\" transtats - Command line interface for transtats
2-
.TH "TRANSTATS" "1" "February 2018" "transtats 0.1.2" "User Commands"
2+
.TH "TRANSTATS" "1" "August 2018" "transtats 0.2.0" "User Commands"
33
.SH "NAME"
44
transtats \- Command line interface for transtats
55
.SH "SYNOPSIS"
@@ -25,8 +25,18 @@ Show this message and exit.
2525
Display the current version.
2626

2727
.br
28-
.I \fB * release [OPTIONS] RELEASE_BRANCH
29-
Translation status of a release branch.
28+
.I \fB * release [OPTIONS] RELEASE_SLUG
29+
Translation status of a release slug(branch).
30+
31+
.br
32+
.I \fB * job [OPTIONS] COMMAND [ARGS]....
33+
Job related operations. There are two sub-commands used with this job command.
34+
35+
1) transtats job log [OPTIONS] JOB_ID
36+
Show the log for a given job id.
37+
38+
2) transtats job run [OPTIONS] JOB_TYPE PACKAGE_NAME
39+
Runs a job and/or show the job log. Available job-types are syncupstream, syncdownstream, stringchange.
3040

3141
.SH "EXAMPLES"
3242
.PP
@@ -54,6 +64,14 @@ Show this message and exit.
5464
\fBTo know the version of this transtats client along with transtats server.\fP
5565
transtats version --server
5666

67+
.PP
68+
\fBTo submit a job to transtats server. There are 3 types of job that users can submit.\fP
69+
These job types are syncupstream, syncdownstream, stringchange.
70+
Various job type command examples are given below
71+
transtats job run stringchange anaconda
72+
transtats job run syncdownstream anaconda --build-system koji --build-tag f29
73+
transtats job run stringchange anaconda --release-slug fedora-29
74+
5775
.SH "NOTES"
5876
These commands give output in plain text format. If you need the same output
5977
in json format then just add to every above command --json option.

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
exclude = .git,*migrations*
3+
max-line-length = 149

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
setup_requires=["flake8"],
2727
test_suite="tests.tscli_test_suit",
2828
scripts=["transtats"],
29-
data_files=[('/usr/share/man/man1', ['docs/man/transtats.1'])],
29+
data_files=[('/usr/share/man/man1', ['docs/man/transtats.1']),
30+
('/usr/share/bash-completion/completions',
31+
['conf/bash-completion/transtats.bash'])],
3032
# entry_points='''
3133
# [console_scripts]
3234
# transtats=tscli:entry_point
@@ -37,6 +39,8 @@
3739
'Intended Audience :: Developers',
3840
'Programming Language :: Python',
3941
'Programming Language :: Python :: 2.7',
42+
'Programming Language :: Python :: 3.4',
43+
'Programming Language :: Python :: 3.5',
4044
'Programming Language :: Python :: 3.6',
4145
],
4246
)

tests/test_data.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,33 @@ def mock_release_status():
106106
return mock_rep
107107

108108

109+
def mock_release_status_by_locale():
110+
"""
111+
release_status_by_locale mock value
112+
"""
113+
mock_rep = Mock()
114+
mock_rep.ok = True
115+
mock_rep.json.return_value = {
116+
"fedora-27": {
117+
"anaconda": {
118+
"Total": 12080,
119+
"Translated": 11191,
120+
"Untranslated": 876,
121+
"Remaining": 7.25
122+
},
123+
"abrt": {
124+
"Total": 4760,
125+
"Translated": 4495,
126+
"Untranslated": 262,
127+
"Remaining": 5.5
128+
},
129+
"Calculated on": "Messages",
130+
"locale": "ja_JP"
131+
}
132+
}
133+
return mock_rep
134+
135+
109136
def mock_release_workload_detail():
110137
"""
111138
release_workload_detail mock value
@@ -146,3 +173,51 @@ def mock_release_workload_detail():
146173
"Release": "fedora-27",
147174
}
148175
return mock_rep
176+
177+
178+
def mock_job_run():
179+
"""
180+
job_run mock value
181+
"""
182+
mock_rep = Mock()
183+
mock_rep.ok = True
184+
mock_rep.json.return_value = {
185+
"Success": "Job created and logged. "
186+
"URL: http://test.transtats.org/jobs/log/bda71131-d177-44d9-9ee7-5df53f03c024/detail",
187+
"job_id": "bda71131-d177-44d9-9ee7-5df53f03c024"
188+
}
189+
return mock_rep
190+
191+
192+
def mock_job_log():
193+
"""
194+
job_log mock value
195+
"""
196+
mock_rep = Mock()
197+
mock_rep.ok = True
198+
mock_rep.json.return_value = {
199+
"id": "bda71131-d177-44d9-9ee7-5df53f03c024",
200+
"type": "stringchange",
201+
"start_time": "2018-08-03 11:39:00",
202+
"end_time": "2018-08-03 11:39:02",
203+
"result": True,
204+
"remarks": "iok",
205+
"YML_input": "job: exception: raise execution: sequential name: string change package: iok",
206+
"log_output": {
207+
"Clone Repository": {
208+
"2018-08-03 11:39:01.006607": "Start cloning https://pagure.io/iok.git repository.",
209+
"2018-08-03 11:39:01.730884": " :: Cloning git repo completed., .git, "
210+
},
211+
"Generate POT File": {
212+
"2018-08-03 11:39:02.022360": " :: POT file generated successfully. [ iok.pot ], "
213+
},
214+
"Calculate Differences": {
215+
"2018-08-03 11:39:02.142378": "No new or updated messages found."
216+
},
217+
"Download platform POT file": {
218+
"2018-08-03 11:39:02.134145": "POT downloaded successfully. "
219+
"URL: https://fedora.../pot?docId=iok"
220+
}
221+
}
222+
}
223+
return mock_rep

tests/test_transtats.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[server]
22
server_url = http://localhost:8080
3+
token = 75910e789ed5f41195d78964c1ea493531c9f0eb

0 commit comments

Comments
 (0)