2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2006, 2007 Red Hat, Inc.
6 # This copyrighted material is made available to anyone wishing to use, modify,
7 # copy, or redistribute it subject to the terms and conditions of the GNU
8 # General Public License v.2. This program is distributed in the hope that it
9 # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
10 # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # this program; if not, write to the Free Software Foundation, Inc., 51
15 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
16 # trademarks that are incorporated in the source code or documentation are not
17 # subject to the GNU General Public License and may only be used or replicated
18 # with the express permission of Red Hat, Inc.
21 Methods for working with kickstart versions.
23 This module defines several symbolic constants that specify kickstart syntax
24 versions. Each version corresponds roughly to one release of Red Hat Linux,
25 Red Hat Enterprise Linux, or Fedora Core as these are where most syntax
28 This module also exports several functions:
30 makeVersion - Given a version number, return an instance of the
31 matching handler class.
33 returnClassForVersion - Given a version number, return the matching
34 handler class. This does not return an
35 instance of that class, however.
37 stringToVersion - Convert a string representation of a version number
38 into the symbolic constant.
40 versionToString - Perform the reverse mapping.
44 from rhpl
.translate
import _
45 from pykickstart
.errors
import KickstartVersionError
47 # Symbolic names for internal version numbers.
59 # This always points at the latest version and is the default.
62 """A one-to-one mapping from string representations to version numbers."""
65 "FC3": FC3
, "FC4": FC4
, "FC5": FC5
, "FC6": FC6
, "F7": F7
, "F8": F8
,
67 "RHEL3": RHEL3
, "RHEL4": RHEL4
, "RHEL5": RHEL5
70 def stringToVersion(s
):
71 """Convert string into one of the provided version constants. Raises
72 KickstartVersionError if string does not match anything.
74 # First try these short forms.
76 return versionMap
[s
.upper()]
80 # Now try the Fedora versions.
81 m
= re
.match("^fedora.* (\d)+$", s
, re
.I
)
84 if versionMap
.has_key("FC" + m
.group(1)):
85 return versionMap
["FC" + m
.group(1)]
86 elif versionMap
.has_key("F" + m
.group(1)):
87 return versionMap
["F" + m
.group(1)]
89 raise KickstartVersionError(_("Unsupported version specified: %s") % s
)
91 # Now try the RHEL versions.
92 m
= re
.match("^red hat enterprise linux.* (\d)+$", s
, re
.I
)
95 if versionMap
.has_key("RHEL" + m
.group(1)):
96 return versionMap
["RHEL" + m
.group(1)]
98 raise KickstartVersionError(_("Unsupported version specified: %s") % s
)
100 # If nothing else worked, we're out of options.
101 raise KickstartVersionError(_("Unsupported version specified: %s") % s
)
103 def versionToString(version
):
104 """Convert version into a string representation of the version number.
105 This is the reverse operation of stringToVersion. Raises
106 KickstartVersionError if version does not match anything.
108 for (key
, val
) in versionMap
.iteritems():
112 raise KickstartVersionError(_("Unsupported version specified: %s") % version
)
114 def returnClassForVersion(version
=DEVEL
):
115 """Return the class of the syntax handler for version. version can be
116 either a string or the matching constant. Raises KickstartValueError
117 if version does not match anything.
120 version
= int(version
)
122 version
= stringToVersion(version
)
125 from pykickstart
.handlers
.fc3
import FC3Handler
128 from pykickstart
.handlers
.fc4
import FC4Handler
131 from pykickstart
.handlers
.fc5
import FC5Handler
134 from pykickstart
.handlers
.fc6
import FC6Handler
137 from pykickstart
.handlers
.f7
import F7Handler
140 from pykickstart
.handlers
.f8
import F8Handler
143 from pykickstart
.handlers
.f9
import F9Handler
145 elif version
== RHEL3
:
146 from pykickstart
.handlers
.rhel3
import RHEL3Handler
148 elif version
== RHEL4
:
149 from pykickstart
.handlers
.rhel4
import RHEL4Handler
151 elif version
== RHEL5
:
152 from pykickstart
.handlers
.rhel5
import RHEL5Handler
155 raise KickstartVersionError(_("Unsupported version specified: %s") % version
)
157 def makeVersion(version
=DEVEL
):
158 """Return a new instance of the syntax handler for version. version can be
159 either a string or the matching constant. This function is useful for
160 standalone programs which just need to handle a specific version of
161 kickstart syntax (as provided by a command line argument, for example)
162 and need to instantiate the correct object.
164 cl
= returnClassForVersion(version
)