From 257d3e3e08478618110c28c7edf53f38653c7571 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Wed, 14 Sep 2016 11:02:38 +0000 Subject: [PATCH] Add configuration.yaml This change refactor events.yaml into something more generic and usable by openstack_election module Change-Id: I26e25cb31c60645742baba1e73f8da9043029381 --- configuration.yaml | 9 +++++++++ doc/source/_exts/events.py | 13 ++++--------- events.yaml | 9 --------- openstack_election/utils.py | 1 + tox.ini | 2 +- 5 files changed, 15 insertions(+), 19 deletions(-) create mode 100644 configuration.yaml delete mode 100644 events.yaml diff --git a/configuration.yaml b/configuration.yaml new file mode 100644 index 00000000..fef160dd --- /dev/null +++ b/configuration.yaml @@ -0,0 +1,9 @@ +timelines: + - {'date': '2016-09-12T00:00', 'name': 'PTL nomination starts'} + - {'date': '2016-09-18T23:45', 'name': 'PTL nomination ends'} + - {'date': '2016-09-19T00:00', 'name': 'PTL elections begins'} + - {'date': '2016-09-25T23:45', 'name': 'PTL elections ends'} + - {'date': '2016-09-26T00:00', 'name': 'TC nomination starts'} + - {'date': '2016-10-01T23:45', 'name': 'TC nomination ends'} + - {'date': '2016-10-03T00:00', 'name': 'TC elections begins'} + - {'date': '2016-10-08T23:45', 'name': 'TC elections ends'} diff --git a/doc/source/_exts/events.py b/doc/source/_exts/events.py index 86c564a9..f93a86ce 100644 --- a/doc/source/_exts/events.py +++ b/doc/source/_exts/events.py @@ -14,23 +14,21 @@ """ import os -import yaml import calendar import time from jinja2 import FileSystemLoader from jinja2.environment import Environment -PATH_PREFIX = 'candidates' +from openstack_election import utils def build_timer(app): app.add_javascript("event_timer.js") - data = yaml.load(open("events.yaml").read()) # add better text for tabulatted planning now = time.time() outdated = '*' - for ev in data: + for ev in utils.conf['timelines']: d, h = ev['date'].split('T') epoch_time = calendar.timegm( time.strptime(ev['date'], "%Y-%m-%dT%H:%M")) @@ -45,18 +43,15 @@ def build_timer(app): outdated = '' ev['date_str'] = "%s%s, %s UTC%s" % (outdated, d, h, outdated) ev['name_str'] = "%s%s%s" % (outdated, ev['name'], outdated) - output_file = os.path.join(PATH_PREFIX, "events.rst") + output_file = os.path.join(utils.CANDIDATE_PATH, "events.rst") with open(output_file, "w") as out: template_dir = os.path.join(".", "doc", "source", "_exts") loader = FileSystemLoader(template_dir) env = Environment(trim_blocks=True, loader=loader) template = env.get_template("events.jinja") - out.write(template.render({'events': data})) + out.write(template.render({'events': utils.conf['timelines']})) def setup(app): - if not os.path.isfile("events.yaml"): - app.info('No events.yaml found, not loading events_timer extension') - return app.info('loading events_timer extension') app.connect('builder-inited', build_timer) diff --git a/events.yaml b/events.yaml deleted file mode 100644 index 5b9dbf96..00000000 --- a/events.yaml +++ /dev/null @@ -1,9 +0,0 @@ ---- -- {'date': '2016-09-12T00:00', 'name': 'PTL nomination starts'} -- {'date': '2016-09-18T23:45', 'name': 'PTL nomination ends'} -- {'date': '2016-09-19T00:00', 'name': 'PTL elections begins'} -- {'date': '2016-09-25T23:45', 'name': 'PTL elections ends'} -- {'date': '2016-09-26T00:00', 'name': 'TC nomination starts'} -- {'date': '2016-10-01T23:45', 'name': 'TC nomination ends'} -- {'date': '2016-10-03T00:00', 'name': 'TC elections begins'} -- {'date': '2016-10-08T23:45', 'name': 'TC elections ends'} diff --git a/openstack_election/utils.py b/openstack_election/utils.py index da3e451f..6d4746de 100644 --- a/openstack_election/utils.py +++ b/openstack_election/utils.py @@ -43,6 +43,7 @@ CGIT_URL = 'https://git.openstack.org/cgit' PROJECTS_URL = ('%s/openstack/governance/plain/reference/projects.yaml' % (CGIT_URL)) +conf = yaml.load(open('configuration.yaml')) exceptions = None diff --git a/tox.ini b/tox.ini index 95f18864..143287fa 100644 --- a/tox.ini +++ b/tox.ini @@ -15,7 +15,7 @@ deps = -r{toxinidir}/requirements.txt commands = python setup.py testr --slowest --testr-args="{posargs}" [testenv:linters] -commands = yamllint events.yaml +commands = yamllint configuration.yaml flake8 [testenv:venv]