]> git.siccegge.de Git - forks/vmdebootstrap.git/commitdiff
pep8 fixes
authorNeil Williams <codehelp@debian.org>
Mon, 25 Aug 2014 20:32:21 +0000 (13:32 -0700)
committerNeil Williams <codehelp@debian.org>
Mon, 25 Aug 2014 20:32:21 +0000 (13:32 -0700)
vmdebootstrap

index e28b98d3d7aa5945d9a997d4728537ba9b8a3c34..4ca922b3e0a54df0e9d535ce536404c146975f1a 100755 (executable)
@@ -1,17 +1,17 @@
 #!/usr/bin/python
 # Copyright 2011-2013  Lars Wirzenius
 # Copyright 2012  Codethink Limited
-# 
+#
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
@@ -20,6 +20,7 @@ import crypt
 import logging
 import os
 import re
+import time
 import shutil
 import subprocess
 import tempfile
@@ -72,13 +73,13 @@ class VmDebootstrap(cliapp.Application):
         self.settings.string_list(['package'], 'install PACKAGE onto system')
         self.settings.string_list(['custom-package'],
                                   'install package in DEB file onto system '
-                                    '(not from mirror)',
+                                  '(not from mirror)',
                                   metavar='DEB')
         self.settings.boolean(['no-kernel'], 'do not install a linux package')
         self.settings.boolean(['enable-dhcp'], 'enable DHCP on eth0')
         self.settings.string(['root-password'], 'set root password',
                              metavar='PASSWORD')
