3 # Chris Lumens <clumens@redhat.com>
5 # Copyright 2005, 2006 Red Hat, Inc.
7 # This software may be freely redistributed under the terms of the GNU
8 # general public license.
10 # You should have received a copy of the GNU General Public License
11 # along with this program; if not, write to the Free Software
12 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 from pykickstart.data import *
23 from pykickstart.parser import *
25 from rhpl.translate import _
26 import rhpl.translate as translate
28 translate.textdomain("pykickstart")
30 def cleanup(destdir, exitval=1):
31 shutil.rmtree(destdir)
34 op = OptionParser(usage="usage: %prog [options] ksfile|url")
35 op.add_option("-e", "--firsterror", dest="firsterror", action="store_true",
36 default=False, help=_("halt after the first error or warning"))
37 op.add_option("-i", "--followincludes", dest="followincludes",
38 action="store_true", default=False,
39 help=_("parse include files when %include is seen"))
41 (opts, extra) = op.parse_args(sys.argv[1:])
47 destdir = tempfile.mkdtemp("", "ksvalidator-tmp-", "/tmp")
48 f = urlgrabber.urlgrab(extra[0], filename="%s/ks.cfg" % destdir)
50 ksdata = KickstartData()
51 kshandlers = KickstartHandlers(ksdata)
52 ksparser = KickstartParser(ksdata, kshandlers,
53 followIncludes=opts.followincludes,
54 errorsAreFatal=opts.firsterror)
56 # turn DeprecationWarnings into errors
57 warnings.filterwarnings("error")
60 ksparser.readKickstart(f)
61 except DeprecationWarning, msg:
62 print _("File uses a deprecated option or command.\n%s") % msg
64 except (KickstartParseError, KickstartValueError), msg:
67 except KickstartError:
68 print _("General kickstart error in input file")
71 print _("General error in input file: %s") % e
74 cleanup(destdir, exitval=0)