Use gerrit fullname in list rendering

This change improves candidate list rendering using gerrit to retrieve fullname.
The list rendering now uses the openstack_election libraries and some part
have been refactored accordingly.

Change-Id: Iccba3e4c529740758323b51548a2144fc7c77879
This commit is contained in:
Tristan Cacqueray 2016-09-12 08:37:13 +00:00
parent 9d96997e72
commit 6698ffe6a4
7 changed files with 50 additions and 33 deletions

View File

@ -14,20 +14,11 @@
"""
import os
import subprocess
from jinja2 import FileSystemLoader
from jinja2.environment import Environment
BASE_URL = "http://git.openstack.org/cgit/openstack/election"
PATH_PREFIX = 'candidates'
def get_fullname(filepath, exceptions):
if filepath in exceptions:
return exceptions[filepath]
return subprocess.Popen(["git", "log", "--format=%aN", filepath],
stdout=subprocess.PIPE).stdout.readlines()[-1][:-1]
from openstack_election import utils
def render_template(template, data, **kwargs):
@ -38,18 +29,12 @@ def render_template(template, data, **kwargs):
return template.render(data)
def build_candidates_list(election):
project_list = os.listdir(os.path.join(PATH_PREFIX, election))
def build_candidates_list(election=utils.SERIES_NAME):
project_list = os.listdir(os.path.join(utils.CANDIDATE_PATH, election))
project_list.sort()
exceptions = {}
for e in open("exceptions.txt").readlines():
if e[0] == "#" or ":" not in e:
continue
exceptions[e.split(':')[0]] = " ".join(e.split(':')[1:])[:-1].strip()
candidates_lists = {}
for project in project_list:
project_prefix = os.path.join(PATH_PREFIX, election, project)
project_prefix = os.path.join(utils.CANDIDATE_PATH, election, project)
file_list = filter(
lambda x: x.endswith(".txt"),
os.listdir(unicode(project_prefix)),
@ -59,9 +44,10 @@ def build_candidates_list(election):
filepath = os.path.join(project_prefix, candidate_file)
candidates_list.append(
{
'path': filepath,
'url': '%s/openstack/election/plain/%s' % (utils.CGIT_URL,
filepath),
'ircname': os.path.basename(filepath)[:-4],
'fullname': get_fullname(filepath, exceptions)
'fullname': utils.get_fullname(filepath)
})
candidates_list.sort(key=lambda x: x['fullname'])
@ -73,7 +59,7 @@ def build_candidates_list(election):
def render_list(list_type, candidates_list):
output_file = os.path.join(PATH_PREFIX, "%s.rst" % list_type)
output_file = os.path.join(utils.CANDIDATE_PATH, "%s.rst" % list_type)
template_name = "%s.jinja" % list_type
template_dir = os.path.join(".", "doc", "source", "_exts")
with open(output_file, "w") as out:
@ -87,9 +73,7 @@ def render_list(list_type, candidates_list):
def build_lists(app):
# TODO: make election a parameter
election = 'ocata'
candidates_list = build_candidates_list(election)
candidates_list = build_candidates_list()
render_list("ptl", candidates_list)
render_list("tc", candidates_list)

View File

@ -4,7 +4,7 @@
* {{ project.replace('_', ' ') }}
{% for candidate in candidates[project] %}
* `{{ candidate['fullname'] }} ({{ candidate['ircname'] }}) <http://git.openstack.org/cgit/openstack/election/plain/{{ candidate['path'] }}>`_
* `{{ candidate['fullname'] }} ({{ candidate['ircname'] }}) <{{ candidate['url'] }}>`_
{% endfor %}
{% endif %}{% endfor %}

View File

@ -2,5 +2,5 @@
======================
{% for candidate in candidates['TC'] %}
* `{{ candidate['fullname'] }} ({{ candidate['ircname'] }}) <http://git.openstack.org/cgit/openstack/election/plain/{{ candidate['path'] }}>`_
* `{{ candidate['fullname'] }} ({{ candidate['ircname'] }}) <{{ candidate['url'] }}>`_
{% endfor %}

View File

@ -1 +0,0 @@
../../candidates/

View File

@ -8,14 +8,14 @@
OpenStack Election
==================
.. include:: ./candidates/events.rst
.. include:: ../../candidates/events.rst
See `Election system`_, `PTL details`_ and `TC details`_.
Below is the official list of candidates for the current round.
.. TODO: Change from ptl.rst to tc.rst when TC rounds starts
.. include:: ./candidates/ptl.rst
.. include:: ../../candidates/ptl.rst
.. TODO: Adds TC Results and a link to `TC Candidates list`_ when TC candidacies are over
.. TODO: Adds PTL Results and a link to `PTL Candidates list`_ when PTL candidacies are over

View File

@ -59,7 +59,7 @@ def check_candidate(project_name, email, projects, limit=1):
(repo_name, email))
for review in utils.get_reviews(query):
url = ('%s/%s/commit/?id=%s' % (
utils.BASE_URL, review['project'],
utils.CGIT_URL, review['project'],
review['current_revision']))
print('%2d: %s %s' %
(found, pretty_datetime(review['submitted']),

View File

@ -20,6 +20,7 @@ import os
import pickle
import pytz
import requests
import subprocess
import time
import urllib
import yaml
@ -37,9 +38,21 @@ PROJECTS_TAG = 'sept-2016-elections'
CANDIDATE_PATH = 'candidates'
GERRIT_BASE = 'https://review.openstack.org'
ELECTION_REPO = 'openstack/election'
BASE_URL = 'https://git.openstack.org/cgit'
CGIT_URL = 'https://git.openstack.org/cgit'
PROJECTS_URL = ('%s/openstack/governance/plain/reference/projects.yaml' %
(BASE_URL))
(CGIT_URL))
exceptions = None
# Generic functions
def load_exceptions():
global exceptions
exceptions = {}
for e in open("exceptions.txt").readlines():
if e[0] == "#" or ":" not in e:
continue
exceptions[e.split(':')[0]] = " ".join(e.split(':')[1:])[:-1].strip()
# Gerrit functions
@ -56,6 +69,27 @@ def gerrit_query(url):
return data
def get_email(filepath):
return subprocess.Popen(["git", "log", "--format=%aE", filepath],
stdout=subprocess.PIPE).stdout.readlines()[-1][:-1]
def get_fullname(filepath):
# Check if filepath is an exception
if exceptions is None:
load_exceptions()
if filepath in exceptions:
return exceptions[filepath]
# Otherwise query gerrit using git log email
email = get_email(filepath)
url = '%s/accounts/%s' % (GERRIT_BASE, email)
fullname = gerrit_query(url)['name']
# Return capitalized name
return u" ".join(map(unicode.capitalize, fullname.split()))
def get_reviews(query):
opts = ['CURRENT_REVISION', 'CURRENT_FILES', 'DETAILED_ACCOUNTS']
opts_str = '&o=%s' % ('&o='.join(opts))