[Pkg-privacy-commits] [tails-installer] 11/34: Lint.

anonym anonym-tails-guest at moszumanska.debian.org
Mon Jan 22 14:05:32 UTC 2018


This is an automated email from the git hooks/post-receive script.

anonym-tails-guest pushed a commit to branch tails/master
in repository tails-installer.

commit 048f7fe041ec201b858c48d599e21b09ff8c5256
Author: intrigeri <intrigeri at boum.org>
Date:   Sat Jan 20 11:09:06 2018 +0000

    Lint.
---
 tails_installer/creator.py | 150 +++++++++++++++++++++++++--------------------
 tails_installer/gui.py     |  20 +++---
 2 files changed, 96 insertions(+), 74 deletions(-)

diff --git a/tails_installer/creator.py b/tails_installer/creator.py
index 858930c..dea4d20 100755
--- a/tails_installer/creator.py
+++ b/tails_installer/creator.py
@@ -56,12 +56,12 @@ from tails_installer.config import config
 from tails_installer.source import SourceError
 
 #XXX: size should be configurable
-SYSTEM_PARTITION_FLAGS = [ 0,    # system partition
-                           2,    # legacy BIOS bootable
-                           60,   # read-only
-                           62,   # hidden
-                           63    # do not automount
-                         ]
+SYSTEM_PARTITION_FLAGS = [0,    # system partition
+                          2,    # legacy BIOS bootable
+                          60,   # read-only
+                          62,   # hidden
+                          63    # do not automount
+                          ]
 # EFI System Partition
 ESP_GUID = 'C12A7328-F81F-11D2-BA4B-00A0C93EC93B'
 
@@ -91,7 +91,7 @@ class TailsInstallerCreator(object):
     force_reinstall = False
 
     drive = property(fget=lambda self: self.drives[self._drive],
-	                     fset=lambda self, d: self._set_drive(d))
+                     fset=lambda self, d: self._set_drive(d))
 
     def __init__(self, opts):
         self.opts = opts
@@ -151,7 +151,8 @@ class TailsInstallerCreator(object):
         if delta.seconds:
             self.mb_per_sec = (self.source.size / delta.seconds) / 1024**2
             if self.mb_per_sec:
-                self.log.info(_("Wrote to device at %(speed)d MB/sec") % {'speed': self.mb_per_sec})
+                self.log.info(_("Wrote to device at %(speed)d MB/sec") % {
+                    'speed': self.mb_per_sec})
 
     def syslinux_options(self):
         opts = []
@@ -254,7 +255,8 @@ class TailsInstallerCreator(object):
         if not device:
             device = self.drive['device']
 
-        proc = self.popen(['/sbin/sgdisk', '--print', device], shell=False, passive=True)
+        proc = self.popen(['/sbin/sgdisk', '--print', device],
+                          shell=False, passive=True)
         if proc.returncode:
             return False
         return True
@@ -290,13 +292,13 @@ class TailsInstallerCreator(object):
         """
         if isinstance(cmd, list):
             cmd_decoded = u' '.join(cmd)
-            cmd_bytes = [ unicode_to_filesystemencoding(el) for el in cmd ]
+            cmd_bytes = [unicode_to_filesystemencoding(el) for el in cmd]
         else:
             cmd_decoded = cmd
             cmd_bytes = unicode_to_filesystemencoding(cmd)
         self.log.debug(cmd_decoded)
         self.output.write(cmd_bytes)
-        kwargs = { 'shell': True, 'stdin': subprocess.PIPE }
+        kwargs = {'shell': True, 'stdin': subprocess.PIPE}
         kwargs.update(user_kwargs)
         proc = subprocess.Popen(cmd_bytes, stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
@@ -368,10 +370,11 @@ class TailsInstallerCreator(object):
         self.log.debug('overlaysize = %d' % overlaysize)
         self.totalsize = overlaysize + self.source.size
         if self.totalsize > freebytes:
-            raise TailsInstallerError(_("Not enough free space on device." +
-                                 "\n%dMB ISO + %dMB overlay > %dMB free space") %
-                                 (self.source.size/1024**2, self.overlay,
-                                  freebytes/1024**2))
+            raise TailsInstallerError(_(
+                "Not enough free space on device." +
+                "\n%dMB ISO + %dMB overlay > %dMB free space") %
+                (self.source.size/1024**2, self.overlay,
+                 freebytes/1024**2))
 
     def create_persistent_overlay(self):
         if self.overlay:
@@ -463,9 +466,10 @@ class TailsInstallerCreator(object):
                 try:
                     os.unlink(path)
                 except:
-                    raise TailsInstallerError(_("Unable to remove file from"
-                                         " previous LiveOS: %(message)s")
-                                         % {'message': str(e)})
+                    raise TailsInstallerError(_(
+                        "Unable to remove file from"
+                        " previous LiveOS: %(message)s")
+                        % {'message': str(e)})
             elif os.path.isdir(path):
                 try:
                     _set_liberal_perms_recursive(path)
@@ -475,9 +479,10 @@ class TailsInstallerCreator(object):
                 try:
                     shutil.rmtree(path)
                 except OSError, e:
-                    raise TailsInstallerError(_("Unable to remove directory from"
-                                         " previous LiveOS: %(message)s")
-                                         % {'message': str(e)})
+                    raise TailsInstallerError(_(
+                        "Unable to remove directory from"
+                        " previous LiveOS: %(message)s")
+                        % {'message': str(e)})
 
     def get_liveos(self):
         return self.get_liveos_file_path(config['main_liveos_dir'])
@@ -501,7 +506,7 @@ class TailsInstallerCreator(object):
         """
         toplevels = config['liveos_toplevel_files']
         if absolute:
