adsfolio.pdf.renamer
Template-based PDF renaming engine.
- exception adsfolio.pdf.renamer.MissingTemplateFieldsError(missing_fields)[source]
Bases:
ValueErrorReport missing metadata required by a filename template.
- Parameters:
missing_fields (collections.abc.Sequence[str])
- Return type:
None
- class adsfolio.pdf.renamer.PdfRenamer(client=None)[source]
Bases:
objectRender rename templates and optionally apply them to disk.
- Parameters:
client (ADSClient | None)
- batch_rename(sidecar, template='{authors}_{bibcode}-{title}', dry_run=True, author_format='surname_initials', max_authors=3, authors_when_truncated=1, char_policy='keep', move_resolved_from=None, move_resolved_to=None, author_separator='+', author_truncation_suffix='+', current_filenames=None)[source]
Rename tracked PDFs with verified ADS or ready local metadata.
If both move directories are supplied, resolved files below
move_resolved_fromare placed inmove_resolved_toafter the new filename is rendered. Non-ADS records are renamed in place.Records whose identity is not proven by the PDF itself are skipped, including in a dry run. Their tracked names and reasons are kept in
identity_refuseduntil the next call.current_filenames, when supplied, limits processing to these current paths relative to the catalog root. An empty sequence selects no files. A Unicode alias selects a current path only when its directory entry proves the match.
Use the selected template without substitution. Skip records when a referenced field has no value. Record unchanged targets in unchanged and other skipped reasons in skipped. Clear these mappings for each call.
- Parameters:
sidecar (adsfolio.pdf.sidecar.Sidecar)
template (str)
dry_run (bool)
author_format (str)
max_authors (int)
authors_when_truncated (int)
char_policy (str)
move_resolved_from (pathlib.Path | None)
move_resolved_to (pathlib.Path | None)
author_separator (str)
author_truncation_suffix (str)
current_filenames (collections.abc.Sequence[str] | None)
- Return type:
- rename_tracked_file(state, source_path, metadata, template='{authors}_{bibcode}-{title}', dry_run=True, author_format='surname_initials', max_authors=3, authors_when_truncated=1, char_policy='keep', author_separator='+', author_truncation_suffix='+', target_directory=None)[source]
Plan or apply a rename for one tracked resolved PDF.
- Raises:
MissingTemplateFieldsError – The template references fields without metadata. No move occurs.
- Parameters:
state (adsfolio.pdf.sidecar.Sidecar)
source_path (pathlib.Path)
metadata (collections.abc.Mapping[str, Any])
template (str)
dry_run (bool)
author_format (str)
max_authors (int)
authors_when_truncated (int)
char_policy (str)
author_separator (str)
author_truncation_suffix (str)
target_directory (pathlib.Path | None)
- Return type:
- adsfolio.pdf.renamer.identity_view(record)[source]
Flatten a catalog or sidecar record into one metadata mapping.
Nested
metadatavalues are overridden by top-level record fields, matching how readiness checks read the same record.
- adsfolio.pdf.renamer.recover_stale_record(state, relative_path, *, apply)[source]
Reverify a changed PDF against its cached ADS record.
- Parameters:
state (adsfolio.pdf.sidecar.Sidecar | adsfolio.pdf.registry.CentralPdfRegistryState) – Library state containing the tracked PDF and cached ADS record.
relative_path (str) – Current PDF path relative to the library root.
apply (bool) – Persist a verified recovery when True. False only checks and plans.
- Returns:
Flat, rename-ready metadata, or None if recovery does not apply.
- Return type:
dict or None
- Raises:
IdentityValidationError – The cached record, PDF, catalog, or shared locations cannot be verified.
Notes
Recovery also handles a changed file before the catalog scans it. It never fetches a provider record or changes the shared document metadata. Recovery retains prior identity proof and content versions as history.
- adsfolio.pdf.renamer.verify_record_identity(pdf_path, record, *, sha256=None, manual_confirmation=False, manual_conflict_override=False, provider_document=None, state=None, client=None, providers=(DoiProvider.ADS, DoiProvider.CROSSREF, DoiProvider.DATACITE))[source]
Check that a stored record is proven to describe the PDF’s bytes.
- Parameters:
pdf_path (Path) – PDF that a write or rename would affect.
record (Mapping[str, Any]) – Catalog or sidecar record, flat or with nested
metadata.sha256 (str, optional) – Digest the proof must be tied to. Defaults to the record’s digest.
manual_confirmation (bool, optional) – Set only for an explicit, user-reviewed confirmation of an unknown identity. A known conflict is never overridden.
manual_conflict_override (bool, optional) – Allow a specifically reviewed conflict with a fresh provider record.
provider_document (Mapping[str, Any], optional) – Authoritative raw ADS or provider document for the record. When omitted, a valid stored proof is checked first. Otherwise, the cached ADS document for the record’s primary Bibcode is used when available.
state (Sidecar or CentralPdfRegistryState, optional) – Catalog state used to look up the cached document.
client (ADSClient, optional) – Client for automatically fetching an unverifiable stored ADS candidate. Valid stored proofs need no request. An omitted client keeps checks local.
providers (sequence of DoiProvider, optional) – Enabled providers. Automatic ADS requests require ADS in this sequence.
- Returns:
Identity proof to store under
IDENTITY_KEY.- Return type:
- Raises:
IdentityValidationError – If the identity is conflicting or cannot be independently verified.
adsfolio.config.ADSError – An enabled ADS record lookup failed.