From c217a1db8bd17fc023e809a8cafcdcf925316b31 Mon Sep 17 00:00:00 2001 From: Tony Breeds Date: Fri, 14 Jul 2017 12:05:21 +1000 Subject: [PATCH] Make get_email() work with python3 If you try to build the docs with python3 you'll see something ending with: ValueError: Couldn't find gerrit account with 'b'dmccowan@cisco.com'' This is because the default encoding from subprocess.Popen() under python3 is bytes() which then fails to work with the gerrit API. Check we have a text_type and decode() if needed. Change-Id: Iccbc891a33d15ef82ddbc913549e64547a967195 --- openstack_election/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openstack_election/utils.py b/openstack_election/utils.py index 7ffd4e6c..af970ca1 100644 --- a/openstack_election/utils.py +++ b/openstack_election/utils.py @@ -21,6 +21,7 @@ import pickle import pytz import re import requests +import six import subprocess import time import yaml @@ -77,7 +78,12 @@ def gerrit_query(url): def get_email(filepath): cmd = ["git", "log", "--follow", "--format=%aE", filepath] git = subprocess.Popen(cmd, stdout=subprocess.PIPE) - return git.stdout.readlines()[-1][:-1] + email = git.stdout.readlines()[-1][:-1] + # Force to text_type in py2 or py3 + if isinstance(email, six.text_type): + return email + else: + return email.decode('utf-8') def get_gerrit_account(email):