Skip to content

Commit

Permalink
Merge pull request #38 from sundeep-co-in/STAGE
Browse files Browse the repository at this point in the history
ZNTA-865: locale support to zanata stats
  • Loading branch information
definite committed Jan 13, 2016
2 parents bdbd01e + d22f5e0 commit 68a9879
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* Thu Jan 7 2016 Sundeep Anand <[email protected]>
* Tue Jan 12 2016 Sundeep Anand <[email protected]> - 1.4.1
- Implemented zanata init (ZNTA-780)
- Bug ZNTA-853 - Crash when pushing local translations
- Bug 1206995 - allow anonymous pull
Expand Down
3 changes: 3 additions & 0 deletions zanataclient/cmdbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ def run(self):
for cmd in ('detailstats', 'wordstats', 'docid')
if cmd in self.context_data])
cmd_opts['locale_map'] = self.context_data.get('locale_map')
if self.context_data.get('lang') and isinstance(self.context_data['lang'], str):
cmd_opts['lang'] = filter(lambda locale: locale if locale else None,
self.context_data['lang'].split(','))
self.zanatacmd.display_translation_stats(*id_version, **cmd_opts)


Expand Down
11 changes: 6 additions & 5 deletions zanataclient/initcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ def print_trans_matches(self, match, locale, transdir):
elements = match.split('/')
elements[0] = transdir
elements[len(elements) - 1] = locale + '.po'
print("\t " + '/'.join(elements))
self.ptxt('info_blue', "\t " + '/'.join(elements))
elif self.local_config.get('project_type') == 'podir':
elements = match.split('/')
elements[0] = transdir
elements.insert(len(elements) - 1, locale)
print("\t " + '/'.join(elements).replace('pot', 'po'))
self.ptxt('info_blue', "\t " + '/'.join(elements).replace('pot', 'po'))

def print_dir_contents(self, directory, mode, transdir):
matches = []
Expand All @@ -267,12 +267,13 @@ def print_dir_contents(self, directory, mode, transdir):
if len(matches) > 0:
locale = 'en-US'
if mode == 'source':
print("\n\tFound %s documents: " % mode)
self.ptxt('header', "\n\tFound %s documents: " % mode)
else:
print('\n\tZanata will put translation files as below (e.g. for locale %s): ' % locale)
self.ptxt('header', '\n\tZanata will put translation files as '
'below (e.g. for locale %s): ' % locale)
for match in matches:
if mode == 'source':
print("\t\t%s" % match.rstrip(ext))
self.ptxt('info_blue', "\t\t%s" % match.rstrip(ext))
else:
self.print_trans_matches(match, locale, transdir)

Expand Down
1 change: 1 addition & 0 deletions zanataclient/zanata.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ def stats(command_options, args):
--project-version : id of the version (defaults to zanata.xml value)
--details : Include statistics for lower levels (i.e., for documents in a project version)
--docid : Document Id to fetch statistics for
--lang : Language list (comma separated)
--word : Include word level statistics. By default only message level statistics are shown
--disable-ssl-cert disable ssl certificate validation in 0.7.x python-httplib2
"""
Expand Down
5 changes: 3 additions & 2 deletions zanataclient/zanatacmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,11 @@ def display_translation_stats(self, *args, **kwargs):
try:
project_id, project_version = args
server_return = self.zanata_resource.stats.get_project_stats(
project_id, project_version, 'wordstats' in kwargs
project_id, project_version, 'wordstats' in kwargs, kwargs.get('lang')
) if not kwargs.get('docid') else \
self.zanata_resource.stats.get_doc_stats(
project_id, project_version, kwargs['docid'], 'wordstats' in kwargs
project_id, project_version, kwargs['docid'],
'wordstats' in kwargs, kwargs.get('lang')
)
except ZanataException, e:
self.log.error(str(e))
Expand Down
17 changes: 15 additions & 2 deletions zanataclient/zanatalib/statservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,29 @@ def __init__(self, *args, **kargs):
def disable_ssl_cert_validation(self):
self.restclient.disable_ssl_cert_validation()

def get_project_stats(self, project_id, project_version, word=False):
def _append_locales(self, ext, locales):
for locale in locales:
ext += '&locale=%s' % locale
return ext

def get_project_stats(
self, project_id, project_version, word=False, locales=None
):
ext = "?detail=true&word=true" if word else "?detail=true&word=false"
if isinstance(locales, list) and len(locales) > 0:
ext = self._append_locales(ext, locales)
res, content = self.restclient.process_request(
'proj_trans_stats', project_id, project_version,
headers=self.http_headers, extension=ext
)
return self.messages(res, content)

def get_doc_stats(self, project_id, project_version, doc_id, word=False):
def get_doc_stats(
self, project_id, project_version, doc_id, word=False, locales=None
):
ext = "?detail=true&word=true" if word else "?detail=true&word=false"
if isinstance(locales, list) and len(locales) > 0:
ext = self._append_locales(ext, locales)
res, content = self.restclient.process_request(
'doc_trans_stats', project_id, project_version, doc_id,
headers=self.http_headers, extension=ext
Expand Down

0 comments on commit 68a9879

Please sign in to comment.