adsfolio.pdf.registry
Root-scoped views over the central PDF catalog.
- class adsfolio.pdf.registry.CentralPdfRegistry(directory)[source]
Bases:
objectRoot-scoped view over the user-wide
PdfCatalog.- Parameters:
directory (Path)
- count_files_matching(**filters)[source]
Count current locations matching supported catalog filters.
Counts in SQL when the filters allow it. The source filter reads metadata JSON. Identification groups also read current identity evidence. duplicates_only compares digests and paper records across the filtered rows, so those still load the records.
- find_file_by_current_path(root, current_path)[source]
Return the current location at
current_path.- Parameters:
root (pathlib.Path)
current_path (str)
- Return type:
- find_file_by_relative_path(root, relative_path)[source]
Return the current location at a root-relative path.
- Parameters:
root (pathlib.Path)
relative_path (str)
- Return type:
- find_files_by_bibcode(root, bibcode)[source]
Return unchanged current locations carrying one Bibcode.
- iter_files(status=None, *, include_missing=False)[source]
Yield locations in this root, optionally including missing history.
- query_files(*, order_by='relative_path', descending=False, secondary_order_by=None, tertiary_order_by=None, limit=None, offset=0, **filters)[source]
Return sorted and paged current locations for this root.
- query_records(**filters)[source]
Return filtered current locations in catalog order, without sorting.
Catalog order is
relative_pathand then location identifier. query_files sorts this list.
- reconcile_file_facts(root, *, recursive=True, cancelled=None)[source]
Refresh current filesystem facts without deleting locations.
- Parameters:
root (pathlib.Path)
recursive (bool)
cancelled (collections.abc.Callable[[], bool] | None)
- Return type:
- record_facts()[source]
Return count facts for every current location in this root.
The result is cached until the catalog change token changes, so repeated view and status counts parse the metadata JSON once.
- Return type:
- record_rename(root, relative_path, current_path, new_relative_path=None)[source]
Record a location move while retaining attachment identity.
- Parameters:
root (pathlib.Path)
relative_path (str)
current_path (str)
new_relative_path (str | None)
- Return type:
- refresh_local_files(*, recursive=True, cancelled=None)[source]
Scan local PDFs, update changed facts, and retain missing history.
No ADS queries or file renames are performed. Files with changed facts are hashed before discovery updates those facts. Incomplete directory scans raise an error instead of marking unseen paths missing.
- Parameters:
recursive (bool)
cancelled (collections.abc.Callable[[], bool] | None)
- Return type:
- replace_file_metadata(root, relative_path, metadata)[source]
Replace one attachment’s local metadata.
- Parameters:
root (pathlib.Path)
relative_path (str)
metadata (collections.abc.Mapping[str, Any])
- Return type:
- replace_file_metadata_if_unchanged(root, relative_path, metadata, expected_record, *, expected_document=<object object>, changed_fields=None, allow_reviewed_stale_recovery=False)[source]
Replace metadata if the catalog still matches the original record.
See
PdfCatalog.replace_file_metadata_if_unchangedfor the snapshot requirements and transaction behavior.- Parameters:
root (pathlib.Path)
relative_path (str)
metadata (collections.abc.Mapping[str, Any])
expected_record (collections.abc.Mapping[str, Any])
expected_document (collections.abc.Mapping[str, Any] | None)
changed_fields (collections.abc.Collection[str] | None)
allow_reviewed_stale_recovery (bool)
- Return type:
- search_documents()[source]
Return exact and folded search documents for current locations.
Each entry holds the location identifier and the outputs of record_search_document and fold_document. Do not change them.
- search_location_keys(search, *, exact=False, wildcards=False, fields=())[source]
Return
(root, location_id)keys that match the query search.The keys equal the result of the catalog search filter with the same options. fields names the fields that plain terms search. See adsfolio.pdf.search.document_matches for the rules. The last result is cached until the catalog change token changes.
- set_ads_document_metrics(bibcode, metrics)[source]
Store cached citation metrics.
- Parameters:
bibcode (str)
metrics (collections.abc.Mapping[str, int | None])
- Return type:
- sort_records(records, *, order_by='relative_path', descending=False, secondary_order_by=None, tertiary_order_by=None)[source]
Sort records in place with the query_files order rules.
Empty values sort last for each key, in both directions.
- update_file_status(root, relative_path, status)[source]
Update one attachment’s local status.
- Parameters:
root (pathlib.Path)
relative_path (str)
status (str)
- Return type:
- upsert_ads_document(document, *, source)[source]
Cache one ADS document in the central catalog.
- Parameters:
document (collections.abc.Mapping[str, Any])
source (str)
- Return type:
None
- upsert_ads_documents(documents, *, source)[source]
Cache ADS documents atomically in the central catalog.
- Parameters:
documents (list[collections.abc.Mapping[str, Any]])
source (str)
- Return type:
None
- class adsfolio.pdf.registry.CentralPdfRegistryState(registry)[source]
Bases:
objectState adapter exposing current catalog locations to CLI workflows.
- Parameters:
registry (CentralPdfRegistry)
- property files: dict[str, dict[str, Any]][source]
Return current location metadata keyed by relative path.
- property identify_settings: adsfolio.pdf.identify_settings.IdentifySettings | None[source]
Return root-specific reusable Identify settings.
- property rename_settings: RenameSettings | None[source]
Return root-specific reusable Rename settings.
- set_current_filename(relative_path, current_filename)[source]
Record a move between current root-relative locations.
- set_identify_profile(profile)[source]
Set identify profile metadata and report whether it changed.
- Parameters:
profile (collections.abc.Mapping[str, Any] | None)
- Return type:
- set_identify_settings(settings)[source]
Set root-specific reusable Identify settings.
- Parameters:
settings (adsfolio.pdf.identify_settings.IdentifySettings | None)
- Return type:
- set_rename_settings(settings)[source]
Set root-specific reusable Rename settings.
- Parameters:
settings (RenameSettings | None)
- Return type:
- class adsfolio.pdf.registry.FileReconciliation(scanned, updated, missing)[source]
Bases:
objectSummary of filesystem facts reconciled against one catalog root.
- class adsfolio.pdf.registry.LibraryRefresh(scanned, added, updated, moved, restored, missing)[source]
Bases:
objectCount local file changes while retaining missing-location history.
- adsfolio.pdf.registry.PdfRegistry
- adsfolio.pdf.registry.PdfRegistryState
- class adsfolio.pdf.registry.RecordFact(root, location_id, group, source, sha256, document_id=None, edition='')[source]
Bases:
NamedTupleHold the record values that view and status counts need.
The fields are the canonical library root, the catalog location identifier, the value of
identification_group(record), the saved metadata source, and the current content digest. A missing source or digest is an empty string.- Parameters:
- adsfolio.pdf.registry.duplicate_kinds(keys)[source]
Return the duplicate kind of each PDF, or
""for a single copy.- Parameters:
keys (collections.abc.Sequence[tuple[str, int | None, str]]) –
(sha256, document_id, edition)of each PDF, with the edition from pdf_edition. An empty digest or a None document does not group.- Returns:
DUPLICATE_SAME_FILE when another PDF has the same bytes. Otherwise DUPLICATE_SAME_PAPER when another PDF links to the same paper record and is the same edition. An unknown edition matches either edition. A preprint and its published edition are not duplicates.
- Return type:
- adsfolio.pdf.registry.mark_duplicates(records)[source]
Return the duplicate records with
duplicate_kindandduplicate_group.Copies of one paper share a group, including copies with the same bytes. When ADS links a preprint and its published edition to one record, each edition forms its own group. Copies without a paper record group by bytes.
- adsfolio.pdf.registry.merge_ads_metadata(existing, document)[source]
Merge nonempty ADS values while retaining locally locked fields.
- Parameters:
existing (collections.abc.Mapping[str, Any]) – Metadata currently stored for one attachment.
document (collections.abc.Mapping[str, Any]) – ADS document returned for the attachment’s Bibcode.
- Returns:
Merged metadata.
- Return type:
- adsfolio.pdf.registry.migrate_sidecar(json_path, registry)[source]
Import legacy root data without modifying its source files.
- Parameters:
json_path (pathlib.Path)
registry (adsfolio.pdf.registry.CentralPdfRegistry)
- Return type:
- adsfolio.pdf.registry.open_registry_state(directory)[source]
Open a central catalog state view for one library root.
- Parameters:
directory (pathlib.Path)
- Return type:
- adsfolio.pdf.registry.order_duplicate_groups(records)[source]
Keep each duplicate group together and number the groups, in place.
The first copy of each group keeps its place in the current sort. The other copies of that group follow it. Groups are numbered from 1 in that order, in
duplicate_group_number.
- adsfolio.pdf.registry.pdf_edition(record)[source]
Return
"preprint","published", or""from the PDF’s own IDs.The identity proof lists the identifiers that the PDF states. A journal DOI marks the published edition. An arXiv ID or arXiv DOI alone marks the preprint. ADS can link both editions to one paper record.
- Parameters:
record (collections.abc.Mapping[str, Any])
- Return type:
- adsfolio.pdf.registry.stored_count(record, key)[source]
Return a saved non-negative count from a catalog record, or None.
The record’s own field is read first, then its metadata mapping. Whole numbers (int) and strings of decimal digits are accepted. Booleans, negative numbers, floats, and other text, including malformed digit strings, are treated as unknown, so a missing value is never reported as zero. The count is the value saved at the last ADS lookup, refresh, or manual edit, not a live ADS value.
PdfRegistry is the compatibility alias of
CentralPdfRegistry; PdfRegistryState aliases
CentralPdfRegistryState.
REGISTRY_FILENAME names the legacy per-root database. Use
adsfolio.pdf.catalog.CATALOG_FILENAME for the central catalog filename.