Improve randomisation of answers
This commit is contained in:
+18
-4
@@ -37,6 +37,7 @@ import secrets
|
||||
import shutil
|
||||
import sqlite3
|
||||
import sys
|
||||
import time
|
||||
import unicodedata
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
@@ -1790,6 +1791,19 @@ def resolve_shuffle_seed(seed):
|
||||
return secrets.token_hex(16)
|
||||
|
||||
|
||||
def build_epoch_for_rebuild(override_epoch=None):
|
||||
"""Return the modification epoch for a multiple-choice deck build.
|
||||
|
||||
A normal rebuild reshuffles the answer HTML, so its notes must carry
|
||||
the current time for Anki to recognize the imported copies as newer.
|
||||
`--epoch` remains the explicit escape hatch for byte-reproducible
|
||||
builds, where the caller intentionally fixes every timestamp.
|
||||
"""
|
||||
if override_epoch is not None:
|
||||
return int(override_epoch)
|
||||
return int(time.time())
|
||||
|
||||
|
||||
def build_all(data_dir, out_dir, seed, override_epoch=None, explanations_path=None):
|
||||
"""Build every category's `.apkg` and return their result dicts.
|
||||
|
||||
@@ -1798,8 +1812,8 @@ def build_all(data_dir, out_dir, seed, override_epoch=None, explanations_path=No
|
||||
`.apkg` each. Raises `AnkiBuildError` on configuration / catalog
|
||||
/ explanation-schema problems.
|
||||
"""
|
||||
edition_dir, manifest, catalog = load_latest_catalog(data_dir)
|
||||
build_epoch = build_epoch_from_manifest(manifest, override_epoch)
|
||||
edition_dir, _manifest, catalog = load_latest_catalog(data_dir)
|
||||
build_epoch = build_epoch_for_rebuild(override_epoch)
|
||||
explanations = load_explanations(
|
||||
explanations_path if explanations_path is not None
|
||||
else DEFAULT_EXPLANATIONS_PATH
|
||||
@@ -1866,8 +1880,8 @@ def _parse_args(argv):
|
||||
type=int,
|
||||
default=None,
|
||||
help=(
|
||||
"override the package timestamp epoch; by default this is "
|
||||
"derived from manifest.json's fetched_at"
|
||||
"override the package and note modification timestamp epoch; "
|
||||
"by default the current rebuild time is used"
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
|
||||
Reference in New Issue
Block a user