Skip to content

Commit

Permalink
[0.3] Add memsource project template list
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludek Janda committed Nov 27, 2019
1 parent 7b79b21 commit 5876cf3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
6 changes: 4 additions & 2 deletions memsource_cli/api/project_template_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ def get_project_templates_with_http_info(self, **kwargs): # noqa: E501
returns the request thread.
"""

all_params = ['name', 'client_id', 'page_number', 'page_size'] # noqa: E501
all_params = ['name', 'client_id', 'page_number', 'page_size', 'token'] # noqa: E501
all_params.append('async_req')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
Expand Down Expand Up @@ -1405,7 +1405,9 @@ def get_project_templates_with_http_info(self, **kwargs): # noqa: E501
query_params.append(('pageNumber', params['page_number'])) # noqa: E501
if 'page_size' in params:
query_params.append(('pageSize', params['page_size'])) # noqa: E501

if 'token' in params:
query_params.append(('token', params['token'])) # noqa: E501

header_params = {}

form_params = []
Expand Down
53 changes: 53 additions & 0 deletions memsource_cli/template/v1/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,63 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4

from cliff.show import ShowOne
from cliff.lister import Lister

import memsource_cli
from memsource_cli.lib import utils

class ListTemplate(Lister):
"""
List templates
"""

def get_parser(self, prog_name):
"""Command argument parsing."""
parser = super(ListTemplate, self).get_parser(prog_name)
all_params = ['name'] # noqa: E501
all_params_int = ['client_id', 'page_number', 'page_size'] # noqa: E501

for param in all_params:
parser.add_argument(
'--' + param.replace('_', '-'),
help=param,
dest=param
)
for param in all_params_int:
parser.add_argument(
'--' + param.replace('_', '-'),
help=param,
type=int
)

return parser

def take_action(self, parsed_args):
api = memsource_cli.ProjectTemplateApi(self.app.client)
query_params = vars(parsed_args)
args = {}
all_params = ['name', 'client_id', 'page_number', 'page_size'] # noqa: E501

for k, v in query_params.items():
if k in all_params and v is not None:
args[k] = v


response = api.get_project_templates(token=self.app.client.configuration.token, # noqa: E501
**args)

response = response.to_dict()

return(('id',
'target_langs',
'source_lang',
'template_name'),(
(response['content'][i]['id'],
response['content'][i]['target_langs'],
response['content'][i]['source_lang'],
response['content'][i]['template_name'])
for i in range(0, len(response['content']))))

class ShowTemplate(ShowOne):
"""
Show template
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ memsource.cli =
analyse_language_create = memsource_cli.analysis.v1.analysis:CreateAnalysisByLanguages
analyse_project_list = memsource_cli.analysis.v2.analysis:ListAnalysisByProject
analyse_show = memsource_cli.analysis.v2.analysis:ShowAnalysis
template_list = memsource_cli.template.v1.template:ListTemplate
template_show = memsource_cli.template.v1.template:ShowTemplate
translation_pre-translate = memsource_cli.translation.v1.translation:PreTranslate

Expand Down

0 comments on commit 5876cf3

Please sign in to comment.