-            return [ self.get_liveos_file_path(f) for f in toplevels ]
+            return [self.get_liveos_file_path(f) for f in toplevels]
         return toplevels
 
     def existing_overlay(self):
@@ -595,13 +600,15 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
             block = obj.props.block
             self.log.debug("looking at %s" % obj.get_object_path())
             if not block:
-                self.log.debug("skip %s which is not a block device" % obj.get_object_path())
+                self.log.debug("skip %s which is not a block device"
+                               % obj.get_object_path())
                 continue
             partition = obj.props.partition
             filesystem = obj.props.filesystem
             drive = self._udisksclient.get_drive_for_block(block)
             if not drive:
-                self.log.debug("skip %s which has no associated drive" % obj.get_object_path())
+                self.log.debug("skip %s which has no associated drive"
+                               % obj.get_object_path())
                 continue
             data = {
                 'udi': obj.get_object_path(),
@@ -626,11 +633,13 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
 
             # Check non-removable drives
             if not data['removable']:
-                self.log.debug('Skipping non-removable device: %s' % data['device'])
+                self.log.debug('Skipping non-removable device: %s'
+                               % data['device'])
 
             # Only pay attention to USB and SDIO devices, unless --force'd
             iface = drive.props.connection_bus
-            if iface != 'usb' and iface != 'sdio' and self.opts.force != data['device']:
+            if iface != 'usb' and iface != 'sdio' \
+               and self.opts.force != data['device']:
                 self.log.warning(
                     "Skipping device '%(device)s' connected to '%(interface)s' interface"
                     % {'device': data['udi'], 'interface': iface}
@@ -644,11 +653,13 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
 
             # Skip things without a size
             if not data['size'] and not self.opts.force:
-                self.log.debug('Skipping device without size: %s' % data['device'])
+                self.log.debug('Skipping device without size: %s'
+                               % data['device'])
                 continue
 
             if partition:
-                partition_table = self._udisksclient.get_partition_table(partition)
+                partition_table = self._udisksclient.get_partition_table(
+                    partition)
                 parent_block = partition_table.get_object().props.block
                 data['label'] = partition.props.name
                 data['parent'] = parent_block.props.device
@@ -688,7 +699,7 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
             if mount:
                 if len(mount) > 1:
                     self.log.warning('Multiple mount points for %s' %
-                            data['device'])
+                                     data['device'])
                 mount = data['mount'] = data['mount'][0]
             else:
                 mount = data['mount'] = None
@@ -731,13 +742,15 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
         self.log.debug(pformat(mounted_parts))
 
         for device, data in self.drives.iteritems():
-            if self.source and self.source.dev and data['udi'] == self.source.dev:
+            if self.source \
+               and self.source.dev and data['udi'] == self.source.dev:
                 continue
             if device in mounted_parts and len(mounted_parts[device]) > 0:
                 data['mounted_partitions'] = mounted_parts[device]
-                self.log.debug(_('Some partitions of the target device %(device)s are mounted. '
-                                 'They will be unmounted before starting the '
-                                 'installation process.') % {'device': data['device']})
+                self.log.debug(_(
+                    'Some partitions of the target device %(device)s are mounted. '
+                    'They will be unmounted before starting the '
+                    'installation process.') % {'device': data['device']})
 
         if callback:
             callback()
@@ -764,25 +777,25 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
         if parent:
             parent = parent.GetProperty('block.device')
         self.drives[device] = {
-            'label'   : str(dev.GetProperty('volume.label')).replace(' ', '_'),
-            'fstype'  : str(dev.GetProperty('volume.fstype')),
+            'label':     str(dev.GetProperty('volume.label')).replace(' ', '_'),
+            'fstype':    str(dev.GetProperty('volume.fstype')),
             'fsversion': str(dev.GetProperty('volume.fsversion')),
-            'uuid'    : str(dev.GetProperty('volume.uuid')),
-            'mount'   : mount,
-            'udi'     : dev,
-            'free'    : mount and self.get_free_bytes(mount) / 1024**2 or None,
-            'device'  : device,
-            'parent'  : parent
+            'uuid':      str(dev.GetProperty('volume.uuid')),
+            'mount':     mount,
+            'udi':       dev,
+            'free':      mount and self.get_free_bytes(mount) / 1024**2 or None,
+            'device':    device,
+            'parent':    parent
         }
 
     def mount_device(self):
         """ Mount our device if it is not already mounted """
         if not self.fstype:
             raise TailsInstallerError(_("Unknown filesystem.  Your device "
-                                 "may need to be reformatted."))
+                                        "may need to be reformatted."))
         if self.fstype not in self.valid_fstypes:
             raise TailsInstallerError(_("Unsupported filesystem: %s") %
-                                 self.fstype)
+                                      self.fstype)
         self.dest = self.drive['mount']
         if not self.dest:
             self.log.debug("Mounting %s" % self.drive['udi'])
