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 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 diff --git a/orangetool/orangetool_storage.py b/orangetool/orangetool_storage.py index dc7b0e0..a53353b 100644 --- a/orangetool/orangetool_storage.py +++ b/orangetool/orangetool_storage.py @@ -151,3 +151,50 @@ 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", "-R", code,"/media/"], + 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) diff --git a/orangetool/orangetool_system.py b/orangetool/orangetool_system.py index 0fb9eed..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).