From adacf455227333e33a95a1692a18fb7ccb319367 Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Sat, 27 Oct 2018 11:40:26 +0900 Subject: [PATCH 1/5] Fix PEP8 W605 --- bin/candy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/candy b/bin/candy index d6e85eb..e052c15 100755 --- a/bin/candy +++ b/bin/candy @@ -290,7 +290,7 @@ def connection_resume(cmd, suppress=False): def usb_connected(): try: with open(MODEM_SERIAL_PORT_FILE, 'r') as f: - return re.match("/dev/QWS\.[A-Z0-9]*\.MODEM", f.read().strip()) + return re.match("/dev/QWS\\.[A-Z0-9]*\\.MODEM", f.read().strip()) except IOError: return False From 47125d1968a5119af043dd9ab6087dae182cfba7 Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Sat, 27 Oct 2018 11:42:17 +0900 Subject: [PATCH 2/5] Rename the common function name --- bin/candy | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/candy b/bin/candy index e052c15..5f77111 100755 --- a/bin/candy +++ b/bin/candy @@ -295,7 +295,7 @@ def usb_connected(): return False -def gnss_common(cmd): +def cmd_common(cmd): code = 0 if usb_connected(): return perform_remote_cmd(cmd) @@ -314,23 +314,23 @@ def gnss_common(cmd): def gnss_start(cmd): - code = gnss_common(cmd) + code = cmd_common(cmd) if code == 0: notice('OK') def gnss_stop(cmd): - code = gnss_common(cmd) + code = cmd_common(cmd) if code == 0: notice('OK') def gnss_status(cmd): - return gnss_common(cmd) + return cmd_common(cmd) def gnss_locate(cmd): - return gnss_common(cmd) + return cmd_common(cmd) if __name__ == "__main__": From 924723f65049408b6f2e9490efebf36b25312d19 Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Sat, 27 Oct 2018 11:44:54 +0900 Subject: [PATCH 3/5] Improve I/O error description --- bin/candy | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/candy b/bin/candy index 5f77111..f8e23d7 100755 --- a/bin/candy +++ b/bin/candy @@ -151,7 +151,11 @@ def perform_local_cmd(args): except KeyError: return err("Invalid Args") except OSError: - return err("I/O Error") + return err("I/O Error: %s" % + (''.join(traceback + .format_exception(*sys.exc_info())[-2:]) + .strip().replace('\n', ': ')) + ) except Exception: return err("Unexpected error: %s" % (''.join(traceback From 7c0ad1ce29a74cf54a897d4d43002c7192d9b406 Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Sat, 27 Oct 2018 12:53:19 +0900 Subject: [PATCH 4/5] Make `--suspend` and `--resume` options available for `apn ls`, `network show`, `sim show` and `modem show` commands --- bin/candy | 55 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/bin/candy b/bin/candy index f8e23d7..fb89b57 100755 --- a/bin/candy +++ b/bin/candy @@ -147,7 +147,7 @@ def perform_local_cmd(args): except socket.error, v: raise v except AttributeError: - return err("Unknown Command") + return cmd_common(cmd) except KeyError: return err("Invalid Args") except OSError: @@ -218,13 +218,8 @@ def main(args): if not os.path.exists(SOCK_PATH): err("[ERROR] CANDY Board Service isn't running") return 1 - sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) try: - if args.category == "gnss": - return perform_local_cmd(args) - else: - sock.connect(SOCK_PATH) - return perform_remote_cmd(args, sock) + return perform_local_cmd(args) except socket.error, v: errorcode = v[0] if errorcode == errno.ECONNREFUSED: @@ -329,14 +324,6 @@ def gnss_stop(cmd): notice('OK') -def gnss_status(cmd): - return cmd_common(cmd) - - -def gnss_locate(cmd): - return cmd_common(cmd) - - if __name__ == "__main__": parser = argparse.ArgumentParser(description="CANDY Board Service CLI") categories = parser.add_subparsers(title="categories", dest="category") @@ -348,6 +335,14 @@ if __name__ == "__main__": title="APN actions", dest="action") parser_apn_ls = apn_commands.add_parser("ls", help="List all APNs") + parser_apn_ls.add_argument( + "-s", "--suspend", action="store_const", const=True, required=False, + help="Suspend the UART connection if already established " + "prior to listing all APNs (UART only)") + parser_apn_ls.add_argument( + "-r", "--resume", action="store_const", const=True, required=False, + help="Resume the suspended UART connection " + "after listing all APNs (UART only)") parser_apn_set = apn_commands.add_parser("set", help="Set a new APN") parser_apn_set.add_argument( "-n", "--name", type=str, required=True, help="APN") @@ -372,9 +367,19 @@ if __name__ == "__main__": network_commands = parser_network.add_subparsers( title="Phone Network actions", dest="action") parser_network_show = network_commands.add_parser( - "show", help="Show Phone network state and Signal strength") + "show", help="Show the Phone network state and Signal strength") parser_network_show.add_argument( "-o", "--opts", type=str, required=False, help="Show Options") + parser_network_show.add_argument( + "-s", "--suspend", action="store_const", const=True, required=False, + help="Suspend the UART connection if already established " + "prior to showing the Phone network state and Signal strength" + " (UART only)") + parser_network_show.add_argument( + "-r", "--resume", action="store_const", const=True, required=False, + help="Resume the suspended UART connection " + "after showing the Phone network state and Signal strength" + " (UART only)") parser_network_deregister = network_commands.add_parser( "deregister", help="Deregister from the current network") parser_network_register = network_commands.add_parser( @@ -391,13 +396,29 @@ if __name__ == "__main__": title="SIM actions", dest="action") parser_sim_show = sim_commands.add_parser( "show", help="Show SIM state and SIM information") + parser_sim_show.add_argument( + "-s", "--suspend", action="store_const", const=True, required=False, + help="Suspend the UART connection if already established " + "prior to showing the SIM state and SIM information (UART only)") + parser_sim_show.add_argument( + "-r", "--resume", action="store_const", const=True, required=False, + help="Resume the suspended UART connection " + "after showing the SIM state and SIM information (UART only)") parser_modem = categories.add_parser( "modem", help="Manage LTE/3G module modem") modem_commands = parser_modem.add_subparsers( title="Modem actions", dest="action") parser_modem_show = modem_commands.add_parser( - "show", help="Show Module information") + "show", help="Show the Module information") + parser_modem_show.add_argument( + "-s", "--suspend", action="store_const", const=True, required=False, + help="Suspend the UART connection if already established " + "prior to showing the Module information (UART only)") + parser_modem_show.add_argument( + "-r", "--resume", action="store_const", const=True, required=False, + help="Resume the suspended UART connection " + "after showing the Module information (UART only)") parser_modem_reset = modem_commands.add_parser( "reset", help="Reset modem") parser_modem_reset.add_argument( From 97b335c10747e3bae3ce51c92a7d8505b70803fc Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Sat, 27 Oct 2018 12:54:33 +0900 Subject: [PATCH 5/5] Bump version --- README.md | 3 +++ setup.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d4d021..f68f1f7 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,9 @@ $ tar czvf candy-board-cli.tgz --exclude "./.*" --exclude build --exclude dist * ``` # Revision history +* 3.1.0 + - Make `--suspend` and `--resume` options available for `apn ls`, `network show`, `sim show` and `modem show` commands + * 3.0.0 - Add new categories, `connection` and `gnss` - Add new actions in `service` category diff --git a/setup.py b/setup.py index 9d1b5ee..809bac3 100755 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ except IOError: # For tox long_description = "" -version = "3.0.0" +version = "3.1.0" if sys.argv[-1] == 'publish': os.system('rm -fr dist/*')