Version 13.4.5
[livecd.git] / tools / image-creator
blob6f2604c478d2cc579f53e32f2b348cfbfba91470
1 #!/usr/bin/python -tt
3 # image-creator: Create an ext3 system image
5 # Copyright 2007, Red Hat Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Library General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 import os
21 import sys
22 import shutil
23 import optparse
24 import logging
26 import imgcreate
28 def parse_options(args):
29 parser = optparse.OptionParser(usage = "%prog [--name=<name>] <kickstart>")
31 parser.add_option("-n", "--name", type="string", dest="name",
32 help="Image name and filesystem label")
34 imgcreate.setup_logging(parser)
36 (options, args) = parser.parse_args()
38 if len(args) != 1:
39 parser.print_usage()
40 sys.exit(1)
42 return (args[0], options)
44 def main():
45 (kscfg, options) = parse_options(sys.argv[1:])
47 if os.geteuid () != 0:
48 print >> sys.stderr, "You must run image-creator as root"
49 return 1
51 try:
52 ks = imgcreate.read_kickstart(kscfg)
53 except imgcreate.CreatorError, e:
54 logging.error("Unable to load kickstart file '%s' : %s" % (kscfg, e))
55 return 1
57 if options.name:
58 name = options.name
59 else:
60 name = imgcreate.build_name(kscfg)
62 creator = imgcreate.LoopImageCreator(ks, name)
64 try:
65 creator.create()
66 except imgcreate.CreatorError, e:
67 logging.error("Unable to create image : %s" % e)
68 return 1
69 finally:
70 creator.cleanup()
72 return 0
74 if __name__ == "__main__":
75 sys.exit(main())