Skip to content

Commit

Permalink
flake8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Apr 9, 2024
1 parent 5eaf5f1 commit f018abd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 38 deletions.
33 changes: 11 additions & 22 deletions MethodicConfigurator/backend_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
from logging import warning as logging_warning
from logging import error as logging_error
from json import load as json_load
from typing import Dict, List
from typing import Dict
from typing import List
from typing import Tuple
from zipfile import ZipFile
from annotate_params import BASE_URL, PARAM_DEFINITION_XML_FILE, Par
from annotate_params import get_xml_data
Expand Down Expand Up @@ -309,8 +311,7 @@ def zip_file_exists(self):
zip_file_path = self.zip_file_path()
return os_path.exists(zip_file_path) and os_path.isfile(zip_file_path)

def zip_files(self, wrote_complete, filename_complete, wrote_read_only, filename_read_only,
wrote_calibrations, filename_calibrations, wrote_non_calibrations, filename_non_calibrations): # pylint: disable=too-many-arguments
def zip_files(self, files_to_zip: List[Tuple[bool, str]]):
"""
Zips the intermediate parameter files that were written to, including specific summary files.
Expand All @@ -320,16 +321,8 @@ def zip_files(self, wrote_complete, filename_complete, wrote_read_only, filename
attempting to add it to the zip archive.
Parameters:
- wrote_complete (bool): Indicates if the complete parameter file was written.
- filename_complete (str): The name of the complete parameter file.
- wrote_read_only (bool): Indicates if the read-only parameter file was written.
- filename_read_only (str): The name of the read-only parameter file.
- wrote_calibrations (bool): Indicates if the calibration parameter file was written.
- filename_calibrations (str): The name of the calibration parameter file.
- wrote_non_calibrations (bool): Indicates if the non-calibration parameter file was written.
- filename_non_calibrations (str): The name of the non-calibration parameter file.
The method does not return any value. Instead, it logs the path of the created zip file upon completion.
- files_to_zip (List[Tuple[bool, str]]): A list of tuples, where each tuple contains a boolean
indicating if the file was written and a string for the filename.
"""
zip_file_path = self.zip_file_path()
with ZipFile(zip_file_path, 'w') as zipf:
Expand All @@ -344,15 +337,11 @@ def zip_files(self, wrote_complete, filename_complete, wrote_read_only, filename
if os_path.exists(file_path):
zipf.write(file_path, arcname=file_name)

# Add the newly created summary files
if wrote_complete:
zipf.write(os_path.join(self.vehicle_dir, filename_complete), arcname=filename_complete)
if wrote_read_only:
zipf.write(os_path.join(self.vehicle_dir, filename_read_only), arcname=filename_read_only)
if wrote_calibrations:
zipf.write(os_path.join(self.vehicle_dir, filename_calibrations), arcname=filename_calibrations)
if wrote_non_calibrations:
zipf.write(os_path.join(self.vehicle_dir, filename_non_calibrations), arcname=filename_non_calibrations)
for wrote, filename in files_to_zip:
if wrote:
file_path = os_path.join(self.vehicle_dir, filename)
if os_path.exists(file_path):
zipf.write(file_path, arcname=filename)

logging_info("Intermediate parameter files and summary files zipped to %s", zip_file_path)

Expand Down
33 changes: 18 additions & 15 deletions MethodicConfigurator/frontend_tkinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from PIL import Image
from PIL import ImageTk
from platform import system as platform_system
from typing import List
from typing import Tuple

from webbrowser import open as webbrowser_open # to open the blog post documentation

Expand Down Expand Up @@ -1038,7 +1040,12 @@ def write_summary_files(self):
"non-default_writable_calibrations.param", False)
wrote_non_calibrations = self.write_summary_file(non_default__writable_non_calibrations,
"non-default_writable_non-calibrations.param", False)
self.write_zip_file(wrote_complete, wrote_read_only, wrote_calibrations, wrote_non_calibrations)
files_to_zip = [
(wrote_complete, "complete.param"),
(wrote_read_only, "non-default_read-only.param"),
(wrote_calibrations, "non-default_writable_calibrations.param"),
(wrote_non_calibrations, "non-default_writable_non-calibrations.param")]
self.write_zip_file(files_to_zip)

def write_summary_file(self, param_dict: dict, filename: str, annotate_doc: bool):
should_write_file = True
Expand All @@ -1051,21 +1058,17 @@ def write_summary_file(self, param_dict: dict, filename: str, annotate_doc: bool
logging_info("Summary file %s written", filename)
return should_write_file

def write_zip_file(self, file1: bool, file2: bool, file3: bool, file4: bool):
def write_zip_file(self, files_to_zip: List[Tuple[bool, str]]):
should_write_file = True
if True or file1 or file2 or file3 or file4:
zip_file_path = self.local_filesystem.zip_file_path()
if self.local_filesystem.zip_file_exists():
should_write_file = messagebox.askyesno("Overwrite existing file",
f"{zip_file_path} file already exists.\nDo you want to overwrite it?")
if should_write_file:
self.local_filesystem.zip_files(file1, "complete.param",
file2, "non-default_read-only.param",
file3, "non-default_writable_calibrations.param",
file4, "non-default_writable_non-calibrations.param")
messagebox.showinfo("Parameter files zipped", "All relevant files have been zipped into the \n"
f"{zip_file_path} file.\n\nYou can now upload this file to the ArduPilot Methodic\n"
"Configuration Blog post on discuss.ardupilot.org.")
zip_file_path = self.local_filesystem.zip_file_path()
if self.local_filesystem.zip_file_exists():
should_write_file = messagebox.askyesno("Overwrite existing file",
f"{zip_file_path} file already exists.\nDo you want to overwrite it?")
if should_write_file:
self.local_filesystem.zip_files(files_to_zip)
messagebox.showinfo("Parameter files zipped", "All relevant files have been zipped into the \n"
f"{zip_file_path} file.\n\nYou can now upload this file to the ArduPilot Methodic\n"
"Configuration Blog post on discuss.ardupilot.org.")
return should_write_file

def close_connection_and_quit(self):
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def package_files(directory):
long_description = long_description.replace("(CODE_OF_CONDUCT.md", f"({prj_url}/blob/master/CODE_OF_CONDUCT.md")
long_description = long_description.replace("(LICENSE.md", f"({prj_url}/blob/master/LICENSE.md")
long_description = long_description.replace("(credits/CREDITS.md", f"({prj_url}/blob/master/credits/CREDITS.md")
long_description = long_description.replace("images/App_screenshot1.png", f"{prj_url}/raw/master/images/App_screenshot1.png")
long_description = long_description.replace("images/App_screenshot1.png",
f"{prj_url}/raw/master/images/App_screenshot1.png")

setup(
name='MethodicConfigurator',
Expand Down

0 comments on commit f018abd

Please sign in to comment.