Fix some lousy error handling

This commit is contained in:
Teo Mrnjavac 2014-07-28 17:46:56 +02:00
parent 4fc2efb7fa
commit e937782a4e

View File

@ -18,6 +18,7 @@
# along with Calamares. If not, see <http://www.gnu.org/licenses/>. # along with Calamares. If not, see <http://www.gnu.org/licenses/>.
import os import os
import shutil
import subprocess import subprocess
import tempfile import tempfile
from collections import namedtuple from collections import namedtuple
@ -61,7 +62,6 @@ class UnsquashOperation:
sourceMountPath = tempfile.mkdtemp() sourceMountPath = tempfile.mkdtemp()
try: try:
for entry in self.unpacklist: for entry in self.unpacklist:
try:
sqfsList = subprocess.check_output( [ "unsquashfs", "-l", entry.source ] ) sqfsList = subprocess.check_output( [ "unsquashfs", "-l", entry.source ] )
filesCount = sqfsList.splitlines().count() filesCount = sqfsList.splitlines().count()
self.unpackstatus[ entry.source ].total = filesCount self.unpackstatus[ entry.source ].total = filesCount
@ -69,22 +69,16 @@ class UnsquashOperation:
imgBaseName = os.path.splitext( os.path.basename( entry.source ) )[ 0 ] imgBaseName = os.path.splitext( os.path.basename( entry.source ) )[ 0 ]
imgMountDir = sourceMountPath + os.sep + imgBaseName imgMountDir = sourceMountPath + os.sep + imgBaseName
os.mkdir( imgMountDir ) os.mkdir( imgMountDir )
entry.sourceDir = imgMountDir entry.sourceDir = imgMountDir
self.reportProgress() self.reportProgress()
self.unsquashImage( entry ) self.unsquashImage( entry )
finally: finally:
os.rmdir( imgMountDir ) shutil.rmtree( sourceMountPath )
finally:
os.rmdir( sourceMountPath )
def unsquashImage( self, entry ): def unsquashImage( self, entry ):
try:
subprocess.check_call( [ "mount", entry.source, entry.sourceDir, "-t", "squashfs", "-o", "loop" ] ) subprocess.check_call( [ "mount", entry.source, entry.sourceDir, "-t", "squashfs", "-o", "loop" ] )
try:
t = FileCopy( entry.sourceDir, entry.destination, self.reportProgress ) t = FileCopy( entry.sourceDir, entry.destination, self.reportProgress )
t.run() t.run()
finally: finally: