@@ -137,6 +137,15 @@ def _parse_chromeos_offset(self, bin_path):
137
137
self ._log ('Failed to calculate losetup offset.' )
138
138
return False
139
139
140
+ def _run_cmd (self , cmd ):
141
+ try :
142
+ output = subprocess .check_output (cmd )
143
+ self ._log ('{0} cmd executed successfully.' .format (cmd ))
144
+ return True
145
+ except subprocess .CalledProcessError , error :
146
+ self ._log ('cmd failed with output: {0}' .format (error .output ))
147
+ return False
148
+
140
149
def _set_loop_dev (self ):
141
150
"""Set an unused loop device that's available for use."""
142
151
cmd = ['losetup' , '-f' ]
@@ -147,9 +156,12 @@ def _set_loop_dev(self):
147
156
def _losetup (self , bin_path ):
148
157
"""Setup Chrome OS loop device."""
149
158
cmd = ['losetup' , self ._loop_dev , bin_path , '-o' , self ._parse_chromeos_offset (bin_path )]
150
- subprocess .check_output (cmd )
151
- self ._attached_loop_dev = True
152
- return True
159
+ success = self ._run_cmd (cmd )
160
+ if success :
161
+ self ._attached_loop_dev = True
162
+ return True
163
+ else :
164
+ return False
153
165
154
166
def _mnt_loop_dev (self ):
155
167
"""Mount loop device to self._mnt_path()"""
@@ -163,9 +175,12 @@ def _mnt_loop_dev(self):
163
175
else :
164
176
self ._log ('User do not have root permissions and/or sudo installed.' )
165
177
166
- subprocess .check_output (cmd )
167
- self ._mounted = True
168
- return True
178
+ success = self ._run_cmd (cmd )
179
+ if success :
180
+ self ._mounted = True
181
+ return True
182
+ else :
183
+ return False
169
184
170
185
def _has_widevine_cdm (self ):
171
186
if xbmc .getCondVisibility ('system.platform.android' ): # widevine is built in on android
@@ -463,12 +478,14 @@ def _cleanup(self):
463
478
cmd = ['umount' , self ._mnt_path ()]
464
479
if not os .getuid () == 0 and self ._cmd_exists ('sudo' ): # no need to ask for permission again
465
480
cmd .insert (0 , 'sudo' )
466
- subprocess .check_call (cmd )
467
- self ._mounted = False
481
+ unmount_success = self ._run_cmd (cmd )
482
+ if unmount_success :
483
+ self ._mounted = False
468
484
if self ._attached_loop_dev :
469
485
cmd = ['losetup' , '-d' , self ._loop_dev ]
470
- subprocess .check_call (cmd )
471
- self ._loop_dev = False
486
+ unattach_success = self ._run_cmd (cmd )
487
+ if unattach_success :
488
+ self ._loop_dev = False
472
489
473
490
shutil .rmtree (self ._temp_path ())
474
491
return True
0 commit comments