3 # Chris Lumens <clumens@redhat.com>
5 # Copyright 2005, 2006, 2007 Red Hat, Inc.
7 # This copyrighted material is made available to anyone wishing to use, modify,
8 # copy, or redistribute it subject to the terms and conditions of the GNU
9 # General Public License v.2. This program is distributed in the hope that it
10 # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
11 # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 # See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
17 # trademarks that are incorporated in the source code or documentation are not
18 # subject to the GNU General Public License and may only be used or replicated
19 # with the express permission of Red Hat, Inc.
29 from pykickstart.errors import *
30 from pykickstart.parser import *
31 from pykickstart.version import *
34 gettext.install("pykickstart", unicode=True)
36 def cleanup(destdir, file=None, exitval=1):
37 shutil.rmtree(destdir)
39 # Don't care if this file doesn't exist.
48 op = OptionParser(usage="usage: %prog [options] ksfile|url")
49 op.add_option("-e", "--firsterror", dest="firsterror", action="store_true",
50 default=False, help=_("halt after the first error or warning"))
51 op.add_option("-i", "--followincludes", dest="followincludes",
52 action="store_true", default=False,
53 help=_("parse include files when %include is seen"))
54 op.add_option("-l", "--listversions", dest="listversions", action="store_true",
56 help=_("list the available versions of kickstart syntax"))
57 op.add_option("-v", "--version", dest="version", default=DEVEL,
58 help=_("version of kickstart syntax to validate against"))
60 (opts, extra) = op.parse_args(sys.argv[1:])
63 for key in sorted(versionMap.keys()):
72 destdir = tempfile.mkdtemp("", "ksvalidator-tmp-", "/tmp")
74 f = urlgrabber.urlgrab(extra[0], filename="%s/ks.cfg" % destdir)
75 except urlgrabber.grabber.URLGrabError, e:
76 print _("Error reading %s:\n%s" % (extra[0],e))
80 handler = makeVersion(opts.version)
81 except KickstartVersionError:
82 print _("The version %s is not supported by pykickstart" % opts.version)
85 ksparser = KickstartParser(handler, followIncludes=opts.followincludes,
86 errorsAreFatal=opts.firsterror)
88 # turn DeprecationWarnings into errors
89 warnings.filterwarnings("error")
94 processedFile = preprocessKickstart(f)
95 ksparser.readKickstart(processedFile)
96 cleanup(destdir, processedFile, exitval=0)
97 except DeprecationWarning, msg:
98 print _("File uses a deprecated option or command.\n%s") % msg
99 cleanup(destdir, processedFile)
100 except (KickstartParseError, KickstartValueError), msg:
102 cleanup(destdir, processedFile)
103 except KickstartError:
104 print _("General kickstart error in input file")
105 cleanup(destdir, processedFile)
107 print _("General error in input file: %s") % e
108 cleanup(destdir, processedFile)