@@ -792,18 +805,20 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
             mount = None
             try:
                 mount = filesystem.call_mount_sync(
-                        arg_options = GLib.Variant('a{sv}', None),
-                        cancellable = None)
+                    arg_options=GLib.Variant('a{sv}', None),
+                    cancellable=None)
             except GLib.Error as e:
                 if 'org.freedesktop.UDisks2.Error.AlreadyMounted' in e.message:
                     self.log.debug('Device already mounted')
                 else:
-                    raise TailsInstallerError(_('Unknown GLib exception while trying to '
-                                     'mount device: %(message)s')
-                                     % {'message': str(e)})
+                    raise TailsInstallerError(_(
+                        'Unknown GLib exception while trying to '
+                        'mount device: %(message)s')
+                        % {'message': str(e)})
             except Exception, e:
-                raise TailsInstallerError(_("Unable to mount device: %(message)s")
-                                     % {'message': str(e)})
+                raise TailsInstallerError(_(
+                    "Unable to mount device: %(message)s")
+                    % {'message': str(e)})
 
             # Get the new mount point
             if not mount:
@@ -841,7 +856,8 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
                     arg_options=GLib.Variant('a{sv}', None),
                     cancellable=None)
         self.drive['mount'] = None
-        if not self.opts.partition and self.dest is not None and os.path.exists(self.dest):
+        if not self.opts.partition and self.dest is not None \
+           and os.path.exists(self.dest):
             self.log.error(_("Mount %s exists after unmounting") % self.dest)
         self.dest = None
         # Sometimes the device is still considered as busy by the kernel
