Have objects in one version subclass objects in a previous version. Not
[pykickstart.git] / pykickstart / version.py
blob42612e64a26a0f29d3b26607c9ed9fd33f6d7ac1
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2006 Red Hat, Inc.
6 # This software may be freely redistributed under the terms of the GNU
7 # general public license.
9 # You should have received a copy of the GNU General Public License
10 # along with this program; if not, write to the Free Software
11 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
13 """
14 Methods for working with kickstart versions.
16 This module defines several symbolic constants that specify kickstart syntax
17 versions. Each version corresponds roughly to one release of Red Hat Linux,
18 Red Hat Enterprise Linux, or Fedora Core as these are where most syntax
19 changes take place.
21 This module also exports several functions:
23 stringToVersion - Convert a string representation of a version number
24 into the symbolic constant.
26 returnClassForVersion - Given a version number, return the matching
27 handler class. This does not return an
28 instance of that class, however.
30 makeVersion - Given a version number, return an instance of the
31 matching handler class.
32 """
33 from pykickstart.errors import KickstartVersionError
35 # Symbolic names for internal version numbers.
36 FC4 = 100
37 FC5 = 150
38 FC6 = 200
40 # This always points at the latest version and is the default.
41 DEVEL = FC6
43 def stringToVersion(string):
44 """Convert string into one of the provided version constants. Raises
45 KickstartVersionError if string does not match anything.
46 """
47 if string == "FC4":
48 return FC4
49 elif string == "FC5":
50 return FC5
51 elif string == "FC6":
52 return FC6
53 elif string == "DEVEL":
54 return DEVEL
55 else:
56 raise KickstartVersionError(string)
58 def returnClassForVersion(version):
59 """Return the class of the syntax handler for version. version can be
60 either a string or the matching constant. Raises KickstartValueError
61 if version does not match anything.
62 """
63 try:
64 version = int(version)
65 except ValueError:
66 version = stringToVersion(version)
68 if version == FC4:
69 from pykickstart.commands.fc4 import FC4Version
70 return FC4Version
71 elif version == FC5:
72 from pykickstart.commands.fc5 import FC5Version
73 return FC5Version
74 elif version == FC6:
75 from pykickstart.commands.fc6 import FC6Version
76 return FC6Version
77 else:
78 raise KickstartVersionError(version)
80 # Given a version of the kickstart syntax, this function imports the correct
81 # handler for that version and returns an instance of it.
82 def makeVersion(version=DEVEL):
83 """Return a new instance of the syntax handler for version. version can be
84 either a string or the matching constant. This function is useful for
85 standalone programs which just need to handle a specific version of
86 kickstart syntax (as provided by a command line argument, for example)
87 and need to instantiate the correct object.
88 """
89 super = returnClassForVersion(version)
90 return super()