election/openstack_election/config.py
Ghanshyam Mann aae968f2af Migrate election tooling to release versions
From Antelope (2023.1) onwards, primary identifier
of any release is release version instead of name[1],
we should use release versions in the election tooling
also.

This migrate the election tooling to use the release version
As release repo is not fully migrated to release version yet,
we still need to use the release name to fetch the data from
release repo.

Keeping relaese version as float so that we edit the
configuration file with release version a float not
with string even string is passed.

All the election tools/script/flow has been tested with it and
it is working now.

[1] https://governance.openstack.org/tc/reference/release-naming.html

Change-Id: Ia8a60a9514b1dca5ac97ed8099c34c6c6c7d24e2
2023-03-03 11:01:20 -08:00

42 lines
1.4 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import datetime
import pytz
import yaml
TIME_FMT = "%b %d, %Y %H:%M %Z"
ISO_FMT = "%Y-%m-%dT%H:%M"
# Load configuration.yaml and create datetime objects
def parse_datetime(iso_format):
date = datetime.datetime.strptime(iso_format, ISO_FMT)
return date.replace(tzinfo=pytz.utc)
def load_conf():
conf = yaml.safe_load(open('configuration.yaml'))
conf['release'] = str(conf['release'])
for key in ('start', 'end', 'email_deadline'):
date = parse_datetime(conf['timeframe'][key])
conf['timeframe'][key] = date
conf['timeframe'][key+'_str'] = date.strftime(TIME_FMT)
for event in conf['timeline']:
for key in ('start', 'end'):
date = parse_datetime(event[key])
event[key] = date
event[key+'_iso'] = date.strftime(ISO_FMT)
event[key+'_str'] = date.strftime(TIME_FMT)
return conf