mkefiboot: use argparse, improve --help output

This commit is contained in:
Will Woods 2011-10-25 16:04:09 -04:00
parent a6c93585c0
commit 87eef3ff00

View File

@ -17,7 +17,7 @@
# #
# Red Hat Author(s): Will Woods <wwoods@redhat.com> # Red Hat Author(s): Will Woods <wwoods@redhat.com>
import os, tempfile, optparse import os, tempfile, argparse
from subprocess import check_call, PIPE from subprocess import check_call, PIPE
from pylorax.imgutils import mkdosimg, round_to_blocks, LoopDev, DMDev, dm_detach from pylorax.imgutils import mkdosimg, round_to_blocks, LoopDev, DMDev, dm_detach
from pylorax.imgutils import mkhfsimg, Mount from pylorax.imgutils import mkhfsimg, Mount
@ -77,34 +77,34 @@ def mkefidisk(efiboot, outfile):
dm_detach(dmdev+"p1") dm_detach(dmdev+"p1")
if __name__ == '__main__': if __name__ == '__main__':
parser = optparse.OptionParser(usage="%prog EFIBOOTDIR IMGFILE") parser = argparse.ArgumentParser(description="Make an EFI boot image from the given directory.")
parser.add_option("-d", "--disk", action="store_true", default=False, parser.add_argument("-d", "--disk", action="store_true",
help="make a full EFI disk image") help="make a full EFI disk image (including partition table)")
parser.add_option("-l", "--label", action="store", default="ANACONDA", parser.add_argument("-a", "--apple", action="store_const", const="apple",
help="filesystem label to use")
parser.add_option("-a", "--apple", action="store_const", const="apple",
dest="imgtype", default="default", dest="imgtype", default="default",
help="make an Apple EFI image (hfsplus, bless loader)") help="make an Apple EFI image (use hfs+, bless bootloader)")
parser.add_option("-i", "--icon", action="store", parser.add_argument("-l", "--label", default="EFI",
help="filesystem label to use (default: %(default)s)")
parser.add_argument("-i", "--icon", metavar="ICONFILE",
help="icon file to include (for Apple EFI image)") help="icon file to include (for Apple EFI image)")
# get args parser.add_argument("bootdir", metavar="EFIBOOTDIR",
(opt, args) = parser.parse_args() help="input directory (will become /EFI/BOOT in the image)")
if len(args) != 2: parser.add_argument("outfile", metavar="OUTPUTFILE",
parser.error("need exactly two arguments") help="output file to write")
(bootdir, outfile) = args opt = parser.parse_args()
# sanity checks # sanity checks
if not os.path.isdir(bootdir): if not os.path.isdir(opt.bootdir):
parser.error("%s is not a directory" % bootdir) parser.error("%s is not a directory" % opt.bootdir)
if os.getuid() > 0: if os.getuid() > 0:
parser.error("need root permissions") parser.error("need root permissions")
if opt.icon and not opt.imgtype == "apple": if opt.icon and not opt.imgtype == "apple":
print "Warning: --icon is only useful for Apple EFI images" print "Warning: --icon is only useful for Apple EFI images"
# do the thing! # do the thing!
if opt.imgtype == "apple": if opt.imgtype == "apple":
mkmacboot(bootdir, outfile, opt.label, opt.icon) mkmacboot(opt.bootdir, opt.outfile, opt.label, opt.icon)
else: else:
mkefiboot(bootdir, outfile, opt.label) mkefiboot(opt.bootdir, opt.outfile, opt.label)
if opt.disk: if opt.disk:
efiboot = tempfile.NamedTemporaryFile(prefix="mkefiboot.").name efiboot = tempfile.NamedTemporaryFile(prefix="mkefiboot.").name
shutil.move(outfile, efiboot) shutil.move(opt.outfile, efiboot)
mkefidisk(efiboot, outfile) mkefidisk(efiboot, opt.outfile)