3 # Chris Lumens <clumens@redhat.com>
5 # Copyright 2005, 2006, 2007 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, file=None, exitval=1):
32 shutil.rmtree(destdir)
34 # Don't care if this file doesn't exist.
43 op = OptionParser(usage="usage: %prog [options] ksfile|url")
44 op.add_option("-e", "--firsterror", dest="firsterror", action="store_true",
45 default=False, help=_("halt after the first error or warning"))
46 op.add_option("-i", "--followincludes", dest="followincludes",
47 action="store_true", default=False,
48 help=_("parse include files when %include is seen"))
49 op.add_option("-v", "--version", dest="version", default=DEVEL,
50 help=_("version of kickstart syntax to validate against"))
52 (opts, extra) = op.parse_args(sys.argv[1:])
58 destdir = tempfile.mkdtemp("", "ksvalidator-tmp-", "/tmp")
59 f = urlgrabber.urlgrab(extra[0], filename="%s/ks.cfg" % destdir)
62 handler = makeVersion(opts.version)
63 except KickstartVersionError:
64 print _("The version %s is not supported by pykickstart" % opts.version)
67 ksparser = KickstartParser(handler, followIncludes=opts.followincludes,
68 errorsAreFatal=opts.firsterror)
70 # turn DeprecationWarnings into errors
71 warnings.filterwarnings("error")
74 processedFile = preprocessKickstart(f)
75 ksparser.readKickstart(processedFile)
76 except DeprecationWarning, msg:
77 print _("File uses a deprecated option or command.\n%s") % msg
78 cleanup(destdir, processedFile)
79 except (KickstartParseError, KickstartValueError), msg:
81 cleanup(destdir, processedFile)
82 except KickstartError:
83 print _("General kickstart error in input file")
84 cleanup(destdir, processedFile)
86 print _("General error in input file: %s") % e
89 cleanup(destdir, processedFile, exitval=0)