X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=tools%2Fdistchanges%2Fgerritquery.py;h=b6cddc5cdb22fd526cab938ec18994779f6609b8;hb=605ceec45e75d1e008131e1fec051e29ef71cc50;hp=4e2c6cdd42cb00f687312931e174b5c3d524b4d2;hpb=4a40e16a42945cbed78c5d26541ab2f96fb2fd34;p=integration%2Ftest.git diff --git a/tools/distchanges/gerritquery.py b/tools/distchanges/gerritquery.py index 4e2c6cdd42..b6cddc5cdb 100644 --- a/tools/distchanges/gerritquery.py +++ b/tools/distchanges/gerritquery.py @@ -74,12 +74,15 @@ class GerritQuery: @staticmethod def print_safe_encoding(string): - if type(string) == unicode: - encoding = 'utf-8' - if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding: - encoding = sys.stdout.encoding - return string.encode(encoding or 'utf-8', 'replace') - else: + try: + if type(string) == unicode: + encoding = 'utf-8' + if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding: + encoding = sys.stdout.encoding + return string.encode(encoding or 'utf-8', 'replace') + else: + return str(string) + except: return str(string) def run_command_status(self, *argv, **kwargs): @@ -281,13 +284,14 @@ class GerritQuery: :return list: Lines of the JSON """ lines = [] - for line in changes.split("\n"): - if line.find('"type":"error","message"') != -1: - logger.warn("there was a query error") - continue - if line.find('stats') == -1: + skipped = 0 + for i, line in enumerate(changes.split("\n")): + if line.find('"grantedOn":') != -1: lines.append(line) - logger.debug("get_gerrit_lines: found %d lines", len(lines)) + else: + logger.debug("skipping: {}".format(line)) + skipped += 1 + logger.debug("get_gerrit_lines: found {} lines, skipped: {}".format(len(lines), skipped)) return lines def get_gerrits(self, project, changeid=None, limit=1, msg=None, status=None, comments=False, commitid=None): @@ -326,6 +330,6 @@ class GerritQuery: return gerrits try: sorted_gerrits = sorted(gerrits, key=itemgetter('grantedOn'), reverse=True) - except KeyError, e: + except KeyError as e: logger.warn("KeyError exception in %s, %s", project, str(e)) return sorted_gerrits