-        self.settings.boolean(['lock-root-password'], 
+        self.settings.boolean(['lock-root-password'],
                               'lock root account so they cannot login?')
         self.settings.string(['customize'],
                              'run SCRIPT after setting up system',
@@ -90,19 +91,19 @@ class VmDebootstrap(cliapp.Application):
         self.settings.string_list(['user'],
                                   'create USER with PASSWORD',
                                   metavar='USER/PASSWORD')
-        self.settings.boolean(['serial-console'], 
+        self.settings.boolean(['serial-console'],
                               'configure image to use a serial console')
         self.settings.string(['serial-console-command'],
                              'command to manage the serial console, appended '
-                               'to /etc/inittab (%default)',
+                             'to /etc/inittab (%default)',
                              metavar='COMMAND',
                              default='/sbin/getty -L ttyS0 115200 vt100')
-        self.settings.boolean(['sudo'], 
+        self.settings.boolean(['sudo'],
                               'install sudo, and if user is created, add them '
-                                'to sudo group')
+                              'to sudo group')
         self.settings.string(['owner'],
                              'the user who will own the image when the build '
-                               'is complete.')
+                             'is complete.')
         self.settings.boolean(['squash'],
                               'use squashfs on the final image.')
 
@@ -126,7 +127,7 @@ class VmDebootstrap(cliapp.Application):
                 self.create_empty_image()
                 self.partition_image()
                 self.install_mbr()
-                (rootdev,bootdev) = self.setup_kpartx()
+                (rootdev, bootdev) = self.setup_kpartx()
                 self.mkfs(rootdev, type=roottype)
                 rootdir = self.mount(rootdev)
                 if bootdev:
@@ -182,8 +183,8 @@ class VmDebootstrap(cliapp.Application):
 
     def runcmd(self, argv, stdin='', ignore_fail=False, **kwargs):
         logging.debug('runcmd: %s %s' % (argv, kwargs))
-        p = subprocess.Popen(argv, stdin=subprocess.PIPE, 
-                             stdout=subprocess.PIPE, stderr=subprocess.PIPE, 
+        p = subprocess.Popen(argv, stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                              **kwargs)
         out, err = p.communicate(stdin)
         if p.returncode != 0:
@@ -198,13 +199,13 @@ class VmDebootstrap(cliapp.Application):
         self.remove_dirs.append(dirname)
         logging.debug('mkdir %s' % dirname)
         return dirname
-    
+
     def mount(self, device, path=None):
         if not path:
             mount_point = self.mkdtemp()
         else:
             mount_point = path
-        self.message('Mounting %s on %s' % (device,mount_point))
+        self.message('Mounting %s on %s' % (device, mount_point))
         self.runcmd(['mount', device, mount_point])
         self.mount_points.append(mount_point)
         logging.debug('mounted %s on %s' % (device, mount_point))
@@ -212,7 +213,7 @@ class VmDebootstrap(cliapp.Application):
 
     def create_empty_image(self):
         self.message('Creating disk image')
-        self.runcmd(['qemu-img', 'create', '-f', 'raw', 
+        self.runcmd(['qemu-img', 'create', '-f', 'raw',
                      self.settings['image'],
                      str(self.settings['size'])])
 
@@ -221,11 +222,11 @@ class VmDebootstrap(cliapp.Application):
         self.runcmd(['parted', '-s', self.settings['image'],
                      'mklabel', 'msdos'])
         if self.settings['bootsize'] and self.settings['bootsize'] is not '0%':
-            bootsize=str(self.settings['bootsize']/(1024*1024))
+            bootsize = str(self.settings['bootsize'] / (1024 * 1024))
             self.runcmd(['parted', '-s', self.settings['image'],
                          'mkpart', 'primary', 'fat16', '0', bootsize])
         else:
-            bootsize='0%'
+            bootsize = '0%'
         self.runcmd(['parted', '-s', self.settings['image'],
                      'mkpart', 'primary', bootsize, '100%'])
         self.runcmd(['parted', '-s', self.settings['image'],
@@ -253,12 +254,12 @@ class VmDebootstrap(cliapp.Application):
         root = '/dev/mapper/%s' % devices[rootindex]
         if self.settings['bootsize']:
             boot = '/dev/mapper/%s' % devices[bootindex]
-        return (root,boot)
+        return (root, boot)
 
     def mkfs(self, device, type):
         self.message('Creating filesystem %s' % type)
         self.runcmd(['mkfs', '-t', type, device])
-    
+
     def debootstrap(self, rootdir):
         self.message('Debootstrapping')
 
@@ -302,7 +303,7 @@ class VmDebootstrap(cliapp.Application):
         hostname = self.settings['hostname']
         with open(os.path.join(rootdir, 'etc', 'hostname'), 'w') as f:
             f.write('%s\n' % hostname)
-            
+
         etc_hosts = os.path.join(rootdir, 'etc', 'hosts')
         try:
             with open(etc_hosts, 'r') as f:
@@ -352,8 +353,8 @@ class VmDebootstrap(cliapp.Application):
             self.runcmd_unchecked(['chroot', rootdir, 'dpkg', '-i'] + filenames)
         logging.debug('stdout:\n%s' % out)
         logging.debug('stderr:\n%s' % err)
-        out = self.runcmd(['chroot', rootdir, 
-                     'apt-get', '-f', '--no-remove', 'install'])
+        out = self.runcmd(['chroot', rootdir,
+                          'apt-get', '-f', '--no-remove', 'install'])
         logging.debug('stdout:\n%s' % out)
         shutil.rmtree(tmp)
 
@@ -407,16 +408,16 @@ class VmDebootstrap(cliapp.Application):
 
     def setup_networking(self, rootdir):
         self.message('Setting up networking')
-        
+
         f = open(os.path.join(rootdir, 'etc', 'network', 'interfaces'), 'w')
         f.write('auto lo\n')
         f.write('iface lo inet loopback\n')
-        
+
         if self.settings['enable-dhcp']:
             f.write('\n')
             f.write('auto eth0\n')
             f.write('iface eth0 inet dhcp\n')
-            
+
         f.close()
 
     def append_serial_console(self, rootdir):
@@ -458,18 +459,18 @@ kernel %(kernel)s
 append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
 %(extserial)s
 ''' % {
-    'kernel': kernel_image,
-    'initrd': initrd_image,
-    'uuid': uuid,
-    'kserial': 
-        'console=ttyS0,115200' if self.settings['serial-console'] else '',
-    'extserial': 'serial 0 115200' if self.settings['serial-console'] else '',
-})
+            'kernel': kernel_image,
+            'initrd': initrd_image,
+            'uuid': uuid,
+            'kserial':
+            'console=ttyS0,115200' if self.settings['serial-console'] else '',
+            'extserial': 'serial 0 115200' if self.settings['serial-console'] else '',
+        })
         f.close()
 
         self.runcmd(['extlinux', '--install', rootdir])
         self.runcmd(['sync'])
-        import time; time.sleep(2)
+        time.sleep(2)
 
     def optimize_image(self, rootdir):
         """
@@ -489,8 +490,8 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
         self.message("Running mksquashfs")
         suffixed = "%s.squashfs" % self.settings['image']
         self.runcmd(['mksquashfs', self.settings['image'],
-            suffixed,
-            '-no-progress', '-comp', 'xz'], ignore_fail=False)
+                     suffixed,
+                     '-no-progress', '-comp', 'xz'], ignore_fail=False)
         os.unlink(self.settings['image'])
         self.settings['image'] = suffixed
 
@@ -499,7 +500,7 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
 
         self.message('Cleaning up')
 
-        # Umount in the reverse mount order 
+        # Umount in the reverse mount order
         if self.settings['image']:
             for i in xrange(len(self.mount_points) - 1, -1, -1):
                 mount_point = self.mount_points[i]
@@ -533,9 +534,7 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
         self.message("Changing owner to %s" % self.settings["owner"])
         subprocess.call(["chown",
                          self.settings["owner"],
-                         self.settings["image"]])            
-
+                         self.settings["image"]])
 
 if __name__ == '__main__':
     VmDebootstrap(version=__version__).run()
-