-
-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automx fix #525
base: master
Are you sure you want to change the base?
Automx fix #525
Conversation
…script Added zipfile and urllib.request in 'postwhite.py' to improve the handling of archive downloads and extractions from specified repositories. Refactored 'install_from_archive' to increase the script's portability by removing the 'wget' command, improving reliability across different systems. Included robust error handling to improve user experience and problem diagnosis in case of download or extraction failures.
Modified archive extraction process in automx.py to include verification and error handling functionality. Now, the output of the unzip command is captured to confirm that the directory was successfully created. An exception is raised if the directory is not created, allowing early detection and diagnosis of potential issues.
Enhanced modoboa_installer/utils.py to now include two new methods, info and warning, to print messages in different colors. Also added a more robust download_remote_file function that downloads a file from a remote server with specified retries and exceptional download failure handling. This function was then used to replace previous ad-hoc download implementations for improved code reusability and readability.
…raction Modified the `utils.download_remote_file` function in `utils.py` to return the absolute path of the downloaded file instead of relative path. This change extends the robustness as it makes sure we are always unzipping the downloaded file even if cwd changes. Also, adjusted the `automx.py` script to use the absolute path returned from the download function when extracting the file. This ensures that the correct file gets extracted regardless of current working directory.
In utils.py, the wget command was updated in the exec_cmd function. Previously, the command did not specify the output file for the downloaded content. Now, a new target parameter has been added to the wget command to direct the download to a specific file. This change is done to provide more control over the file handling process within the function.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #525 +/- ##
==========================================
- Coverage 54.40% 53.73% -0.67%
==========================================
Files 10 10
Lines 761 776 +15
==========================================
+ Hits 414 417 +3
- Misses 347 359 +12
☔ View full report in Codecov by Sentry. |
printcolor(message, BLUE) | ||
|
||
|
||
def warning(message): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're at it, could change evey instance of utils.printcolor(*,YELLOW/BLUE) to these functions?
@@ -67,3 +86,6 @@ def restore(self): | |||
if os.path.isfile(postwhite_backup_configuration): | |||
utils.copy_file(postwhite_backup_configuration, self.config_dir) | |||
utils.success("postwhite.conf restored from backup") | |||
|
|||
def download_file(self, url, destination): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you create a new function to download a file using urllib instead of using the function you're adding in the utils.py file?
Description of the issue/feature this PR addresses:
The
_setup_venv
method in the existing codebase has been experiencing intermittent SSL connection issues when attempting to download a file usingwget
. This problem has been causing the method to fail occasionally, preventing the successful setup of a virtual environment. Additionally, the method assumes the downloaded archive will be located in a certain directory without verifying the file's existence, leading to potential errors during the unzipping process.Current behavior before PR:
_setup_venv
method useswget
to download a file, but if an SSL connection issue occurs, the method fails without retrying the download.Desired behavior after PR is merged:
download_remote_file
has been introduced to handle file downloads, with the capability to retry the download a specified number of times in case of failures, mitigating the impact of intermittent SSL connection issues._setup_venv
method now utilizes thedownload_remote_file
method to handle the file download, ensuring that the file exists before proceeding to unzip it.download_remote_file
method ensures the target directory exists or creates it if necessary, and returns the absolute path of the downloaded file, providing more robust file handling and aiding in troubleshooting if issues arise in the future.