o-gs / dji-firmware-tools

Tools for handling firmwares of DJI products, with focus on quadcopters.
GNU General Public License v3.0
1.43k stars 402 forks source link

make comm_sbs_brctl usable as library for external tools #355

Closed Alter-1 closed 11 months ago

Alter-1 commented 11 months ago

allow caller to pass args to main() cache parsed battery drivers to reduce overhead on multiple calls

import comm_sbs_bqctrl def sbs_execute (args): out = "" f = io.StringIO() try: with redirect_stdout(f): comm_sbs_bqctrl.main_api(args[2:]) out = f.getvalue() except Exception as ex: out += "\nError: "+comm_sbs_bqctrl.str_exception_with_type(ex)+"\n" return out

mefistotelis commented 11 months ago

Please adjust the tests to your changes - these are legitimate fails caused by this change:

FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_detect - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_info_commands[BQ30z55-3] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_info_commands[BQ40z50-3] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_info_commands[BQ40z307-3] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_read_commands[BQ30z55-1] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_read_commands[BQ40z50-1] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_read_commands[BQ40z307-1] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_write_commands[BQ30z55-3] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_write_commands[BQ40z50-3] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_write_commands[BQ40z307-3] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_monitor_commands[BQ30z55-1] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_monitor_commands[BQ40z50-1] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_monitor_commands[BQ40z307-1] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_sealing_commands[BQ30z55-1] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_sealing_commands[BQ40z50-1] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_chip_sealing_commands[BQ40z307-1] - SystemExit: 2
FAILED tests/test_comm_sbs_bqctrl1.py::test_comm_sbs_bqctrl_data_flash[BQ40z307-0-1280-32-2] - SystemExit: 2
========== 17 failed, 4 passed, 635 deselected, 57 warnings in 12.85s ==========

(the rest of reported fails is not related to this PR)

Alter-1 commented 11 months ago

tests issues are fixed I've left main() without args and added separate main_api(argv) btw, is it worth adding sbs_execute(arg) from pull request description along with main_argv() ?

mefistotelis commented 11 months ago

I've left main() without args and added separate main_api(argv)

Please add args to the main() instead, no need for additional wrapper. We should probably make main() accept args in all tools; but that's out of scope of this PR.

is it worth adding sbs_execute(arg) from pull request description

I don't think so. Any user will want to wrap it under his/her own rules. To be honest, my idea for using the tool as a library was that users will call specific functions directly, without going through command line args. Though if anyone want to use main(args) there should be no problem with that as well.

Alter-1 commented 11 months ago

done.