diff --git a/CHANGELOG b/CHANGELOG index 6717a8a..0ccfc3c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -* Thu Jan 7 2016 Sundeep Anand +* Tue Jan 12 2016 Sundeep Anand - 1.4.1 - Implemented zanata init (ZNTA-780) - Bug ZNTA-853 - Crash when pushing local translations - Bug 1206995 - allow anonymous pull diff --git a/zanataclient/cmdbase.py b/zanataclient/cmdbase.py index 118fd78..05ffce3 100644 --- a/zanataclient/cmdbase.py +++ b/zanataclient/cmdbase.py @@ -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) diff --git a/zanataclient/initcmd.py b/zanataclient/initcmd.py index 9659885..1d44d40 100644 --- a/zanataclient/initcmd.py +++ b/zanataclient/initcmd.py @@ -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 = [] @@ -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) diff --git a/zanataclient/zanata.py b/zanataclient/zanata.py index 7aae9d6..feb43a6 100644 --- a/zanataclient/zanata.py +++ b/zanataclient/zanata.py @@ -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 """ diff --git a/zanataclient/zanatacmd.py b/zanataclient/zanatacmd.py index 6126997..0805ce7 100644 --- a/zanataclient/zanatacmd.py +++ b/zanataclient/zanatacmd.py @@ -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)) diff --git a/zanataclient/zanatalib/statservice.py b/zanataclient/zanatalib/statservice.py index 7ec374b..55335f8 100644 --- a/zanataclient/zanatalib/statservice.py +++ b/zanataclient/zanatalib/statservice.py @@ -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