Automate the 'date' in setup_election_config

Current we need to pass 'date' as mandatory argument
in setup_election_config CLI and it is sometime confusion
on what date to pass.

This commit automatically select the end date of release if
date is not passed. This will help to generate the correct
election dates without worry about release date to pass.

Change-Id: I444885800b26ca84689d550f81bbe349eae3bd30
This commit is contained in:
Ghanshyam Mann 2021-07-21 12:33:31 -05:00
parent c4667d15ef
commit 500d2c1ed0
1 changed files with 21 additions and 3 deletions

View File

@ -97,17 +97,29 @@ def validate_tc_charter(election_type, release_schedule,
exit(1)
def select_release_end_date(release_schedule):
date = None
for week in release_schedule.get('cycle', []):
if 'x-final' in week.get('x-project', {}):
date = datetime.datetime.strptime(
week['end'],
"%Y-%m-%d").replace(tzinfo=pytz.UTC)
return date
def main():
parser = argparse.ArgumentParser(description=('Given a release '
'date pick some dates for '
'the election'))
# We can't rely on the current schedule being codified in the releases
# repo so just get the date from the command line.
parser.add_argument('date', type=valid_date, help='in the form YYYY-MM-DD')
parser.add_argument('release', help='release name')
parser.add_argument('type', choices=['TC', 'PTL', 'combined'])
parser.add_argument('--tc-seats', default=4, choices=['4', '5'],
help='number of TC seats up for election')
# If date is not passed in command line then, this script will
# automatically pick the release end date.
parser.add_argument('--date', default=None, type=valid_date,
help='Date from release schedule in the form '
'YYYY-MM-DD')
args = parser.parse_args()
args.date = args.date
@ -124,6 +136,12 @@ def main():
# be very early but don't assume that.
idx = names.index(args.release) if args.release in names else -1
# If date is not passed to this script then autimatically
# select the release end date.
if (args.date is None):
schedule = utils.get_schedule_data(names[idx+1])
args.date = select_release_end_date(schedule)
# Given the release history:
# Stein, Rocky[0], Queens[1], Pike[2], Ocata[3]
# For the Stein elections candidates come from the previous 2 cycles so: