omd2tex.tools.search module#
- omd2tex.tools.search.find_file(filename: str, search_path: str | None = None) str | None[source]#
Locate a file by name within a search path honoring ignore rules.
Performs a recursive walk starting from the configured or provided directory, skipping ignored directories, and returns the first path matching the target filename (case-sensitive first, then case-insensitive).
- Parameters:
filename – Target filename; path segments are stripped, and trailing whitespace is trimmed.
search_path – Optional root directory to search; defaults to Settings.Export.search_dir, expanded to user home. Falls back to CWD if None.
- Returns:
Absolute path to the first matching file, or None if not found.
- Raises:
FileNotFoundError – If the search directory does not exist.
- Side Effects:
Prints a not-found message to stdout if no match is located; prints comparison errors if they occur.
- omd2tex.tools.search.find_file_flexible(filename: str, search_path: str | None = None) str | None[source]#
Search for a file using multiple case variants and Unicode normalization.
Recursively walks the provided directory (or the current working directory by default) and compares several case and normalization variants of the target to discover matches.
- Parameters:
filename – Filename to search for; whitespace is preserved except for trailing and leading characters handled externally.
search_path – Optional root directory; defaults to the current working directory if None. Path is expanded for user home.
- Returns:
Absolute path of the first matched file, or None if no match is found.
- Raises:
FileNotFoundError – If the search directory does not exist.
- Side Effects:
Prints progress and results to stdout during the search.
- omd2tex.tools.search.list_files_in_directory(search_path: str | None = None) None[source]#
Print directory tree contents for debugging.
Walks the provided directory (or CWD) and prints folders and files with indentation reflecting depth to stdout.
- Parameters:
search_path – Optional directory to list; expanded for user home. Defaults to CWD when None.
- Returns:
None
- Side Effects:
Writes directory listings to stdout.
- omd2tex.tools.search.get_image_dimensions(file_path: str) Tuple[int, int] | None[source]#
Return width and height of an image file if available.
Attempts to open the file with Pillow and extract its dimensions; returns None if the file is missing or cannot be opened.
- Parameters:
file_path – Absolute or relative path to the image file.
- Returns:
Tuple of (width, height) in pixels when the file is readable, otherwise None.
- Raises:
None explicitly; FileNotFoundError is caught and suppressed. –