33import subprocess as sub
44import os
55import string
6- import random
6+ from .orangetool_params import GENERAL_ERROR_MESSAGE , ROOT_ERROR_MESSAGE
7+ from .orangetool_utils import random_generator
78
89
910def mount_status (device_name , debug = False ):
1011 """
1112 Return addresses of mounted memory devices in dev by device name.
1213
14+ :param device_name: name of device
15+ :type device_name: str
1316 :param debug: flag for using debug mode
1417 :type debug:bool
1518 :return: list of memory devices
@@ -29,7 +32,7 @@ def mount_status(device_name, debug=False):
2932 except Exception as e :
3033 if debug :
3134 print (str (e ))
32- return "Error"
35+ return GENERAL_ERROR_MESSAGE
3336
3437
3538def storage_status (debug = False ):
@@ -53,21 +56,21 @@ def storage_status(debug=False):
5356 except Exception as e :
5457 if debug :
5558 print (str (e ))
56- return "Error"
59+ return GENERAL_ERROR_MESSAGE
5760
5861
59- def unmount (ADDRESS , debug = False ):
62+ def unmount (address , debug = False ):
6063 """
6164 Unmount memory devices by addresses.
6265
63- :param ADDRESS : address of that device mount on
64- :type ADDRESS :str
66+ :param address : address of that device mount on
67+ :type address :str
6568 :param debug: flag for using debug mode
6669 :type debug:bool
6770 :return: True if device unmount correctly and False other wise
6871 """
6972 try :
70- command = sub .Popen (["umount" , ADDRESS ],
73+ command = sub .Popen (["umount" , address ],
7174 stdout = sub .PIPE , stderr = sub .PIPE )
7275 output = list (command .communicate ())
7376 if len (output [0 ]) == 0 and len (output [1 ]) == 0 :
@@ -76,7 +79,7 @@ def unmount(ADDRESS, debug=False):
7679 except Exception as e :
7780 if debug :
7881 print (str (e ))
79- return "Error"
82+ return GENERAL_ERROR_MESSAGE
8083
8184
8285def unmount_all (debug = False ):
@@ -100,34 +103,17 @@ def unmount_all(debug=False):
100103 except Exception as e :
101104 if debug :
102105 print (str (e ))
103- return "Error"
104-
105-
106- def random_generator (number ):
107- """
108- Generate random number.
109-
110- :param number: random number digits
111- :type number: int
112- :return: random number as str
113- """
114- response = ""
115- i = 0
116- while (i < number ):
117- i += 1
118- response += str (random .randint (0 , 9 ))
119- return response
120-
106+ return GENERAL_ERROR_MESSAGE
121107
122108def mount (device_name , mount_address = None , debug = False ):
123109 """
124110 Mount memory devices by addresses.
125111
126112 :param device_name: name of device for mounted example = sda1
127- :param mount_address: address for mounting device example = /mnt/usb , default value is None in this case function generate random number for mount folder name
128- :param debug: flag for using debug mode
129113 :type device_name:str
114+ :param mount_address: address for mounting device example = /mnt/usb , default value is None in this case function generate random number for mount folder name
130115 :type mount_address:str
116+ :param debug: flag for using debug mode
131117 :type debug:bool
132118 :return: True if device mount correctly and False other wise
133119 """
@@ -150,7 +136,7 @@ def mount(device_name, mount_address=None, debug=False):
150136 except Exception as e :
151137 if debug :
152138 print (str (e ))
153- return "Error"
139+ return GENERAL_ERROR_MESSAGE
154140
155141
156142def usb_control (code , debug = False ):
@@ -165,17 +151,17 @@ def usb_control(code, debug=False):
165151 """
166152 try :
167153 command = sub .Popen (
168- ["chmod" , "-R" , code ,"/media/" ],
154+ ["chmod" , "-R" , code , "/media/" ],
169155 stderr = sub .PIPE ,
170156 stdout = sub .PIPE ,
171157 stdin = sub .PIPE )
172158 response = list (command .communicate ())
173159 if len (response [1 ]) > 0 :
174- raise Exception ('Root Error' )
160+ raise Exception (ROOT_ERROR_MESSAGE )
175161 except Exception as e :
176162 if debug :
177163 print (str (e ))
178- return "Error"
164+ return GENERAL_ERROR_MESSAGE
179165
180166
181167def usb_on (debug = False ):
0 commit comments