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.errors import *
23 from pykickstart.parser import *
24 from pykickstart.version import *
26 from rhpl.translate import _
27 import rhpl.translate as translate
29 translate.textdomain("pykickstart")
31 def cleanup(destdir, exitval=1):
32 shutil.rmtree(destdir)
35 op = OptionParser(usage="usage: %prog [options] ksfile|url")
36 op.add_option("-e", "--firsterror", dest="firsterror", action="store_true",
37 default=False, help=_("halt after the first error or warning"))
38 op.add_option("-i", "--followincludes", dest="followincludes",
39 action="store_true", default=False,
40 help=_("parse include files when %include is seen"))
41 op.add_option("-v", "--version", dest="version", default=DEVEL,
42 help=_("version of kickstart syntax to validate against"))
44 (opts, extra) = op.parse_args(sys.argv[1:])
50 destdir = tempfile.mkdtemp("", "ksvalidator-tmp-", "/tmp")
51 f = urlgrabber.urlgrab(extra[0], filename="%s/ks.cfg" % destdir)
54 handler = makeVersion(opts.version)
55 except KickstartVersionError:
56 print _("The version %s is not supported by pykickstart" % opts.version)
59 ksparser = KickstartParser(handler, followIncludes=opts.followincludes,
60 errorsAreFatal=opts.firsterror)
62 # turn DeprecationWarnings into errors
63 warnings.filterwarnings("error")
66 ksparser.readKickstart(f)
67 except DeprecationWarning, msg:
68 print _("File uses a deprecated option or command.\n%s") % msg
70 except (KickstartParseError, KickstartValueError), msg:
73 except KickstartError:
74 print _("General kickstart error in input file")
77 print _("General error in input file: %s") % e
80 cleanup(destdir, exitval=0)