Add new RHEL7 logvol objects to master
[pykickstart.git] / tools / ksverdiff
blob6f31fe0110ecb9878fcba0c0e60a4d7e065bac87
1 #!/usr/bin/python
3 # Chris Lumens <clumens@redhat.com>
5 # Copyright 2009-2014 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.
22 import argparse
23 import sys
24 from pykickstart.base import DeprecatedCommand
25 from pykickstart.errors import KickstartVersionError
26 from pykickstart.version import makeVersion, versionMap
28 import gettext
29 gettext.textdomain("pykickstart")
30 _ = lambda x: gettext.ldgettext("pykickstart", x)
32 def getCommandSet(handler):
33 return set(handler.commands.keys())
35 def getOptSet(lst):
36 return set(map(lambda o: o.get_opt_string(), lst))
38 def printList(lst):
39 for e in lst:
40 sys.stdout.write("%s " % e)
42 print
44 op = argparse.ArgumentParser()
45 op.add_argument("-f", "--from", dest="f")
46 op.add_argument("-t", "--to", dest="t")
47 op.add_argument("-l", "--listversions", dest="listversions", action="store_true",
48 default=False,
49 help=_("list the available versions of kickstart syntax"))
51 opts = op.parse_args(sys.argv[1:])
53 if opts.listversions:
54 for key in sorted(versionMap.keys()):
55 print(key)
57 sys.exit(1)
59 if not opts.f or not opts.t:
60 print(_("You must specify two syntax versions."))
61 sys.exit(1)
63 try:
64 fromHandler = makeVersion(opts.f)
65 toHandler = makeVersion(opts.t)
66 except KickstartVersionError as exn:
67 print(_("The version %s is not supported by pykickstart") % exn)
68 sys.exit(1)
70 fromCmdSet = getCommandSet(fromHandler)
71 toCmdSet = getCommandSet(toHandler)
72 bothSet = fromCmdSet & toCmdSet
74 print(_("The following commands were removed in %s:") % opts.t)
75 printList(list(fromCmdSet - toCmdSet))
77 print(_("The following commands were deprecated in %s:") % opts.t)
78 printList(filter(lambda c: isinstance(toHandler.commands[c], DeprecatedCommand), list(bothSet)))
80 print(_("The following commands were added in %s:") % opts.t)
81 printList(list(toCmdSet - fromCmdSet))
83 print
85 for cmd in bothSet:
86 printed = False
88 newOptList = []
89 deprecatedOptList = []
90 removedOptList = []
92 fromCmd = fromHandler.commands[cmd]
93 toCmd = toHandler.commands[cmd]
95 if not hasattr(fromCmd, "op") or not hasattr(toCmd, "op"):
96 continue
98 fromOpt = fromCmd.op.option_list
99 toOpt = toCmd.op.option_list
101 newOptList = getOptSet(toOpt) - getOptSet(fromOpt)
102 removedOptList = getOptSet(fromOpt) - getOptSet(toOpt)
103 deprecatedOptList = getOptSet(filter(lambda cmd: cmd.deprecated == 1, toOpt))
105 if len(newOptList) > 0:
106 print(_("The following options were added to the %s command in %s:") % (cmd, opts.t))
107 printList(list(newOptList))
108 printed = True
110 if len(deprecatedOptList) > 0:
111 print(_("The following options were deprecated from the %s command in %s:") % (cmd, opts.t))
112 printList(list(deprecatedOptList))
113 printed = True
115 if len(removedOptList) > 0:
116 print(_("The following options were removed from the %s command in %s:") % (cmd, opts.t))
117 printList(list(removedOptList))
118 printed = True
120 if printed:
121 print