import datetime, logging, os, re, subprocess, sys, tempfile, time, os.path
# global variables
-PROG_VERSION = "0.9.11"
+PROG_VERSION = "0.9.12"
MOUNTED = set() # register mountpoints
TMPFILES = set() # register tmpfiles
DATESTAMP = time.mktime(datetime.datetime.now().timetuple()) # unique identifier for syslinux.cfg
# TODO: doesn't work for proc = execute(subprocess.Popen...() -> any ideas?
if options.dryrun:
# pylint: disable-msg=W0141
- logging.debug('dry-run only: %s(%s)' % (get_function_name(f), ', '.join(map(repr, exec_arguments))))
+ logging.debug('dry-run only: %s(%s)', get_function_name(f), ', '.join(map(repr, exec_arguments)))
else:
# pylint: disable-msg=W0142
return f(*exec_arguments)
return 0
logging.info("Formating partition with fat16 filesystem")
- logging.debug("mkfs.vfat -F 16 %s" % device)
+ logging.debug("mkfs.vfat -F 16 %s", device)
proc = subprocess.Popen(["mkfs.vfat", "-F", "16", device])
proc.wait()
if proc.returncode != 0:
cleanup()
sys.exit(1)
except CriticalException, error:
- logging.critical("Fatal: %s" % error)
+ logging.critical("Fatal: %s", error)
cleanup()
sys.exit(1)
# syslinux -d boot/isolinux /dev/sdb1
logging.info("Installing syslinux as bootloader")
- logging.debug("syslinux -d boot/syslinux %s" % device)
+ logging.debug("syslinux -d boot/syslinux %s", device)
proc = subprocess.Popen(["syslinux", "-d", "boot/syslinux", device])
proc.wait()
if proc.returncode != 0:
try:
install_syslinux(device)
except CriticalException, error:
- logging.critical("Fatal: %s" % error)
+ logging.critical("Fatal: %s", error)
cleanup()
sys.exit(1)
else:
try:
install_grub(device)
except CriticalException, error:
- logging.critical("Fatal: %s" % error)
+ logging.critical("Fatal: %s", error)
cleanup()
sys.exit(1)
# to support -A for extended partitions:
logging.info("Activating partitions in MBR via lilo")
- logging.debug("%s -S /dev/null -M %s ext" % (lilo, device))
+ logging.debug("%s -S /dev/null -M %s ext", lilo, device)
proc = subprocess.Popen([lilo, "-S", "/dev/null", "-M", device, "ext"])
proc.wait()
if proc.returncode != 0:
raise Exception("error executing lilo")
# activate partition:
- logging.debug("%s -S /dev/null -A %s 1" % (lilo, device))
+ logging.debug("%s -S /dev/null -A %s 1", lilo, device)
proc = subprocess.Popen([lilo, "-S", "/dev/null", "-A", device, "1"])
proc.wait()
if proc.returncode != 0:
raise Exception("/usr/lib/syslinux/mbr.bin can not be read")
logging.info("Installing syslinux MBR")
- logging.debug("cat /usr/lib/syslinux/mbr.bin > %s" % device)
+ logging.debug("cat /usr/lib/syslinux/mbr.bin > %s", device)
try:
# TODO -> use Popen instead?
retcode = subprocess.call("cat /usr/lib/syslinux/mbr.bin > "+ device, shell=True)
if retcode < 0:
- logging.critical("Error copying MBR to device (%s)" % retcode)
+ logging.critical("Error copying MBR to device (%s)", retcode)
except OSError, error:
- logging.critical("Execution failed:", error)
+ logging.critical("Execution failed: %s", error)
def install_mir_mbr(mbrtemplate, device, partition, ismirbsdmbr=True):
logging.info("Installing default MBR")
if not os.path.isfile(mbrtemplate):
- logging.critical("Error: %s can not be read." % mbrtemplate)
+ logging.critical("Error: %s can not be read.", mbrtemplate)
raise CriticalException("Error installing MBR (either try --syslinux-mbr or install missing file?)")
if (partition < 0) or (partition > 3):
tmpf = tempfile.NamedTemporaryFile()
- logging.debug("executing: dd if='%s' of='%s' bs=512 count=1" % (device, tmpf.name))
+ logging.debug("executing: dd if='%s' of='%s' bs=512 count=1", device, tmpf.name)
proc = subprocess.Popen(["dd", "if=%s" % device, "of=%s" % tmpf.name, "bs=512", "count=1"], stderr=file(os.devnull, "r+"))
proc.wait()
if proc.returncode != 0:
raise Exception("error executing dd (first run)")
- logging.debug("executing: dd if=%s of=%s bs=%s count=1 conv=notrunc" % (mbrtemplate,
- tmpf.name, nmbrbytes))
+ logging.debug("executing: dd if=%s of=%s bs=%s count=1 conv=notrunc", mbrtemplate,
+ tmpf.name, nmbrbytes)
proc = subprocess.Popen(["dd", "if=%s" % mbrtemplate, "of=%s" % tmpf.name, "bs=%s" % nmbrbytes,
"count=1", "conv=notrunc"], stderr=file(os.devnull, "r+"))
proc.wait()
tmpf.file.write(mbrcode)
tmpf.file.close()
- logging.debug("executing: dd if='%s' of='%s' bs=512 count=1 conv=notrunc" % (tmpf.name, device))
+ logging.debug("executing: dd if='%s' of='%s' bs=512 count=1 conv=notrunc", tmpf.name, device)
proc = subprocess.Popen(["dd", "if=%s" % tmpf.name, "of=%s" % device, "bs=512", "count=1",
"conv=notrunc"], stderr=file(os.devnull, "r+"))
proc.wait()
raise CriticalException("Error executing mount: %s already mounted - please unmount before invoking grml2usb" % source)
if os.path.isdir(source):
- logging.debug("Source %s is not a device, therefore not mounting." % source)
+ logging.debug("Source %s is not a device, therefore not mounting.", source)
return 0
- logging.debug("mount %s %s %s" % (mount_options, source, target))
+ logging.debug("mount %s %s %s", mount_options, source, target)
proc = subprocess.Popen(["mount"] + list(mount_options) + [source, target])
proc.wait()
if proc.returncode != 0:
raise CriticalException("Error executing mount (no filesystem on the partition?)")
else:
- logging.debug("register_mountpoint(%s)" % target)
+ logging.debug("register_mountpoint(%s)", target)
register_mountpoint(target)
target_unmount = True
if not target_unmount:
- logging.debug("%s not mounted anymore" % target)
+ logging.debug("%s not mounted anymore", target)
else:
- logging.debug("umount %s %s" % (list(unmount_options), target))
+ logging.debug("umount %s %s", list(unmount_options), target)
proc = subprocess.Popen(["umount"] + list(unmount_options) + [target])
proc.wait()
if proc.returncode != 0:
raise Exception("Error executing umount")
else:
- logging.debug("unregister_mountpoint(%s)" % target)
+ logging.debug("unregister_mountpoint(%s)", target)
unregister_mountpoint(target)
@source: source file/directory
@target: target file/directory"""
- logging.debug(source, target)
+ logging.debug("Source: %s / Target: %s", source, target)
proc = subprocess.Popen(["rsync", "-rlptDH", "--inplace", source, target])
proc.wait()
if proc.returncode == 12:
sys.exit(1)
if proc.returncode != 0:
- logging.critical("Fatal: could not install %s" % source)
+ logging.critical("Fatal: could not install %s", source)
cleanup()
sys.exit(1)
execute(mkdir, grub_target)
if not os.path.isfile(GRML2USB_BASE + "/grub/splash.xpm.gz"):
- logging.critical("Error: %s/grub/splash.xpm.gz can not be read." % (GRML2USB_BASE, ))
- logging.critical("Please make sure you've the grml2usb Debian package installed!")
+ logging.critical("Error: %s/grub/splash.xpm.gz can not be read.", GRML2USB_BASE)
+ logging.critical("Please make sure you've installed the grml2usb (Debian) package!")
raise
else:
exec_rsync(GRML2USB_BASE + '/grub/splash.xpm.gz', grub_target + 'splash.xpm.gz')
@device: partition where grml2usb files should be removed from"""
# TODO - not implemented yet
- logging.critical("TODO: uninstalling files from %s not yet implement, sorry." % device)
+ logging.critical("TODO: uninstalling files from %s not yet implement, sorry.", device)
def identify_grml_flavour(mountpath):
grml_flavour = re.match(r'[\w-]*', grml_info).group()
except TypeError:
raise
- except:
- logging.critical("Unexpected error:", sys.exc_info()[0])
+ except Exception, e:
+ logging.critical("Unexpected error: %s", e)
raise
return grml_flavour
syslinux_config_file.write(generate_flavour_specific_syslinux_config(grml_flavour, bootopt))
syslinux_config_file.close()
- logging.debug("Generating isolinux/syslinux splash %s" % syslinux_target + 'boot.msg')
+ logging.debug("Generating isolinux/syslinux splash %s", syslinux_target + 'boot.msg')
isolinux_splash = open(syslinux_target + 'boot.msg', 'w')
isolinux_splash.write(generate_isolinux_splash(grml_flavour))
isolinux_splash.close()
try:
handle_syslinux_config(grml_flavour, target)
except CriticalException, error:
- logging.critical("Fatal: %s" % error)
+ logging.critical("Fatal: %s", error)
sys.exit(1)
if options.skipgrubconfig:
try:
handle_grub_config(grml_flavour, device, target)
except CriticalException, error:
- logging.critical("Fatal: %s" % error)
+ logging.critical("Fatal: %s", error)
sys.exit(1)
def handle_dir(live_image, device):
@live_image: directory where currently running live system resides (usually /live/image)
@device: partition where the specified ISO should be installed to"""
- logging.info("Using %s as install base" % live_image)
+ logging.info("Using %s as install base", live_image)
if os.path.isdir(device):
logging.info("Specified target is a directory, therefore not mounting.")
try:
mount(device, device_mountpoint, "")
except CriticalException, error:
- logging.critical("Fatal: %s" % error)
+ logging.critical("Fatal: %s", error)
cleanup()
sys.exit(1)
try:
try:
grml_flavour = identify_grml_flavour(live_image)
- logging.info("Identified grml flavour \"%s\"." % grml_flavour)
+ logging.info("Identified grml flavour \"%s\".", grml_flavour)
install_iso_files(grml_flavour, live_image, device, device_mountpoint)
except TypeError:
logging.critical("Fatal: a critical error happend during execution (not a grml ISO?), giving up")
os.rmdir(device_mountpoint)
unregister_tmpfile(device_mountpoint)
except CriticalException, error:
- logging.critical("Fatal: %s" % error)
+ logging.critical("Fatal: %s", error)
cleanup()
@iso: full path to the ISO that should be installed to the specified device
@device: partition where the specified ISO should be installed to"""
- logging.info("Using ISO %s" % iso)
+ logging.info("Using ISO %s", iso)
iso_mountpoint = tempfile.mkdtemp(prefix="grml2usb")
register_tmpfile(iso_mountpoint)
remove_iso_mountpoint = True
if not os.path.isfile(iso):
- logging.critical("Fatal: specified ISO %s could not be read" % iso)
+ logging.critical("Fatal: specified ISO %s could not be read", iso)
cleanup()
sys.exit(1)
try:
mount(iso, iso_mountpoint, ["-o", "loop", "-t", "iso9660"])
except CriticalException, error:
- logging.critical("Fatal: %s" % error)
+ logging.critical("Fatal: %s", error)
sys.exit(1)
if os.path.isdir(device):
try:
mount(device, device_mountpoint, "")
except CriticalException, error:
- logging.critical("Fatal: %s" % error)
+ logging.critical("Fatal: %s", error)
cleanup()
sys.exit(1)
try:
try:
grml_flavour = identify_grml_flavour(iso_mountpoint)
- logging.info("Identified grml flavour \"%s\"." % grml_flavour)
+ logging.info("Identified grml flavour \"%s\".", grml_flavour)
install_iso_files(grml_flavour, iso_mountpoint, device, device_mountpoint)
except TypeError:
logging.critical("Fatal: a critical error happend during execution (not a grml ISO?), giving up")
os.rmdir(device_mountpoint)
unregister_tmpfile(device_mountpoint)
except CriticalException, error:
- logging.critical("Fatal: %s" % error)
+ logging.critical("Fatal: %s", error)
cleanup()
# into /dev/loop of course, therefore use /dev/loop1 as mbr_device
if mbr_device == "/dev/loop":
mbr_device = device
- logging.info("Detected loop device - using %s as MBR device therefore" % mbr_device)
+ logging.info("Detected loop device - using %s as MBR device therefore", mbr_device)
skip_install_mir_mbr = True
try:
if options.copyonly:
logging.info("Not installing bootloader and its files as requested via option copyonly.")
elif os.path.isdir(device):
- logging.info("Not installing bootloader as %s is a directory." % device)
+ logging.info("Not installing bootloader as %s is a directory.", device)
else:
install_bootloader(device)
handle_bootloader(device)
- logging.info("Note: grml flavour %s was installed as the default booting system." % GRML_DEFAULT)
+ logging.info("Note: grml flavour %s was installed as the default booting system.", GRML_DEFAULT)
for flavour in GRML_FLAVOURS:
- logging.info("Note: you can boot flavour %s using '%s' on the commandline." % (flavour, flavour))
+ logging.info("Note: you can boot flavour %s using '%s' on the commandline.", flavour, flavour)
# finally be politely :)
- logging.info("Finished execution of grml2usb (%s). Have fun with your grml system." % PROG_VERSION)
+ logging.info("Finished execution of grml2usb (%s). Have fun with your grml system.", PROG_VERSION)
if __name__ == "__main__":