mirror of
https://github.com/MikronMIK32/mik32-uploader.git
synced 2026-01-01 13:37:03 +03:00
small pile of pythonic
This commit is contained in:
parent
9d52559b5f
commit
f6fcdd9c24
@ -196,6 +196,14 @@ def segments_to_pages(segments: List[Segment], page_size: int) -> Dict[int, List
|
|||||||
return pages
|
return pages
|
||||||
|
|
||||||
|
|
||||||
|
class OpenOCDStartupException(Exception):
|
||||||
|
def __init__(self, msg):
|
||||||
|
self.msg = msg
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"OpenOCD Startup Exception: {self.msg}"
|
||||||
|
|
||||||
|
|
||||||
def run_openocd(
|
def run_openocd(
|
||||||
openocd_exec=openocd_exec_path,
|
openocd_exec=openocd_exec_path,
|
||||||
openocd_scripts=openocd_scripts_path,
|
openocd_scripts=openocd_scripts_path,
|
||||||
@ -286,8 +294,11 @@ def upload_file(
|
|||||||
|
|
||||||
proc: Union[subprocess.Popen, None] = None
|
proc: Union[subprocess.Popen, None] = None
|
||||||
if is_run_openocd:
|
if is_run_openocd:
|
||||||
|
try:
|
||||||
proc = run_openocd(openocd_exec, openocd_scripts,
|
proc = run_openocd(openocd_exec, openocd_scripts,
|
||||||
openocd_interface, openocd_target, is_open_console)
|
openocd_interface, openocd_target, is_open_console)
|
||||||
|
except OSError as e:
|
||||||
|
raise OpenOCDStartupException(e)
|
||||||
try:
|
try:
|
||||||
with OpenOcdTclRpc(host, port) as openocd:
|
with OpenOcdTclRpc(host, port) as openocd:
|
||||||
openocd.run(f"adapter speed {adapter_speed}")
|
openocd.run(f"adapter speed {adapter_speed}")
|
||||||
@ -312,8 +323,7 @@ def upload_file(
|
|||||||
print("ERROR: The connection to OpenOCD is not established. Check the settings and connection of the debugger")
|
print("ERROR: The connection to OpenOCD is not established. Check the settings and connection of the debugger")
|
||||||
except TclException as e:
|
except TclException as e:
|
||||||
print(f"ERROR: TclException {e.code} \n {e.msg}")
|
print(f"ERROR: TclException {e.code} \n {e.msg}")
|
||||||
|
finally:
|
||||||
|
|
||||||
if proc is not None:
|
if proc is not None:
|
||||||
proc.kill()
|
proc.kill()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user