How devthayron/download-organizer works
Purpose and principal workflow
This Python application organizes a user’s Downloads folder by file extension. The external caller is the user or an optional systemd service launching python main.py; startup loads configuration and sorts existing files, then Watchdog observes filesystem events. New or changed files are checked for stable size before being moved into a configured category or Outros.
Components
Application startup and monitoring
• Command-line entry point — main.py: Exposes main(), calls the watcher startup function, and exits with an error status if startup fails.
• Download monitor and startup orchestration — monitor.py: Loads JSON configuration, creates the organizer, processes existing downloads, configures Watchdog, handles filesystem events, and runs stability checks in background threads.
• Watchdog observer library — requirements.txt: Declares the Watchdog dependency used by the monitor to observe filesystem changes. The README documents systemd as an optional way to launch the application.
Organization and filesystem operations
• Download organizer — organizador.py: Validates rules, maps extensions to folders, ignores directories and selected files, creates category folders, avoids overwrites, and moves files using shutil.
• Downloads folder and files — null repository path: The user’s filesystem directory is the application’s input, monitored location, and destination for organized files.
Configuration and diagnostics
• Organization configuration — config.json: Holds the category rules, ignored extensions, and stability interval consumed by the monitor and organizer.
• Logging setup — logger.py: Configures console and file logging; the monitor invokes it during watcher startup.
• User or systemd service — null repository path: The external launcher starts the application; the README documents direct invocation and optional systemd operation.
Relationships
• User or systemd service -> Command-line entry point: launches python main.py; the README documents both direct execution and systemd ExecStart.
• Command-line entry point -> Download monitor and startup orchestration: calls iniciar_watcher(); main.py imports it from the monitor module.
• Download monitor and startup orchestration -> Logging setup: configures logging at startup; iniciar_watcher() calls configurar_logger().
• Download monitor and startup orchestration -> Organization configuration: reads and parses the JSON configuration; carregar_config() opens the configured path.
• Download monitor and startup orchestration -> Download organizer: constructs the organizer with loaded rules and calls it to process existing files.
• Download organizer -> Downloads folder and files: reads directory entries and moves eligible files into category folders; the implementation uses Path and shutil.move.
• Download monitor and startup orchestration -> Watchdog observer library: registers the event handler on the Downloads path and starts the observer.
• Watchdog observer library -> Download monitor and startup orchestration: dispatches created, modified, and moved events to handler methods; the handler schedules stability checks.
• Downloads folder and files -> Watchdog observer library: supplies filesystem changes from the watched directory.
• Download monitor and startup orchestration -> Downloads folder and files: checks file existence and size over time, then asks the organizer to move a stable file.
Coverage limits
The source excerpts establish the main workflow and direct calls. They do not establish the contents of config.json or details of runtime behavior across platforms; systemd support is documented, not implemented in the sampled repository code.
Main entry points: monitor.py Download monitor · main.py CLI entry point · requirements.txt Watchdog observer · organizador.py Download organizer
Components 9
Startup and monitoring
- CLI entry point
main.py - Download monitor
monitor.py - Watchdog observer
requirements.txt
File organization
- Download organizer
organizador.py - Downloads folder · User filesystem input, monitored location, and destination for organized files.
Configuration and diagnostics
- Organization config
config.json - Logging setup
logger.py
Other components
- User
- systemd service · Optional launcher documented in the README.
Connections 11
- User → CLI entry point: launches · Runs python main.py.
- systemd service → CLI entry point: launches · Optional systemd ExecStart.
- CLI entry point → Download monitor: starts watcher · Calls iniciar_watcher().
- Download monitor → Logging setup: configures logging · Calls configurar_logger() at startup.
- Download monitor → Organization config: loads rules · Reads and parses the JSON configuration.
- Download monitor → Download organizer: organizes files · Constructs the organizer with loaded rules and processes existing files.
- Download organizer → Downloads folder: moves files · Reads directory entries and moves eligible files into category folders.
- Download monitor → Watchdog observer: starts observer · Registers the event handler on the Downloads path.
- Watchdog observer → Download monitor: dispatches events · Created, modified, and moved events trigger stability checks.
- Downloads folder → Watchdog observer: emits changes · Filesystem changes from the watched directory.
- Download monitor → Downloads folder: checks stability · Checks file existence and size over time before requesting a move.