Add support for F8. Move DEVEL version along to the latest.
[pykickstart.git] / pykickstart / version.py
bloba9b229246055ce951cced602e4f834ab5a7c5866
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2006, 2007 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 makeVersion - Given a version number, return an instance of the
24 matching handler class.
26 returnClassForVersion - Given a version number, return the matching
27 handler class. This does not return an
28 instance of that class, however.
30 stringToVersion - Convert a string representation of a version number
31 into the symbolic constant.
33 versionToString - Perform the reverse mapping.
34 """
35 import re
37 from rhpl.translate import _
38 from pykickstart.errors import KickstartVersionError
40 # Symbolic names for internal version numbers.
41 RHEL3 = 900
42 FC3 = 1000
43 RHEL4 = 1100
44 FC4 = 2000
45 FC5 = 3000
46 FC6 = 4000
47 RHEL5 = 4100
48 F7 = 5000
49 F8 = 6000
51 # This always points at the latest version and is the default.
52 DEVEL = F8
54 """A one-to-one mapping from string representations to version numbers."""
55 versionMap = {
56 "DEVEL": DEVEL,
57 "FC3": FC3, "FC4": FC4, "FC5": FC5, "FC6": FC6, "F7": F7, "F8": F8,
58 "RHEL3": RHEL3, "RHEL4": RHEL4, "RHEL5": RHEL5
61 def stringToVersion(string):
62 """Convert string into one of the provided version constants. Raises
63 KickstartVersionError if string does not match anything.
64 """
65 # First try these short forms.
66 try:
67 return versionMap[string.upper()]
68 except KeyError:
69 pass
71 # Now try the Fedora versions.
72 m = re.match("^fedora.* (\d)+$", string, re.I)
74 if m and m.group(1):
75 if versionMap.has_key("FC" + m.group(1)):
76 return versionMap["FC" + m.group(1)]
77 elif versionMap.has_key("F" + m.group(1)):
78 return versionMap["F" + m.group(1)]
79 else:
80 raise KickstartVersionError(_("Unsupported version specified: %s") % string)
82 # Now try the RHEL versions.
83 m = re.match("^red hat enterprise linux.* (\d)+$", string, re.I)
85 if m and m.group(1):
86 if versionMap.has_key("RHEL" + m.group(1)):
87 return versionMap["RHEL" + m.group(1)]
88 else:
89 raise KickstartVersionError(_("Unsupported version specified: %s") % string)
91 # If nothing else worked, we're out of options.
92 raise KickstartVersionError(_("Unsupported version specified: %s") % string)
94 def versionToString(version):
95 """Convert version into a string representation of the version number.
96 This is the reverse operation of stringToVersion. Raises
97 KickstartVersionError if version does not match anything.
98 """
99 for (key, val) in versionMap.iteritems():
100 if val == version:
101 return key
103 raise KickstartVersionError(_("Unsupported version specified: %s") % version)
105 def returnClassForVersion(version=DEVEL):
106 """Return the class of the syntax handler for version. version can be
107 either a string or the matching constant. Raises KickstartValueError
108 if version does not match anything.
110 try:
111 version = int(version)
112 except ValueError:
113 version = stringToVersion(version)
115 if version == FC3:
116 from pykickstart.handlers.fc3 import FC3Handler
117 return FC3Handler
118 elif version == FC4:
119 from pykickstart.handlers.fc4 import FC4Handler
120 return FC4Handler
121 elif version == FC5:
122 from pykickstart.handlers.fc5 import FC5Handler
123 return FC5Handler
124 elif version == FC6:
125 from pykickstart.handlers.fc6 import FC6Handler
126 return FC6Handler
127 elif version == F7:
128 from pykickstart.handlers.f7 import F7Handler
129 return F7Handler
130 elif version == F8:
131 from pykickstart.handlers.f8 import F8Handler
132 return F8Handler
133 elif version == RHEL3:
134 from pykickstart.handlers.rhel3 import RHEL3Handler
135 return RHEL3Handler
136 elif version == RHEL4:
137 from pykickstart.handlers.rhel4 import RHEL4Handler
138 return RHEL4Handler
139 elif version == RHEL5:
140 from pykickstart.handlers.rhel5 import RHEL5Handler
141 return RHEL5Handler
142 else:
143 raise KickstartVersionError(_("Unsupported version specified: %s") % version)
145 def makeVersion(version=DEVEL):
146 """Return a new instance of the syntax handler for version. version can be
147 either a string or the matching constant. This function is useful for
148 standalone programs which just need to handle a specific version of
149 kickstart syntax (as provided by a command line argument, for example)
150 and need to instantiate the correct object.
152 cl = returnClassForVersion(version)
153 return cl()