@@ -884,7 +900,8 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
         try:
             partition_table.call_create_partition_sync(
                     arg_offset=0,
-                    arg_size=self.system_partition_size(self.drive['parent_size']),
+                    arg_size=self.system_partition_size(
+                        self.drive['parent_size']),
                     arg_type=ESP_GUID,
                     arg_name=self.label,
                     arg_options=GLib.Variant('a{sv}', None),
@@ -936,7 +953,7 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
         else:
             obj = self._get_object()
 
-        if not obj.props.partition :
+        if not obj.props.partition:
             return False
 
         partition_table = obj.props.partition_table
@@ -967,7 +984,7 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
         self._full_drive = self.drives[self._drive]
 
     def switch_drive_to_system_partition(self):
-        full_drive_name  = self._full_drive['device']
+        full_drive_name = self._full_drive['device']
         append = False
         if full_drive_name.startswith('/dev/sd'):
             append = '1'
@@ -991,10 +1008,10 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
         if self.fstype not in self.valid_fstypes:
             if not self.fstype:
                 raise TailsInstallerError(_("Unknown filesystem.  Your device "
-                                     "may need to be reformatted."))
+                                            "may need to be reformatted."))
             else:
                 raise TailsInstallerError(_("Unsupported filesystem: %s" %
-                                     self.fstype))
+                                            self.fstype))
         if self.drive['label'] != self.label:
             self.log.info("Setting %(device)s label to %(label)s" %
                           {'device': self.drive['device'],
@@ -1042,8 +1059,9 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
                         copied = True
                         break
                 if not copied:
-                    raise TailsInstallerError(_("Could not find the '%s' COM32 module")
-                                       % com32mod)
+                    raise TailsInstallerError(_(
+                        "Could not find the '%s' COM32 module")
+                        % com32mod)
 
         # Don't prompt about overwriting files from mtools (#491234)
         for ldlinux in [self.get_liveos_file_path(p, 'ldlinux.sys')
@@ -1058,7 +1076,8 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
             syslinux_executable = 'syslinux';
             self.log.debug('Will use %s as the syslinux binary'
                            % syslinux_executable)
-            iso_syslinux = self.get_liveos_file_path('utils', 'linux', syslinux_executable)
+            iso_syslinux = self.get_liveos_file_path('utils', 'linux',
+                                                     syslinux_executable)
             tmpdir = tempfile.mkdtemp()
             tmp_syslinux = os.path.join(tmpdir, syslinux_executable)
             shutil.copy(iso_syslinux, tmp_syslinux)
@@ -1066,7 +1085,7 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
                      os.stat(tmp_syslinux).st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)
             self.flush_buffers()
             self.unmount_device()
-            self.popen('%s %s -d %s %s' %  (
+            self.popen('%s %s -d %s %s' % (
                     tmp_syslinux,
                     ' '.join(self.syslinux_options()),
                     'syslinux', self.drive['device']))
@@ -1074,9 +1093,10 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
         else:
             self.flush_buffers()
             self.unmount_device()
-            self.popen('/usr/bin/pkexec /usr/bin/syslinux %s -d syslinux %s' % (
-                ' '.join(self.syslinux_options()),
-                self.drive['device']))
+            self.popen(
+                '/usr/bin/pkexec /usr/bin/syslinux %s -d syslinux %s' % (
+                    ' '.join(self.syslinux_options()),
+                    self.drive['device']))
 
     def get_free_bytes(self, device=None):
         """ Return the number of available bytes on our device """
@@ -1177,8 +1197,8 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
         """ Return the PedDisk and partition of the selected device """
         import parted
         parent = self.drives[self._drive]['parent']
-        dev = parted.Device(path = parent)
-        disk = parted.Disk(device = dev)
+        dev = parted.Device(path=parent)
+        disk = parted.Disk(device=dev)
         for part in disk.partitions:
             if self._drive == "/dev/%s" %(part.getDeviceNodeName(),):
                 return disk, part
diff --git a/tails_installer/gui.py b/tails_installer/gui.py
index a2172e3..83092ac 100755
--- a/tails_installer/gui.py
+++ b/tails_installer/gui.py
@@ -470,10 +470,10 @@ class TailsInstallerWindow(Gtk.ApplicationWindow):
                                     if device['parent_size']
                                     else device['size'])
         pretty_name = _("%(size)s %(vendor)s %(model)s device (%(device)s)") % {
-                    'size'  :  size,
-                    'vendor':  device['vendor'],
-                    'model' :  device['model'],
-                    'device':  device['device']
+                    'size':   size,
+                    'vendor': device['vendor'],
+                    'model':  device['model'],
+                    'device': device['device']
         }
         return pretty_name
 
@@ -506,7 +506,8 @@ class TailsInstallerWindow(Gtk.ApplicationWindow):
             text = text + '\n'
         text_buffer = self.__textview_log.get_buffer()
         text_buffer.insert(text_buffer.get_end_iter(), text)
-        self.__textview_log.scroll_to_iter(text_buffer.get_end_iter(), 0, False, 0, 0)
+        self.__textview_log.scroll_to_iter(text_buffer.get_end_iter(),
+                                           0, False, 0, 0)
 
     def update_start_button(self):
         if self.source_available and self.target_available:
@@ -573,10 +574,11 @@ class TailsInstallerWindow(Gtk.ApplicationWindow):
                 if not info['is_device_big_enough_for_installation']:
                     message =_('The device "%(pretty_name)s"'
                                ' is too small to install'
-                               ' Tails (at least %(size)s GB is required).') %  {
-                               'pretty_name':  pretty_name,
-                               'size'  :  (float(config['official_min_installation_device_size'])
-                                       / 1000)
+                               ' Tails (at least %(size)s GB is required).') % {
+                               'pretty_name': pretty_name,
+                               'size': (float(
+                                   config['official_min_installation_device_size'])
+                                        / 1000)
                                }
                     self.status(message)
                     continue

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/tails-installer.git



More information about the Pkg-privacy-commits mailing list