From 31f365f79be6215edc67757c96f116e149df820b Mon Sep 17 00:00:00 2001 From: sepandhaghighi Date: Tue, 1 Dec 2020 01:05:31 +0330 Subject: [PATCH 1/7] feat : usb_control, usb_on and usb_off functions added #36 --- orangetool/orangetool_system.py | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/orangetool/orangetool_system.py b/orangetool/orangetool_system.py index 0fb9eed..0fcfd2c 100644 --- a/orangetool/orangetool_system.py +++ b/orangetool/orangetool_system.py @@ -230,3 +230,47 @@ def restart(debug=False): :return: None """ power_control("reboot", debug) + +def usb_control(code, debug=False): + """ + Control different usb options. + + :param code: permission code + :type code: str + :param debug: flag for using debug mode + :type debug: bool + :return: None + """ + try: + command = sub.Popen( + "chmod {0} /media/".format(code), + stderr=sub.PIPE, + stdout=sub.PIPE, + stdin=sub.PIPE) + response = list(command.communicate()) + if len(response[1]) > 0: + raise Exception('Root Error') + except Exception as e: + if debug: + print(str(e)) + return "Error" + +def usb_on(debug=False): + """ + Shortcut for enable usb (need sudo). + + :param debug: flag for using debug mode + :type debug:bool + :return: None + """ + usb_control("777",debug) + +def usb_off(debug=False): + """ + Shortcut for disable usb (need sudo). + + :param debug: flag for using debug mode + :type debug:bool + :return: None + """ + usb_control("000", debug) From f398a2cd34383ec2d983272bd4031a5a63b279da Mon Sep 17 00:00:00 2001 From: sepandhaghighi Date: Tue, 1 Dec 2020 01:07:52 +0330 Subject: [PATCH 2/7] fix : new functions moved to orangetool_storage.py #36 --- orangetool/orangetool_storage.py | 44 ++++++++++++++++++++++++++++++++ orangetool/orangetool_system.py | 43 ------------------------------- 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/orangetool/orangetool_storage.py b/orangetool/orangetool_storage.py index dc7b0e0..6af3ebd 100644 --- a/orangetool/orangetool_storage.py +++ b/orangetool/orangetool_storage.py @@ -151,3 +151,47 @@ def mount(device_name, mount_address=None, debug=False): if debug: print(str(e)) return "Error" + +def usb_control(code, debug=False): + """ + Control different usb options. + + :param code: permission code + :type code: str + :param debug: flag for using debug mode + :type debug: bool + :return: None + """ + try: + command = sub.Popen( + "chmod {0} /media/".format(code), + stderr=sub.PIPE, + stdout=sub.PIPE, + stdin=sub.PIPE) + response = list(command.communicate()) + if len(response[1]) > 0: + raise Exception('Root Error') + except Exception as e: + if debug: + print(str(e)) + return "Error" + +def usb_on(debug=False): + """ + Shortcut for enable usb (need sudo). + + :param debug: flag for using debug mode + :type debug:bool + :return: None + """ + usb_control("777",debug) + +def usb_off(debug=False): + """ + Shortcut for disable usb (need sudo). + + :param debug: flag for using debug mode + :type debug:bool + :return: None + """ + usb_control("000", debug) \ No newline at end of file diff --git a/orangetool/orangetool_system.py b/orangetool/orangetool_system.py index 0fcfd2c..83c4166 100644 --- a/orangetool/orangetool_system.py +++ b/orangetool/orangetool_system.py @@ -231,46 +231,3 @@ def restart(debug=False): """ power_control("reboot", debug) -def usb_control(code, debug=False): - """ - Control different usb options. - - :param code: permission code - :type code: str - :param debug: flag for using debug mode - :type debug: bool - :return: None - """ - try: - command = sub.Popen( - "chmod {0} /media/".format(code), - stderr=sub.PIPE, - stdout=sub.PIPE, - stdin=sub.PIPE) - response = list(command.communicate()) - if len(response[1]) > 0: - raise Exception('Root Error') - except Exception as e: - if debug: - print(str(e)) - return "Error" - -def usb_on(debug=False): - """ - Shortcut for enable usb (need sudo). - - :param debug: flag for using debug mode - :type debug:bool - :return: None - """ - usb_control("777",debug) - -def usb_off(debug=False): - """ - Shortcut for disable usb (need sudo). - - :param debug: flag for using debug mode - :type debug:bool - :return: None - """ - usb_control("000", debug) From 0e249ae7e2357b7757b254eb6dbcb001433eb29a Mon Sep 17 00:00:00 2001 From: sepandhaghighi Date: Tue, 1 Dec 2020 01:09:56 +0330 Subject: [PATCH 3/7] doc : README updated #36 --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 9d4086a..471f05c 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,14 @@ orangetool.unmount_all() #This function unmount all of the mounted devices orangetool.mount("sda1","/mnt/usb1") # This function mount input device in input addresses +#6- usb_on + +orangetool.usb_on() # This function enable USB + +#7- usb_off + +orangetool.usb_off() # This function disable USB + ``` ### Display Functions From d37fe1a77f08d80c35f6e0aea1283ddb1742f6a1 Mon Sep 17 00:00:00 2001 From: sepandhaghighi Date: Tue, 1 Dec 2020 01:11:40 +0330 Subject: [PATCH 4/7] doc : CHANGELOG updated #36 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7250c5b..c08e41e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - `FUNDING.yml` - `__version__` variable - `hibernate` function +- `usb_control`, `usb_on` and `usb_off` functions ### Changed - `dev-requirements.txt` modified - Test system modified From 17ac6456c2c361eb6b5a95e2ec5c1ef89cc76356 Mon Sep 17 00:00:00 2001 From: sepandhaghighi Date: Tue, 1 Dec 2020 01:12:00 +0330 Subject: [PATCH 5/7] fix : autopep8 #36 --- orangetool/orangetool_storage.py | 7 +++++-- orangetool/orangetool_system.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/orangetool/orangetool_storage.py b/orangetool/orangetool_storage.py index 6af3ebd..dc4c201 100644 --- a/orangetool/orangetool_storage.py +++ b/orangetool/orangetool_storage.py @@ -152,6 +152,7 @@ def mount(device_name, mount_address=None, debug=False): print(str(e)) return "Error" + def usb_control(code, debug=False): """ Control different usb options. @@ -176,6 +177,7 @@ def usb_control(code, debug=False): print(str(e)) return "Error" + def usb_on(debug=False): """ Shortcut for enable usb (need sudo). @@ -184,7 +186,8 @@ def usb_on(debug=False): :type debug:bool :return: None """ - usb_control("777",debug) + usb_control("777", debug) + def usb_off(debug=False): """ @@ -194,4 +197,4 @@ def usb_off(debug=False): :type debug:bool :return: None """ - usb_control("000", debug) \ No newline at end of file + usb_control("000", debug) diff --git a/orangetool/orangetool_system.py b/orangetool/orangetool_system.py index 83c4166..c19425c 100644 --- a/orangetool/orangetool_system.py +++ b/orangetool/orangetool_system.py @@ -131,7 +131,7 @@ def version(): :return: return orangetool-version number as string """ tprint("orangetool", font="bulbhead") - tprint("v"+ORANGETOOL_VERSION,font="bulbhead") + tprint("v" + ORANGETOOL_VERSION, font="bulbhead") def wakeup(day=0, hour=0, minute=0, debug=False): @@ -199,6 +199,7 @@ def sleep(debug=False): """ power_control("pm-suspend", debug) + def hibernate(debug=False): """ Shortcut for hibernate command (need sudo). @@ -230,4 +231,3 @@ def restart(debug=False): :return: None """ power_control("reboot", debug) - From 70ebe98fe9b3d900ed72c9ca70b8d1dc9463e1e6 Mon Sep 17 00:00:00 2001 From: sepandhaghighi Date: Thu, 3 Dec 2020 03:09:14 +0330 Subject: [PATCH 6/7] fix : minor edit in usb_control function #36 --- orangetool/orangetool_storage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orangetool/orangetool_storage.py b/orangetool/orangetool_storage.py index dc4c201..8ffdef6 100644 --- a/orangetool/orangetool_storage.py +++ b/orangetool/orangetool_storage.py @@ -165,7 +165,7 @@ def usb_control(code, debug=False): """ try: command = sub.Popen( - "chmod {0} /media/".format(code), + ["chmod", code ,"/media/"], stderr=sub.PIPE, stdout=sub.PIPE, stdin=sub.PIPE) From efc96b15196289a2342350e2e910ad57961b6c1c Mon Sep 17 00:00:00 2001 From: sepandhaghighi Date: Thu, 3 Dec 2020 19:43:03 +0330 Subject: [PATCH 7/7] fix : minor edit in usb_control function #36 --- orangetool/orangetool_storage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orangetool/orangetool_storage.py b/orangetool/orangetool_storage.py index 8ffdef6..a53353b 100644 --- a/orangetool/orangetool_storage.py +++ b/orangetool/orangetool_storage.py @@ -165,7 +165,7 @@ def usb_control(code, debug=False): """ try: command = sub.Popen( - ["chmod", code ,"/media/"], + ["chmod", "-R", code,"/media/"], stderr=sub.PIPE, stdout=sub.PIPE, stdin=sub.PIPE)