This is an automated email from the ASF dual-hosted git repository.

gstein pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git

commit 8db06f1d57c0230d4c309820cc435c7a559a73e3
Author: Greg Stein <[email protected]>
AuthorDate: Sun May 29 19:22:35 2022 -0500

    Start work on opening/closing an election.
    
    Collect all the data that will be used to (re)compute the opened_key
    value, in the new gather_election_data() method.
    
    Implement close() as a simple tweak to the METADATA table.
    
    Start the pattern for query cursors, and their usage.
---
 v3/steve/election.py | 40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/v3/steve/election.py b/v3/steve/election.py
index 30670f5..6c27e0d 100644
--- a/v3/steve/election.py
+++ b/v3/steve/election.py
@@ -37,12 +37,48 @@ class Election:
             '''UPDATE ISSUES SET salt = ? WHERE _ROWID_ = ?''')
         self.c_salt_record = self.db.add_statement(
             '''UPDATE RECORD SET salt = ? WHERE _ROWID_ = ?''')
+        self.c_close = self.db.add_statement(
+            'UPDATE METADATA SET closed = 1')
+
+        # Cursors for running queries.
+        self.q_metadata = self.db.add_query('metadata',
+            'SELECT * FROM METADATA')
+        self.q_issues = self.db.add_query('issues',
+            'SELECT * FROM ISSUES ORDER BY iid')
+        self.q_record = self.db.add_query('record',
+            'SELECT * FROM RECORD ORDER BY rid')
 
     def open(self):
-        pass
+        print('EDATA:', self.gather_election_data())
+
+    def gather_election_data(self):
+        "Gather a definition of this election for keying and anti-tamper."
+
+        # NOTE: separators and other zero-entropy constant chars are
+        # not included when assembling the data for hashing. This data
+        # is not intended for human consumption, anyways.
+
+        # NOTE: all assembly of rows must use a repeatable ordering.
+
+        md = self.q_metadata.first_row()
+        mdata = md.eid + md.title
+
+        self.q_issues.perform()
+        # Use an f-string to render "None" if a column is NULL.
+        idata = ''.join(f'{r.iid}{r.title}{r.description}{r.type}{r.kv}'
+                        for r in self.q_issues.fetchall())
+
+        self.q_record.perform()
+        rdata = ''.join(r.rid + r.email
+                        for r in self.q_record.fetchall())
+
+        return (mdata + idata + rdata).encode()
 
     def close(self):
-        pass
+        "Close an election."
+
+        # Simple tweak of the metadata.
+        self.c_close.perform()
 
     def add_salts(self):
         "Set the SALT column in the ISSUES and RECORD tables."

Reply via email to