From: Shane Jaroch Date: Fri, 23 Jan 2026 19:58:17 +0000 (-0500) Subject: move to python script (no shell) X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=82518a63992b6b465da6081a6d2a54d2f54708db;p=gamesguru%2Fgetmyancestors-tests-data.git move to python script (no shell) --- diff --git a/regenerate_fixtures.py b/regenerate_fixtures.py new file mode 100755 index 0000000..93e5e62 --- /dev/null +++ b/regenerate_fixtures.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python3 +import glob +import json +import os +import shutil +import subprocess +import sys +from datetime import datetime, timedelta + + +def update_expiration(cache_dir): + """Updates the 'expires' field in requests-cache JSON fixtures to 5 years in the future.""" + print(f"Updating expiration dates in {cache_dir}...") + + # Calculate 5 years in the future from now + future_date = datetime.now() + timedelta(days=365 * 5) + # Format as ISO 8601 string, e.g., '2030-01-23T19:30:00' + # requests-cache typically uses this format + future_expires = future_date.isoformat() + + json_files = glob.glob(os.path.join(cache_dir, "requests", "*.json")) + count = 0 + + for filepath in json_files: + try: + with open(filepath, "r", encoding="utf-8") as f: + data = json.load(f) + + # Check if it has an 'expires' field (requests-cache format) + if "expires" in data: + data["expires"] = future_expires + + with open(filepath, "w", encoding="utf-8") as f: + json.dump(data, f, indent=4) + count += 1 + except Exception as e: + print(f"Error processing {filepath}: {e}") + + print(f"Updated {count} fixture files in {cache_dir}.") + + +def run_generation(user, person_id, cache_dir, output_file): + """Runs the getmyancestors command.""" + print("========================================") + print(f"Regenerating Fixtures for {person_id}") + print(f"Cache Dir: {cache_dir}") + print("========================================") + + # Clean cache dir + if os.path.exists(cache_dir): + shutil.rmtree(cache_dir) + os.makedirs(cache_dir, exist_ok=True) + + # Construct command + # Using sys.executable to ensure we use the same python interpreter + cmd = [ + sys.executable, + "-m", + "coverage", + "run", + "-p", + "-m", + "getmyancestors", + "--verbose", + "-u", + user, + "-i", + person_id, + "-a", + "3", + "-d", + "2", + "--rate-limit", + "1", + "--cache", + "--no-cache-control", + "--creation-date", + "2026-01-01T12:00:00", + "-o", + output_file, + ] + + env = os.environ.copy() + env["GMA_CACHE_DIR"] = cache_dir + + try: + subprocess.run(cmd, env=env, check=True) + except subprocess.CalledProcessError as e: + print(f"Error running command: {e}") + sys.exit(1) + + # Update expiration after generation + update_expiration(cache_dir) + + +def main(): + user = os.environ.get("FAMILYSEARCH_USER") + if not user: + print("Error: FAMILYSEARCH_USER not set") + sys.exit(1) + + testdata_dir = os.path.dirname(os.path.abspath(__file__)) + tmp_dir = os.path.join(testdata_dir, ".tmp") + os.makedirs(tmp_dir, exist_ok=True) + + # Part 1: Ada (29HC-P5H) + run_generation( + user=user, + person_id="29HC-P5H", + cache_dir=os.path.join(testdata_dir, "fixtures", "part1"), + output_file=os.path.join(tmp_dir, "regenerate_part1.ged"), + ) + + print("") + + # Part 2: Marie Curie (LC5H-V1Z) + run_generation( + user=user, + person_id="LC5H-V1Z", + cache_dir=os.path.join(testdata_dir, "fixtures", "part2"), + output_file=os.path.join(tmp_dir, "regenerate_part2.ged"), + ) + + print("") + print("✅ Regeneration Complete!") + print(f"Part 1 Cache: {os.path.join(testdata_dir, 'fixtures', 'part1')}") + print(f"Part 2 Cache: {os.path.join(testdata_dir, 'fixtures', 'part2')}") + + +if __name__ == "__main__": + main() diff --git a/regenerate_fixtures.sh b/regenerate_fixtures.sh deleted file mode 100755 index 729bb4b..0000000 --- a/regenerate_fixtures.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -set -e - -# Ensure credentials are present -if [ -z "$FAMILYSEARCH_USER" ]; then - echo "Error: FAMILYSEARCH_USER not set" - exit 1 -fi - -testdata_dir="$(dirname "$0")" -mkdir -p "$testdata_dir/.tmp" - -echo "========================================" -echo "Regenerating Fixtures for Part 1 (Ada)" -echo "========================================" -export GMA_CACHE_DIR="$testdata_dir/fixtures/part1" -# Clear existing to ensure clean state -rm -rf "$GMA_CACHE_DIR" -mkdir -p "$GMA_CACHE_DIR" - -python3 -m coverage run -p -m getmyancestors --verbose \ - -u "$FAMILYSEARCH_USER" \ - -i "29HC-P5H" \ - -a 3 -d 2 \ - --rate-limit 1 --cache --no-cache-control \ - --creation-date "2026-01-01T12:00:00" \ - -o "$testdata_dir/.tmp/regenerate_part1.ged" - -echo "" -echo "========================================" -echo "Regenerating Fixtures for Part 2 (Marie Curie)" -echo "========================================" -export GMA_CACHE_DIR="$testdata_dir/fixtures/part2" -# Clear existing -rm -rf "$GMA_CACHE_DIR" -mkdir -p "$GMA_CACHE_DIR" - -python3 -m coverage run -p -m getmyancestors --verbose \ - -u "$FAMILYSEARCH_USER" \ - -i "LC5H-V1Z" \ - -a 3 -d 2 \ - --rate-limit 1 --cache --no-cache-control \ - --creation-date "2026-01-01T12:00:00" \ - -o "$testdata_dir/.tmp/regenerate_part2.ged" - -echo "" -echo "✅ Regeneration Complete!" -echo "Part 1 Cache: $testdata_dir/fixtures/part1" -echo "Part 2 Cache: $testdata_dir/fixtures/part2"