-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from stratofax/development
Extraction code validates and generates ballots, passes GitHub Actions testing, but pytest still fails locally. Good enough for a merge.
- Loading branch information
Showing
12 changed files
with
885 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import logging | ||
from datetime import datetime | ||
from pathlib import Path | ||
|
||
from electos.ballotmaker.ballots.ballot_layout import build_ballot | ||
from electos.ballotmaker.constants import PROGRAM_NAME | ||
from electos.ballotmaker.data.models import ElectionData | ||
|
||
logging.getLogger(__name__) | ||
|
||
|
||
def get_election_header(election: ElectionData) -> dict: | ||
"""extract the shared data for ballot headers""" | ||
name = election.name | ||
end_date = election.end_date | ||
election_type = election.type | ||
return { | ||
"Name": name, | ||
"EndDate": end_date, | ||
"Type": election_type, | ||
} | ||
|
||
|
||
def build_ballots(election: ElectionData) -> Path: | ||
|
||
# create the directories needed | ||
# TODO: clean up datetime code: https://github.com/TrustTheVote-Project/BallotLab/pull/113#discussion_r973609852 | ||
now = datetime.now() | ||
date_time = now.strftime("%Y_%m_%dT%H%M%S") | ||
home_dir = Path.home() | ||
program_dir = Path(home_dir, PROGRAM_NAME) | ||
new_ballot_dir = Path(program_dir, date_time) | ||
logging.info(f"New ballots will be saved in {new_ballot_dir}") | ||
# TODO: Use original EDF file name (no ext) in output dir | ||
# See: https://github.com/TrustTheVote-Project/BallotLab/pull/113#discussion_r973776838 | ||
Path(new_ballot_dir).mkdir(parents=True, exist_ok=False) | ||
# TODO: list actual dir in log output: https://github.com/TrustTheVote-Project/BallotLab/pull/113#discussion_r973610221 | ||
logging.info("Output directory created.") | ||
election_header = get_election_header(election) | ||
|
||
for ballot_data in election.ballot_styles: | ||
logging.info(f"Generating ballot for {ballot_data.id}") | ||
new_ballot_name = build_ballot( | ||
ballot_data, election_header, new_ballot_dir | ||
) | ||
return new_ballot_dir |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.