]> git.siccegge.de Git - forks/vmdebootstrap.git/blobdiff - vmdebootstrap
pylint tweaks
[forks/vmdebootstrap.git] / vmdebootstrap
index 63ade3aaa6d1aa54251c53338c672ee182beefe6..49c21c89bcc28e9350b478ff41654106377f11e1 100755 (executable)
@@ -27,7 +27,7 @@ import tempfile
 import time
 
 
-__version__ = '0.6'
+__version__ = '0.7'
 
 # pylint: disable=invalid-name
 
@@ -333,6 +333,8 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
                 partoffset = self.settings['bootoffset'] / (1024 * 1024)
                 self.message("Using bootoffset: %smib %s bytes" % (partoffset, self.settings['bootoffset']))
         if self.settings['bootsize'] and self.settings['bootsize'] is not '0%':
+            if self.settings['grub'] and not partoffset:
+                partoffset = 1
             bootsize = self.settings['bootsize'] / (1024 * 1024)
             bootsize += partoffset
             self.message("Using bootsize %smib: %s bytes" % (bootsize, self.settings['bootsize']))
@@ -394,7 +396,7 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
                    if line.startswith('add map ')]
         if len(devices) != parts:
             msg = 'Surprising number of partitions - check output of losetup -a'
-            logging.debug("%s" % self.runcmd(['losetup', '-a']))
+            logging.debug("%s", self.runcmd(['losetup', '-a']))
             logging.debug("%s: devices=%s parts=%s", msg, devices, parts)
             raise cliapp.AppException(msg)
         root = '/dev/mapper/%s' % devices[rootindex]
@@ -423,6 +425,8 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
         if not self.settings['no-kernel']:
             if self.settings['arch'] == 'i386':
                 kernel_arch = '486'
+            elif self.settings['arch'] == 'armhf':
+                kernel_arch = 'armmp'
             else:
                 kernel_arch = self.settings['arch']
             kernel_image = 'linux-image-%s' % kernel_arch
@@ -597,6 +601,19 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
             with open(inittab, 'a') as f:
                 f.write('\nS0:23:respawn:%s\n' % serial_command)
 
+    # pylint: disable=no-self-use
+    def _grub_serial_console(self, rootdir):
+        cmdline = 'GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=tty1 console=ttyS0,38400n8"'
+        terminal = 'GRUB_TERMINAL="serial gfxterm"'
+        command = 'GRUB_SERIAL_COMMAND="serial --speed=38400 --unit=0 --parity=no --stop=1"'
+        grub_cfg = os.path.join(rootdir, 'etc', 'default', 'grub')
+        logging.debug("Allowing serial output in grub config %s", grub_cfg)
+        with open(grub_cfg, 'a+') as cfg:
+            cfg.write("# %s serial support\n" % os.path.basename(__file__))
+            cfg.write("%s\n" % cmdline)
+            cfg.write("%s\n" % terminal)
+            cfg.write("%s\n" % command)
+
     def install_grub2(self, rootdev, rootdir):
         self.message("Configuring grub2")
         # rely on kpartx using consistent naming to map loop0p1 to loop0
@@ -607,26 +624,18 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
                      '%s' % os.path.join(rootdir, 'proc')])
         self.runcmd(['mount', '/sys', '-t', 'sysfs', '-obind',
                      '%s' % os.path.join(rootdir, 'sys')])
+        if self.settings['serial-console']:
+            self._grub_serial_console(rootdir)
 
-        cmdline = 'GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=tty1 console=ttyS0,38400n8"'
-        terminal = 'GRUB_TERMINAL="serial gfxterm"'
-        command = 'GRUB_SERIAL_COMMAND="serial --speed=38400 --unit=0 --parity=no --stop=1"'
-        grub_cfg = os.path.join(rootdir, 'etc', 'default', 'grub')
-        logging.debug("Allowing serial output in grub config %s", grub_cfg)
-        with open(grub_cfg, 'a+') as cfg:
-            cfg.write("# %s serial support\n" % os.path.basename(__file__))
-            cfg.write("%s\n" % cmdline)
-            cfg.write("%s\n" % terminal)
-            cfg.write("%s\n" % command)
         try:
             self.runcmd(['chroot', rootdir, 'update-grub'])
             self.runcmd(['chroot', rootdir, 'grub-install', install_dev])
         except cliapp.AppException:
             self.message("Failed. Is grub2-common installed? Using extlinux.")
+            self.install_extlinux(rootdev, rootdir)
         self.runcmd(['umount', os.path.join(rootdir, 'sys')])
         self.runcmd(['umount', os.path.join(rootdir, 'proc')])
         self.runcmd(['umount', os.path.join(rootdir, 'dev')])
-        self.install_extlinux(rootdev, rootdir)
 
     def install_extlinux(self, rootdev, rootdir):
         if not os.path.exists("/usr/bin/extlinux"):
@@ -746,7 +755,7 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
         with open('/dev/tty', 'w') as tty:
             try:
                 cliapp.runcmd([script, rootdir, self.settings['image']], stdout=tty, stderr=tty)
-            except IOError as e:
+            except IOError:
                 subprocess.call([script, rootdir, self.settings['image']])
 
     def create_tarball(self, rootdir):