Skip to content

Commit

Permalink
feat(project): build ok for linux, macos, windows
Browse files Browse the repository at this point in the history
  • Loading branch information
shanisma committed Feb 28, 2022
1 parent cc94970 commit cac480b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pyqt6 = "*"
colorlog = "*"
gitpython = "*"
pyyaml = "*"
serial = "*"
pyserial = "*"

[dev-packages]
ipython = "*"
Expand Down
5 changes: 5 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ tasks:
- mv dist/main.exe build_windows/flash_tool_win_amd64.exe
- yes | rm -rv build
- yes | rm -rv dist

build-local:
desc: run pyinstaller locally
cmds:
- pyinstaller --onefile --windowed main.py
70 changes: 49 additions & 21 deletions src/handlers/flash_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ def __init__(self, ui):
self.firmware_src_path = ""
self.list_serial_ports()
self.set_default_node_and_firmware()
self.known_flash_err_msg: list = ["Traceback", "FAILED", "Error"]
self.known_flash_err_msg: list = [
"Traceback",
"FAILED",
"Error",
"No such file or directory",
]

def set_default_node_and_firmware(self):
# set Sprinkler node and default firmware
Expand All @@ -40,11 +45,18 @@ def set_firmwares(self, node_type):
self.ui.firmwareList.addItems(
[getattr(_, "caption_name") for _ in SprinklerNodes]
)
self.node_type = node_type.text()

elif node_type.text() == "Water tank":
self.ui.firmwareList.addItems(
[getattr(_, "caption_name") for _ in WaterTankNodes]
)
self.node_type = node_type.text()
self.node_type = node_type.text()

else:
self.node_type = "node_type_not_handled"
self.firmware_src_path = "firmware_not_defined"
logger.warning(f"selected node type not handled")

def set_firmware_src_path(self, firmware_type):
logger.debug(f"selected firmware '{firmware_type.text()}'")
Expand Down Expand Up @@ -93,27 +105,43 @@ def list_serial_ports(self):

def flash(self):
err: bool = False
process = Popen(self.generate_cmd(), shell=True, stdout=PIPE, stderr=STDOUT)
with process.stdout:
try:
for line in iter(process.stdout.readline, b""):
line = line.decode("utf-8").strip()
self.ui.flashStatus.setStyleSheet("color: blue;")
self.ui.flashStatus.setText(line)

confirm = QMessageBox()
confirm.setWindowTitle("Flash")
confirm.setText("Continue flash")
confirm.setStandardButtons(
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
)

self.ui.flashStatus.setStyleSheet("color: blue;")
self.ui.flashStatus.setText("flash started")
self.ui.flashStatus.repaint()

if confirm.exec() == QMessageBox.StandardButton.Yes:
process = Popen(self.generate_cmd(), shell=True, stdout=PIPE, stderr=STDOUT)
with process.stdout:
try:
for line in iter(process.stdout.readline, b""):
line = line.decode("utf-8").strip()
self.ui.flashStatus.setStyleSheet("color: blue;")
self.ui.flashStatus.setText(line)
self.ui.flashStatus.repaint()
pio_logger.debug(f"{line}")
if any(_ in line for _ in self.known_flash_err_msg):
err = True
except CalledProcessError as e:
self.ui.flashStatus.setStyleSheet("background-color: red;")
self.ui.flashStatus.setText("process error: check 'pio.log' file")
self.ui.flashStatus.repaint()
pio_logger.debug(f"{line}")
if any(_ in line for _ in self.known_flash_err_msg):
err = True
except CalledProcessError as e:
pio_logger.error(f"{str(e)}")
if err:
self.ui.flashStatus.setStyleSheet("background-color: red;")
self.ui.flashStatus.setText("process error: check 'pio.log' file")
pio_logger.error(f"{str(e)}")
if err:
self.ui.flashStatus.setStyleSheet("background-color: red;")
self.ui.flashStatus.setText("flash failed: check 'pio.log' file")
else:
self.ui.flashStatus.setStyleSheet("background-color: green;")
self.ui.flashStatus.setText("Flashed successfully")
self.ui.flashStatus.setText("flash failed: check 'pio.log' file")
self.ui.flashStatus.repaint()
else:
self.ui.flashStatus.setStyleSheet("background-color: green;")
self.ui.flashStatus.setText("Flashed successfully")
self.ui.flashStatus.repaint()

def display_cmd(self):
logger.debug("cmd test clicked")
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/setup_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def is_pip_exist() -> bool:
def is_pio_exist() -> bool:
_platform = platform.system()

if _platform == ("Linux" or "Darwin"):
if _platform == "Linux" or "Darwin":
_ = shutil.which(PIO)
if _:
logger.info(f"{PIO} for {_platform} found: '{_}'")
Expand Down

0 comments on commit cac480b

Please sign in to comment.