3 # Simple script to take a kickstart config, read it in, parse any %includes,
4 # etc to write out a flattened config that is stand-alone
6 # Copyright 2007-2014, Red Hat, Inc.
7 # Jeremy Katz <katzj@redhat.com>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; version 2 of the License.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Library General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 from __future__
import print_function
27 import pykickstart
.parser
28 from pykickstart
.version
import DEVEL
, makeVersion
31 gettext
.textdomain("pykickstart")
32 _
= lambda x
: gettext
.ldgettext("pykickstart", x
)
35 parser
= argparse
.ArgumentParser()
36 parser
.add_argument("-c", "--config", dest
="kscfg", required
=True,
37 help=_("Path to kickstart config file"))
38 parser
.add_argument("-v", "--version", dest
="version", default
=DEVEL
,
39 help=_("Kickstart version to use for interpreting config"))
40 parser
.add_argument("-o", "--output", dest
="output",
41 help=_("Write flattened config to OUTPUT"))
43 return parser
.parse_args()
48 print(_("Need to specify a config to flatten"), file=sys
.stderr
)
51 ksversion
= makeVersion(opts
.version
)
52 ksparser
= pykickstart
.parser
.KickstartParser(ksversion
)
54 ksparser
.readKickstart(opts
.kscfg
)
55 except IOError as msg
:
56 print(_("Failed to read kickstart file '%s' : %s") % (opts
.kscfg
, msg
), file=sys
.stderr
)
58 except pykickstart
.errors
.KickstartError
as e
:
59 print(_("Failed to parse kickstart file '%s' : %s") % (opts
.kscfg
, e
), file=sys
.stderr
)
63 f
= open(opts
.output
, 'w')
64 except IOError as msg
:
65 print(_("Failed to open output file '%s' : %s") % (opts
.output
, msg
), file=sys
.stderr
)
69 f
.write("%s" % ksparser
.handler
)
72 if __name__
== "__main__":