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.
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
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.
37 from rhpl
.translate
import _
38 from pykickstart
.errors
import KickstartVersionError
40 # Symbolic names for internal version numbers.
51 # This always points at the latest version and is the default.
54 """A one-to-one mapping from string representations to version numbers."""
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.
65 # First try these short forms.
67 return versionMap
[string
.upper()]
71 # Now try the Fedora versions.
72 m
= re
.match("^fedora.* (\d)+$", string
, re
.I
)
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)]
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
)
86 if versionMap
.has_key("RHEL" + m
.group(1)):
87 return versionMap
["RHEL" + m
.group(1)]
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.
99 for (key
, val
) in versionMap
.iteritems():
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.
111 version
= int(version
)
113 version
= stringToVersion(version
)
116 from pykickstart
.handlers
.fc3
import FC3Handler
119 from pykickstart
.handlers
.fc4
import FC4Handler
122 from pykickstart
.handlers
.fc5
import FC5Handler
125 from pykickstart
.handlers
.fc6
import FC6Handler
128 from pykickstart
.handlers
.f7
import F7Handler
131 from pykickstart
.handlers
.f8
import F8Handler
133 elif version
== RHEL3
:
134 from pykickstart
.handlers
.rhel3
import RHEL3Handler
136 elif version
== RHEL4
:
137 from pykickstart
.handlers
.rhel4
import RHEL4Handler
139 elif version
== RHEL5
:
140 from pykickstart
.handlers
.rhel5
import RHEL5Handler
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
)