#! /usr/bin/env python import os import os.path import logging from shutil import copyfile class GrubFloppy: run_sudo= "" mnt_floppy= "/mnt/floppy" dev_floppy= "/dev/fd0" grub_conf= "/boot/grub/grub.conf" def set_sudo(self): if test "$UID" != "0": export PATH="$PATH:/sbin:/usr/sbin" self.run_sudo= "sudo " else: self.run_sudo= "" # def prep_mnt_floppy(self): if os.path.isdir( self.mnt_floppy): self.rmfloppy=False else: self.mnt_floppy= "/tmp/floppy" logging.info( "mkdir "+self.mnt_floppy) os.mkdir( self.mnt_floppy) self.rmfloppy=True # def done_mnt_floppy(self): if self.rmfloppy: logging.info( "rmdir "+self.mnt_floppy) os.rmdir( self.mnt_floppy) def format_floppy(self): command= self.sudo+"fdformat "+self.dev_floppy logging.info( command) ; os.spawnle( command) def mkfs_floppy(self): command= self.sudo+"mke2fs "+self.dev_floppy logging.info( command) ; os.spawnle( command) def mount_floppy(self): command= self.sudo+"mount -t ext2 "+self.dev_floppy+" "+self.mnt_floppy logging.info( command) ; os.spawnle( command) def umount_floppy(self): command= self.sudo+"umount "+self.mnt_floppy logging.info( command) ; os.spawnle( command) def grub_install_floppy(self): command= (self.sudo+"grub-install "+ "--root-directory="+self.mnt_floppy+ " ("+os.path.basename(self.dev_floppy)+")") logging.info( command) ; os.spawnle( command) def copy_grub_conf(self): source= self.grub.conf target= self.mnt_floppy+self.grub_conf os.path.mkdirs( os.path.dirname( target)) copyfile( source, target) def run(self): self.set_sudo() self.prep_mnt_floppy() self.format_floppy() self.mkfs_floppy() self.mount_floppy() self.grub_install_floppy() self.copy_grub_conf() self.unmount_floppy() self.done_mnt_floppy() if __name__ = "__main__": GrubFloppy().run()