Refactor sphinx candidate list rendering

This change now uses the new schema to render candidate
list including ircname.

Moreover this change introduces an exceptions.txt file to
manage candidacies exception where a candidate isn't the
git commit author of a candidacy statement. In such case
the candidacy needs to be manually verified and the candidate
fullname needs to be added to the exceptions.txt.

Change-Id: I2e59f4880d34cdb09321dbc110ecf5a103f81dff
This commit is contained in:
Tristan Cacqueray 2016-09-08 04:36:34 +00:00
parent 5137e30f6a
commit 2709992456
5 changed files with 36 additions and 7 deletions

View File

@ -14,6 +14,7 @@
""" """
import os import os
import subprocess
from jinja2 import FileSystemLoader from jinja2 import FileSystemLoader
from jinja2.environment import Environment from jinja2.environment import Environment
@ -22,6 +23,13 @@ BASE_URL = "http://git.openstack.org/cgit/openstack/election"
PATH_PREFIX = 'candidates' 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]
def render_template(template, data, **kwargs): def render_template(template, data, **kwargs):
template_dir = kwargs.get('template_dir', os.getcwd()) template_dir = kwargs.get('template_dir', os.getcwd())
loader = FileSystemLoader(template_dir) loader = FileSystemLoader(template_dir)
@ -33,17 +41,30 @@ def render_template(template, data, **kwargs):
def build_candidates_list(election): def build_candidates_list(election):
project_list = os.listdir(os.path.join(PATH_PREFIX, election)) project_list = os.listdir(os.path.join(PATH_PREFIX, election))
project_list.sort() 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 = {} candidates_lists = {}
for project in project_list: for project in project_list:
project_prefix = os.path.join(PATH_PREFIX, election, project) project_prefix = os.path.join(PATH_PREFIX, election, project)
candidates_list = filter( file_list = filter(
lambda x: x.endswith(".txt"), lambda x: x.endswith(".txt"),
os.listdir(unicode(project_prefix)), os.listdir(unicode(project_prefix)),
) )
candidates_list = [os.path.join(project_prefix, c) candidates_list = []
for c in candidates_list] for candidate_file in file_list:
candidates_list.sort() filepath = os.path.join(project_prefix, candidate_file)
candidates_list.append(
{
'path': filepath,
'ircname': os.path.basename(filepath)[:-4],
'fullname': get_fullname(filepath, exceptions)
})
candidates_list.sort(key=lambda x: x['fullname'])
candidates_lists[project] = candidates_list candidates_lists[project] = candidates_list
return {'election': election, return {'election': election,

View File

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

View File

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

View File

@ -10,13 +10,15 @@ OpenStack Election
.. include:: ./candidates/events.rst .. include:: ./candidates/events.rst
See `Election system`_ `PTL details`_ and `TC details`_. See `Election system`_, `PTL details`_ and `TC details`_.
Below is the official list of candidates for the current round. Below is the official list of candidates for the current round.
.. TODO: Change from ptl.rst to tc.rst when TC rounds starts .. 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
Election Officials Election Officials
================== ==================
@ -144,6 +146,10 @@ candidates/<cycle>/TC/<candidate_irc_name>.txt.
The candidacy is then confirmed by elections officials through gerrit vote. The candidacy is then confirmed by elections officials through gerrit vote.
See above `How to submit a candidacy`_ documentation. See above `How to submit a candidacy`_ documentation.
.. TODO: add PTL Candidates list when PTL elections are over
.. TODO: add TC Candidates list when TC elections are over
.. seealso:: .. seealso::
See the `Election Officiating Guidelines`_ page in the wiki for details on the See the `Election Officiating Guidelines`_ page in the wiki for details on the

2
exceptions.txt Normal file
View File

@ -0,0 +1,2 @@
# This file contains exception for manually verified candidates
# <filename>: <real name>