Add sorter progress counters
The prompts used to arrive at this change since the previous commit Add a counter to the verplaats_bestaand file Any special observations that may be relevant for version management for this version. Be brief. Audit mode now reports folder position and scanned message progress every 250 messages without running live mailbox scripts from Codex.
This commit is contained in:
@@ -78,6 +78,7 @@ Scripts using shared IMAP folder handling:
|
||||
- Default mode is dry-run; real moves require `--uitvoeren` and an interactive `JA` confirmation.
|
||||
- Account selection is explicit with `--account <naam>`; use `--account backup` for the disposable backup mailbox. The script prints both the config account name and mailbox address before connecting.
|
||||
- `--audit` is available only in dry-run mode. It suppresses per-message dry-run lines and prints planned move counts grouped by source folder and destination folder for step 2 and step 3.
|
||||
- Long scans show progress counters: source folders are printed as `[current/total]`, and audit mode prints `Gescand: processed/total` every 250 messages and at folder completion.
|
||||
- IMAP `LIST`, `SELECT`, `UID SEARCH`, and `UID FETCH` aborts are logged and retried once after reconnecting. If reconnect also fails, the script records an `ABORT`/`ERROR` in `verplaats_log.json` instead of printing a Python traceback.
|
||||
- `MAP_RENAMES` is intentionally empty.
|
||||
- Source folders are selected by shared `list_folders()` plus `mail_routes.is_source_folder()`.
|
||||
|
||||
+15
-5
@@ -36,6 +36,7 @@ LOG_FILE = Path(__file__).parent / "verplaats_log.json"
|
||||
|
||||
DRY_RUN = "--uitvoeren" not in sys.argv
|
||||
AUDIT = "--audit" in sys.argv
|
||||
PROGRESS_INTERVAL = 250
|
||||
|
||||
|
||||
# Mappen die in één keer worden hernoemd/verplaatst (oud → nieuw).
|
||||
@@ -126,6 +127,11 @@ def print_audit(title: str, by_source: Counter, by_destination: Counter):
|
||||
print(f" {count:5d} {folder}")
|
||||
|
||||
|
||||
def print_progress(folder: str, processed: int, total: int):
|
||||
if processed == total or processed % PROGRESS_INTERVAL == 0:
|
||||
print(f" Gescand: {processed}/{total} | {folder}")
|
||||
|
||||
|
||||
def safe_select(session: ImapSession, log: dict, stap: str, folder: str, readonly: bool):
|
||||
for attempt in range(2):
|
||||
try:
|
||||
@@ -302,7 +308,7 @@ def stap2_bronmappen_routing(session: ImapSession, log: dict, dry: bool):
|
||||
totaal_mislukt = 0
|
||||
al_verwerkt = set(log.get("stap2_verwerkt", []))
|
||||
|
||||
for bron in bron_mappen:
|
||||
for folder_index, bron in enumerate(bron_mappen, start=1):
|
||||
status, data = safe_select(session, log, "stap2", bron, readonly=dry)
|
||||
mail = session.mail
|
||||
if status != "OK":
|
||||
@@ -312,7 +318,7 @@ def stap2_bronmappen_routing(session: ImapSession, log: dict, dry: bool):
|
||||
n = int(data[0])
|
||||
if n == 0:
|
||||
continue
|
||||
print(f" {bron}: {n} berichten")
|
||||
print(f" [{folder_index}/{len(bron_mappen)}] {bron}: {n} berichten")
|
||||
|
||||
status, data = safe_uid(
|
||||
session, log, "stap2", bron, "", "SEARCH", "ALL", readonly=dry
|
||||
@@ -331,6 +337,8 @@ def stap2_bronmappen_routing(session: ImapSession, log: dict, dry: bool):
|
||||
|
||||
for uid in ids:
|
||||
verwerkt += 1
|
||||
if AUDIT:
|
||||
print_progress(bron, verwerkt, len(ids))
|
||||
uid_str = uid.decode()
|
||||
log_key = f"{bron}:{uid_str}"
|
||||
if log_key in al_verwerkt:
|
||||
@@ -440,7 +448,7 @@ def stap3_facturen(session: ImapSession, log: dict, dry: bool):
|
||||
audit_by_source = Counter()
|
||||
audit_by_destination = Counter()
|
||||
|
||||
for bron in bron_mappen:
|
||||
for folder_index, bron in enumerate(bron_mappen, start=1):
|
||||
status, data = safe_select(session, log, "stap3", bron, readonly=dry)
|
||||
mail = session.mail
|
||||
if status != "OK":
|
||||
@@ -448,10 +456,10 @@ def stap3_facturen(session: ImapSession, log: dict, dry: bool):
|
||||
|
||||
n = int(data[0])
|
||||
if n == 0:
|
||||
print(f" {bron}: leeg")
|
||||
print(f" [{folder_index}/{len(bron_mappen)}] {bron}: leeg")
|
||||
continue
|
||||
|
||||
print(f" {bron}: {n} berichten")
|
||||
print(f" [{folder_index}/{len(bron_mappen)}] {bron}: {n} berichten")
|
||||
status, data = safe_uid(
|
||||
session, log, "stap3", bron, "", "SEARCH", "ALL", readonly=dry
|
||||
)
|
||||
@@ -464,6 +472,8 @@ def stap3_facturen(session: ImapSession, log: dict, dry: bool):
|
||||
mislukt = 0
|
||||
|
||||
for index, uid in enumerate(ids, start=1):
|
||||
if AUDIT:
|
||||
print_progress(bron, index, len(ids))
|
||||
status, data = safe_uid(
|
||||
session,
|
||||
log,
|
||||
|
||||
Reference in New Issue
Block a user