Have objects in one version subclass objects in a previous version. Not
[pykickstart.git] / validator / ksvalidator
blob865d1026323db0af35b8c49500a1e62df2356acf
1 #!/usr/bin/python2
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.
15 import optparse
16 import os
17 import sys
18 import warnings
19 import tempfile
20 import urlgrabber
21 import shutil
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)
33     os._exit(exitval)
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:])
46 if len(extra) != 1:
47     op.print_help()
48     os._exit(1)
49 else:
50     destdir = tempfile.mkdtemp("", "ksvalidator-tmp-", "/tmp")
51     f = urlgrabber.urlgrab(extra[0], filename="%s/ks.cfg" % destdir)
53 try:
54     handler = makeVersion(opts.version)
55 except KickstartVersionError:
56     print _("The version %s is not supported by pykickstart" % opts.version)
57     cleanup(destdir)
59 ksparser = KickstartParser(handler, followIncludes=opts.followincludes,
60                            errorsAreFatal=opts.firsterror)
62 # turn DeprecationWarnings into errors
63 warnings.filterwarnings("error")
65 try:
66     ksparser.readKickstart(f)
67 except DeprecationWarning, msg:
68     print _("File uses a deprecated option or command.\n%s") % msg
69     cleanup(destdir)
70 except (KickstartParseError, KickstartValueError), msg:
71     print msg
72     cleanup(destdir)
73 except KickstartError:
74     print _("General kickstart error in input file")
75     cleanup(destdir)
76 except Exception, e:
77     print _("General error in input file:  %s") % e
78     cleanup(destdir)
80 cleanup(destdir, exitval=0)