Refactor core/chdman.py for improved logging, structure, and safety#1
Merged
Soundchazer2k merged 1 commit intodev-1.2.0from May 22, 2025
Merged
Refactor core/chdman.py for improved logging, structure, and safety#1Soundchazer2k merged 1 commit intodev-1.2.0from
Soundchazer2k merged 1 commit intodev-1.2.0from
Conversation
This commit implements a series of improvements to the CHDMAN wrapper module based on a detailed code review.
Key changes include:
1. **Logging:** Replaced all `print()` statements and direct file writes (`error.log`) with Python's standard `logging` module. Implemented basic logging configuration.
2. **Refactoring `CHDManWorker.run()`:** Broke down the large `run()` method into smaller, more manageable private helper methods (`_perform_pre_flight_checks`, `_build_chdman_command`, `_execute_and_monitor_process`, `_handle_process_completion`) to enhance readability and maintainability.
3. **Consolidated Compression Validation:** Centralized compression algorithm validation and correction logic into a static method `CHDManWorker._sanitize_compression_algorithms`, removing duplicated code.
4. **Refactored `CHDMan` Instance Creation:** Introduced a `_create_and_start_instance` helper method in `CHDMan` to streamline the creation and setup of `CHDManWorker` instances.
5. **Concurrency Safety:**
* Made the `get_chd_manager()` singleton initialization thread-safe using `threading.Lock`.
* Added `threading.Lock` to protect access to `CHDMan.active_instances`.
6. **Style and Minor Fixes (PEP 8):**
* Addressed overly long lines.
* Moved local imports to the module's top level where appropriate.
* Standardized string quote usage.
* Replaced `os.system()` calls with `subprocess.run()`.
* Removed an unused `find_chdman()` call in `CHDManager.execute_all_operations()`.
* Refined error handling for compression algorithm sanitization to consistently raise `CHDManError`.
These changes aim to make the module more robust, easier to debug, and more maintainable, while preserving existing functionality, including operations relevant to the compression tab, batch processor, and batch tab.
There was a problem hiding this comment.
Hi @Soundchazer2k! 👋
Your private repo does not have access to Sourcery.
Please upgrade to continue using Sourcery ✨
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit implements a series of improvements to the CHDMAN wrapper module based on a detailed code review.
Key changes include:
print()statements and direct file writes (error.log) with Python's standardloggingmodule. Implemented basic logging configuration.CHDManWorker.run(): Broke down the largerun()method into smaller, more manageable private helper methods (_perform_pre_flight_checks,_build_chdman_command,_execute_and_monitor_process,_handle_process_completion) to enhance readability and maintainability.CHDManWorker._sanitize_compression_algorithms, removing duplicated code.CHDManInstance Creation: Introduced a_create_and_start_instancehelper method inCHDManto streamline the creation and setup ofCHDManWorkerinstances.get_chd_manager()singleton initialization thread-safe usingthreading.Lock.threading.Lockto protect access toCHDMan.active_instances.os.system()calls withsubprocess.run().find_chdman()call inCHDManager.execute_all_operations().CHDManError.These changes aim to make the module more robust, easier to debug, and more maintainable, while preserving existing functionality, including operations relevant to the compression tab, batch processor, and batch tab.