summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2019-02-24 06:21:52 +0000
committerintrigeri <intrigeri@boum.org>2019-02-24 06:21:52 +0000
commitef2d2c290c642043e1e37fbbe6c98056a2d9a4b6 (patch)
tree4b40df7d44a5d385d71b96b5a4f5037cef5e150e
parent29e75c99605ab5c40875eeec92b93b7e504b27db (diff)
parentf7ee5e20ee4b20615625591a27980866764ff833 (diff)
Merge remote-tracking branch 'kurono/bug/15166-installer-crashes-no-ascii'
-rwxr-xr-xtails_installer/creator.py36
-rw-r--r--tails_installer/source.py5
-rw-r--r--tails_installer/utils.py11
3 files changed, 32 insertions, 20 deletions
diff --git a/tails_installer/creator.py b/tails_installer/creator.py
index 745e546..44de28e 100755
--- a/tails_installer/creator.py
+++ b/tails_installer/creator.py
@@ -50,7 +50,7 @@ from tails_installer.utils import (_move_if_exists, _unlink_if_exists, unicode_t
unicode_to_filesystemencoding, is_running_from_tails,
_set_liberal_perms_recursive, underlying_physical_device,
get_open_write_fd, write_to_block_device,
- MiB_to_bytes)
+ MiB_to_bytes, TailsError)
from tails_installer import _
from tails_installer.config import config
from tails_installer.source import SourceError
@@ -65,9 +65,9 @@ SYSTEM_PARTITION_FLAGS = [0, # system partition
# EFI System Partition
ESP_GUID = 'C12A7328-F81F-11D2-BA4B-00A0C93EC93B'
-class TailsInstallerError(Exception):
+class TailsInstallerError(TailsError):
""" A generic error message that is thrown by the Tails Installer"""
-
+ pass
class TailsInstallerCreator(object):
""" An OS-independent parent class for Tails Installer Creators """
@@ -421,7 +421,7 @@ class TailsInstallerCreator(object):
self.log.warning(_("Unable to copy %(infile)s to %(outfile)s: %(message)s")
% {'infile': infile,
'outfile': outfile,
- 'message': unicode(e.message).encode("utf-8")})
+ 'message': str(e)})
syslinux_path = self.get_liveos_file_path("syslinux")
_move_if_exists(self.get_liveos_file_path("isolinux"), syslinux_path)
@@ -442,28 +442,28 @@ class TailsInstallerCreator(object):
os.chmod(path, 0644)
except OSError, e:
self.log.debug(_("Unable to chmod %(file)s: %(message)s") %
- {'file': path, 'message': unicode(e.message).encode("utf-8")})
+ {'file': path, 'message': str(e)})
try:
os.unlink(path)
except:
raise TailsInstallerError(_(
"Unable to remove file from"
" previous LiveOS: %(message)s") %
- {'message': unicode(e.message).encode("utf-8")})
+ {'message': str(e)})
elif os.path.isdir(path):
try:
_set_liberal_perms_recursive(path)
except OSError, e:
self.log.debug(_("Unable to chmod %(file)s: %(message)s")
% {'file': path,
- 'message': unicode(e.message).encode("utf-8")})
+ 'message': str(e)})
try:
shutil.rmtree(path)
except OSError, e:
raise TailsInstallerError(_(
"Unable to remove directory from"
" previous LiveOS: %(message)s") %
- {'message': unicode(e.message).encode("utf-8")})
+ {'message': str(e)})
def get_liveos(self):
return self.get_liveos_file_path(config['main_liveos_dir'])
@@ -806,11 +806,11 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
raise TailsInstallerError(_(
'Unknown GLib exception while trying to '
'mount device: %(message)s') %
- {'message': unicode(e.message).encode("utf-8")})
+ {'message': str(e)})
except Exception, e:
raise TailsInstallerError(_(
"Unable to mount device: %(message)s") %
- {'message': unicode(e.message).encode("utf-8")})
+ {'message': str(e)})
# Get the new mount point
if not mount:
@@ -1029,7 +1029,7 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
self.label))
except TailsInstallerError, e:
self.log.error(_("Unable to change volume label: %(message)s") %
- {'message': unicode(e.message).encode("utf-8")})
+ {'message': str(e)})
def install_bootloader(self):
""" Run syslinux to install the bootloader on our devices """
@@ -1129,7 +1129,7 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
os.kill(pid, signal.SIGHUP)
self.log.debug("Killed process %d" % pid)
except OSError, e:
- self.log.debug(unicode(e.message).encode("utf-8"))
+ self.log.debug(str(e))
if os.path.exists(self._error_log_filename):
if not os.path.getsize(self._error_log_filename):
# We don't want any failure here to block other tear down tasks
@@ -1380,7 +1380,7 @@ class WindowsTailsInstallerCreator(TailsInstallerCreator):
vol = win32api.GetVolumeInformation(drive)
except pywintypes.error, e:
self.log.error('Unable to get GetVolumeInformation(%s): %s' %
- (drive, unicode(e.message).encode("utf-8")))
+ (drive, str(e)))
continue
self.drives[drive] = {
'label': vol[0],
@@ -1420,7 +1420,7 @@ class WindowsTailsInstallerCreator(TailsInstallerCreator):
self.label))
except pywintypes.error, e:
self.log.warning("Unable to SetVolumeLabel: " + \
- unicode(e.message).encode("utf-8"))
+ str(e))
def get_free_bytes(self, device=None):
""" Return the number of free bytes on our selected drive """
@@ -1430,7 +1430,7 @@ class WindowsTailsInstallerCreator(TailsInstallerCreator):
(spc, bps, fc, tc) = win32file.GetDiskFreeSpace(device)
except Exception, e:
self.log.error("Problem determining free space: %s" %
- unicode(e.message).encode("utf-8"))
+ str(e))
return 0
return fc * (spc * bps) # free-clusters * bytes per-cluster
@@ -1503,7 +1503,7 @@ class WindowsTailsInstallerCreator(TailsInstallerCreator):
except Exception, e:
self.log.exception(e)
self.log.warning("Exception while fetching UUID: %s" %
- unicode(e.message).encode("utf-8"))
+ str(e))
return uuid
def _get_device_size(self, drive):
@@ -1515,7 +1515,7 @@ class WindowsTailsInstallerCreator(TailsInstallerCreator):
except Exception, e:
self.log.exception(e)
self.log.warning("Error getting drive size: %s" %
- unicode(e.message).encode("utf-8"))
+ str(e))
return size
def popen(self, cmd, **kwargs):
@@ -1580,7 +1580,7 @@ class WindowsTailsInstallerCreator(TailsInstallerCreator):
settings.Close()
except Exception, e:
self.log.warning('Unable to detect proxy settings: %s' %
- unicode(e.message).encode("utf-8"))
+ str(e))
self.log.debug('Using proxies: %s' % proxies)
return proxies
diff --git a/tails_installer/source.py b/tails_installer/source.py
index 96cb785..2ab3c73 100644
--- a/tails_installer/source.py
+++ b/tails_installer/source.py
@@ -11,10 +11,11 @@ from tails_installer.config import config
from tails_installer.utils import (_to_unicode, _dir_size, iso_is_live_system,
unicode_to_utf8, unicode_to_filesystemencoding,
_set_liberal_perms_recursive,
- underlying_physical_device)
+ underlying_physical_device, TailsError)
-class SourceError(Exception):
+class SourceError(TailsError):
""" A generic error message that is thrown by the Source classes """
+ pass
class Source(object):
def clone(self, destination):
diff --git a/tails_installer/utils.py b/tails_installer/utils.py
index bc460f9..008897c 100644
--- a/tails_installer/utils.py
+++ b/tails_installer/utils.py
@@ -12,6 +12,17 @@ from tails_installer.config import config
if 'linux' in sys.platform:
from gi.repository import GLib
+class TailsError(Exception):
+ """ A generic Exception the allows us to manage error
+ messages encoded in unicode """
+ def __init__(self, message):
+ encoded_message=unicode_to_utf8(message)
+ super(TailsError, self).__init__(encoded_message)
+ self.message = encoded_message
+
+ def __unicode__(self):
+ return self.message
+
def _to_unicode(obj, encoding='utf-8'):
if hasattr(obj, 'toUtf8'): # PyQt4.QtCore.QString
obj = str(obj.toUtf8())