Skip to content

Commit d212c75

Browse files
Merge pull request #40 from Moduland/usb_control
USB control functions
2 parents 285d62f + efc96b1 commit d212c75

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99
- `FUNDING.yml`
1010
- `__version__` variable
1111
- `hibernate` function
12+
- `usb_control`, `usb_on` and `usb_off` functions
1213
### Changed
1314
- `dev-requirements.txt` modified
1415
- Test system modified

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ orangetool.unmount_all() #This function unmount all of the mounted devices
188188

189189
orangetool.mount("sda1","/mnt/usb1") # This function mount input device in input addresses
190190

191+
#6- usb_on
192+
193+
orangetool.usb_on() # This function enable USB
194+
195+
#7- usb_off
196+
197+
orangetool.usb_off() # This function disable USB
198+
191199
```
192200

193201
### Display Functions

orangetool/orangetool_storage.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,50 @@ def mount(device_name, mount_address=None, debug=False):
151151
if debug:
152152
print(str(e))
153153
return "Error"
154+
155+
156+
def usb_control(code, debug=False):
157+
"""
158+
Control different usb options.
159+
160+
:param code: permission code
161+
:type code: str
162+
:param debug: flag for using debug mode
163+
:type debug: bool
164+
:return: None
165+
"""
166+
try:
167+
command = sub.Popen(
168+
["chmod", "-R", code,"/media/"],
169+
stderr=sub.PIPE,
170+
stdout=sub.PIPE,
171+
stdin=sub.PIPE)
172+
response = list(command.communicate())
173+
if len(response[1]) > 0:
174+
raise Exception('Root Error')
175+
except Exception as e:
176+
if debug:
177+
print(str(e))
178+
return "Error"
179+
180+
181+
def usb_on(debug=False):
182+
"""
183+
Shortcut for enable usb (need sudo).
184+
185+
:param debug: flag for using debug mode
186+
:type debug:bool
187+
:return: None
188+
"""
189+
usb_control("777", debug)
190+
191+
192+
def usb_off(debug=False):
193+
"""
194+
Shortcut for disable usb (need sudo).
195+
196+
:param debug: flag for using debug mode
197+
:type debug:bool
198+
:return: None
199+
"""
200+
usb_control("000", debug)

orangetool/orangetool_system.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def version():
131131
:return: return orangetool-version number as string
132132
"""
133133
tprint("orangetool", font="bulbhead")
134-
tprint("v"+ORANGETOOL_VERSION,font="bulbhead")
134+
tprint("v" + ORANGETOOL_VERSION, font="bulbhead")
135135

136136

137137
def wakeup(day=0, hour=0, minute=0, debug=False):
@@ -199,6 +199,7 @@ def sleep(debug=False):
199199
"""
200200
power_control("pm-suspend", debug)
201201

202+
202203
def hibernate(debug=False):
203204
"""
204205
Shortcut for hibernate command (need sudo).

0 commit comments

Comments
 (0)