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 c8f504cdc711f3e992e790ac9dec53e3ceca34a5 Author: Greg Stein <[email protected]> AuthorDate: Sat Oct 4 02:30:10 2025 -0500 add script to load some fake data for Elections/Issues --- v3/pyproject.toml | 2 ++ v3/server/bin/load_fakedata.py | 81 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/v3/pyproject.toml b/v3/pyproject.toml index 59ea29b..6201cd1 100644 --- a/v3/pyproject.toml +++ b/v3/pyproject.toml @@ -30,6 +30,8 @@ asfquart = ">=0.1.12" ### not sure about this. not needed for server operation. ### let the import fail, and the user can do a pip install. #python-ldap = "^3.0.0" +### same. let this fail, if the user needs it. +#faker = "^37.8.0" [tool.poetry.extras] server = ["asfquart", ] # Core dependencies for apache-steve[server] diff --git a/v3/server/bin/load_fakedata.py b/v3/server/bin/load_fakedata.py new file mode 100755 index 0000000..9f82455 --- /dev/null +++ b/v3/server/bin/load_fakedata.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +# Load a bunch of fake data into the database, for stuff to work with. + +import sys +import sqlite3 +import pathlib +import logging + +import faker # pip3 install faker + +_LOGGER = logging.getLogger(__name__) + +THIS_DIR = pathlib.Path(__file__).resolve().parent +DB_FNAME = THIS_DIR.parent / 'steve.db' + +sys.path.insert(0, str(THIS_DIR.parent.parent)) +import steve.election + +### we shouldn't need this. do so, for now. +import steve.crypto + +# Do we need individual instances? Use a singleton for now. +FAKE = faker.Faker() + + +def main(count=10, owner_pid=None): + for _ in range(count): + gen_election(owner_pid) + + +def gen_election(owner_pid=None, issue_count=10): + title = FAKE.sentence() + if not owner_pid: + owner_pid = random_owner() + #owner_pid = 'gstein' + e = steve.election.Election.create(DB_FNAME, title, owner_pid) + _LOGGER.info(f'Created election[E:{e.eid}]: "{title}",' + f' by owner "{owner_pid}"') + + for _ in range(issue_count): + title = FAKE.sentence() + description = FAKE.paragraph() + vtype = 'yna' ### something else? + kv = None ### something else? + + ### grr. this should be internal + iid = steve.crypto.create_id() + e.add_issue(iid, title, description, vtype, kv) + _LOGGER.info(f'[E:{e.eid}]: created issue[I:{iid}]: "{title}"') + + +def random_owner(): + "Pick a random PID from those available." + + conn = sqlite3.connect(DB_FNAME) + cursor = conn.execute('SELECT pid FROM person ORDER BY RANDOM() LIMIT 1') + pid = cursor.fetchone()[0] + conn.close() + + return pid + + +if __name__ == '__main__': + logging.basicConfig(level=logging.INFO) + main()
