all2md.cli.watch
Watch mode implementation for all2md CLI.
This module provides file system monitoring for automatic conversion of files when they change. Supports bidirectional conversion between any formats.
- class all2md.cli.watch.ConversionEventHandler
Bases:
FileSystemEventHandlerFile system event handler for watch mode.
- Parameters:
paths_to_watch (List[Path]) – Paths to monitor (files or directories)
output_dir (Path) – Directory to write converted files
options (Dict[str, Any]) – Conversion options
format_arg (str) – Source format specification
target_format (DocumentFormat, default "markdown") – Target output format
output_extension (str, optional) – Custom output file extension (overrides target_format default)
transforms (list, optional) – Transform instances to apply
debounce_seconds (float, default 1.0) – Debounce delay in seconds
preserve_structure (bool, default False) – Whether to preserve directory structure
recursive (bool, default False) – Whether to watch directories recursively
exclude_patterns (List[str], optional) – Patterns to exclude from processing
Initialize the conversion event handler with watch settings.
- __init__(paths_to_watch: List[Path], output_dir: Path, options: Dict[str, Any], format_arg: Literal['auto', 'archive', 'asciidoc', 'ast', 'bbcode', 'chm', 'csv', 'docx', 'dokuwiki', 'eml', 'enex', 'epub', 'fb2', 'html', 'ini', 'ipynb', 'jinja', 'json', 'latex', 'markdown', 'mbox', 'mediawiki', 'mhtml', 'odp', 'ods', 'odt', 'openapi', 'org', 'outlook', 'pdf', 'plaintext', 'pptx', 'rst', 'rtf', 'sourcecode', 'textile', 'toml', 'webarchive', 'xlsx', 'yaml', 'zip'], target_format: Literal['auto', 'archive', 'asciidoc', 'ast', 'bbcode', 'chm', 'csv', 'docx', 'dokuwiki', 'eml', 'enex', 'epub', 'fb2', 'html', 'ini', 'ipynb', 'jinja', 'json', 'latex', 'markdown', 'mbox', 'mediawiki', 'mhtml', 'odp', 'ods', 'odt', 'openapi', 'org', 'outlook', 'pdf', 'plaintext', 'pptx', 'rst', 'rtf', 'sourcecode', 'textile', 'toml', 'webarchive', 'xlsx', 'yaml', 'zip'] = 'markdown', output_extension: str | None = None, transforms: list | None = None, debounce_seconds: float = 1.0, preserve_structure: bool = False, recursive: bool = False, exclude_patterns: List[str] | None = None) None
Initialize the conversion event handler with watch settings.
- should_process(file_path: str) bool
Check if file should be processed.
- Parameters:
file_path (str) – Path to the file
- Returns:
True if file should be processed
- Return type:
bool
- convert_file(file_path: str) None
Convert a single file.
- Parameters:
file_path (str) – Path to the file to convert
- on_modified(event: Any) None
Handle file modification events.
- Parameters:
event (FileSystemEvent) – The file system event
- on_created(event: Any) None
Handle file creation events.
- Parameters:
event (FileSystemEvent) – The file system event
- on_moved(event: Any) None
Handle file move events.
- Parameters:
event (FileSystemEvent) – The file system event
- all2md.cli.watch.run_watch_mode(paths: List[Path], output_dir: Path, options: Dict[str, Any], format_arg: Literal['auto', 'archive', 'asciidoc', 'ast', 'bbcode', 'chm', 'csv', 'docx', 'dokuwiki', 'eml', 'enex', 'epub', 'fb2', 'html', 'ini', 'ipynb', 'jinja', 'json', 'latex', 'markdown', 'mbox', 'mediawiki', 'mhtml', 'odp', 'ods', 'odt', 'openapi', 'org', 'outlook', 'pdf', 'plaintext', 'pptx', 'rst', 'rtf', 'sourcecode', 'textile', 'toml', 'webarchive', 'xlsx', 'yaml', 'zip'], target_format: Literal['auto', 'archive', 'asciidoc', 'ast', 'bbcode', 'chm', 'csv', 'docx', 'dokuwiki', 'eml', 'enex', 'epub', 'fb2', 'html', 'ini', 'ipynb', 'jinja', 'json', 'latex', 'markdown', 'mbox', 'mediawiki', 'mhtml', 'odp', 'ods', 'odt', 'openapi', 'org', 'outlook', 'pdf', 'plaintext', 'pptx', 'rst', 'rtf', 'sourcecode', 'textile', 'toml', 'webarchive', 'xlsx', 'yaml', 'zip'] = 'markdown', output_extension: str | None = None, transforms: list | None = None, debounce: float = 1.0, preserve_structure: bool = False, recursive: bool = False, exclude_patterns: List[str] | None = None) int
Run watch mode to monitor and convert files on change.
Supports bidirectional conversion between any formats using the convert() API.
- Parameters:
paths (List[Path]) – Paths to monitor (files or directories)
output_dir (Path) – Directory to write converted files
options (Dict[str, Any]) – Conversion options
format_arg (DocumentFormat) – Source format specification
target_format (DocumentFormat, default "markdown") – Target output format for conversion
output_extension (str, optional) – Custom output file extension (overrides target_format default)
transforms (list, optional) – Transform instances to apply
debounce (float, default 1.0) – Debounce delay in seconds
preserve_structure (bool, default False) – Whether to preserve directory structure
recursive (bool, default False) – Whether to watch directories recursively
exclude_patterns (List[str], optional) – Patterns to exclude from processing
- Returns:
Exit code (0 for success)
- Return type:
int