generic-poky/scripts/lib/mic/3rdparty/pykickstart/version.py

198 lines
6.4 KiB
Python
Raw Normal View History

wic: Add mic w/pykickstart This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen <gui.chen@intel.com> Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-08-24 15:31:34 +00:00
#
# Chris Lumens <clumens@redhat.com>
#
# Copyright 2006, 2007, 2008, 2009, 2010 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use, modify,
# copy, or redistribute it subject to the terms and conditions of the GNU
# General Public License v.2. This program is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
# trademarks that are incorporated in the source code or documentation are not
# subject to the GNU General Public License and may only be used or replicated
# with the express permission of Red Hat, Inc.
#
"""
Methods for working with kickstart versions.
This module defines several symbolic constants that specify kickstart syntax
versions. Each version corresponds roughly to one release of Red Hat Linux,
Red Hat Enterprise Linux, or Fedora Core as these are where most syntax
changes take place.
This module also exports several functions:
makeVersion - Given a version number, return an instance of the
matching handler class.
returnClassForVersion - Given a version number, return the matching
handler class. This does not return an
instance of that class, however.
stringToVersion - Convert a string representation of a version number
into the symbolic constant.
versionToString - Perform the reverse mapping.
versionFromFile - Read a kickstart file and determine the version of
syntax it uses. This requires the kickstart file to
have a version= comment in it.
"""
import imputil, re, sys
from urlgrabber import urlopen
import gettext
_ = lambda x: gettext.ldgettext("pykickstart", x)
from pykickstart.errors import KickstartVersionError
# Symbolic names for internal version numbers.
RHEL3 = 900
FC3 = 1000
RHEL4 = 1100
FC4 = 2000
FC5 = 3000
FC6 = 4000
RHEL5 = 4100
F7 = 5000
F8 = 6000
F9 = 7000
F10 = 8000
F11 = 9000
F12 = 10000
F13 = 11000
RHEL6 = 11100
F14 = 12000
F15 = 13000
F16 = 14000
# This always points at the latest version and is the default.
DEVEL = F16
# A one-to-one mapping from string representations to version numbers.
versionMap = {
"DEVEL": DEVEL,
"FC3": FC3, "FC4": FC4, "FC5": FC5, "FC6": FC6, "F7": F7, "F8": F8,
"F9": F9, "F10": F10, "F11": F11, "F12": F12, "F13": F13,
"F14": F14, "F15": F15, "F16": F16,
"RHEL3": RHEL3, "RHEL4": RHEL4, "RHEL5": RHEL5, "RHEL6": RHEL6
}
def stringToVersion(s):
"""Convert string into one of the provided version constants. Raises
KickstartVersionError if string does not match anything.
"""
# First try these short forms.
try:
return versionMap[s.upper()]
except KeyError:
pass
# Now try the Fedora versions.
m = re.match("^fedora.* (\d+)$", s, re.I)
if m and m.group(1):
if versionMap.has_key("FC" + m.group(1)):
return versionMap["FC" + m.group(1)]
elif versionMap.has_key("F" + m.group(1)):
return versionMap["F" + m.group(1)]
else:
raise KickstartVersionError(_("Unsupported version specified: %s") % s)
# Now try the RHEL versions.
m = re.match("^red hat enterprise linux.* (\d+)([\.\d]*)$", s, re.I)
if m and m.group(1):
if versionMap.has_key("RHEL" + m.group(1)):
return versionMap["RHEL" + m.group(1)]
else:
raise KickstartVersionError(_("Unsupported version specified: %s") % s)
# If nothing else worked, we're out of options.
raise KickstartVersionError(_("Unsupported version specified: %s") % s)
def versionToString(version, skipDevel=False):
"""Convert version into a string representation of the version number.
This is the reverse operation of stringToVersion. Raises
KickstartVersionError if version does not match anything.
"""
if not skipDevel and version == versionMap["DEVEL"]:
return "DEVEL"
for (key, val) in versionMap.iteritems():
if key == "DEVEL":
continue
elif val == version:
return key
raise KickstartVersionError(_("Unsupported version specified: %s") % version)
def versionFromFile(f):
"""Given a file or URL, look for a line starting with #version= and
return the version number. If no version is found, return DEVEL.
"""
v = DEVEL
fh = urlopen(f)
while True:
try:
l = fh.readline()
except StopIteration:
break
# At the end of the file?
if l == "":
break
if l.isspace() or l.strip() == "":
continue
if l[:9] == "#version=":
v = stringToVersion(l[9:].rstrip())
break
fh.close()
return v
def returnClassForVersion(version=DEVEL):
"""Return the class of the syntax handler for version. version can be
either a string or the matching constant. Raises KickstartValueError
if version does not match anything.
"""
try:
version = int(version)
module = "%s" % versionToString(version, skipDevel=True)
except ValueError:
module = "%s" % version
version = stringToVersion(version)
module = module.lower()
try:
import pykickstart.handlers
sys.path.extend(pykickstart.handlers.__path__)
found = imputil.imp.find_module(module)
loaded = imputil.imp.load_module(module, found[0], found[1], found[2])
for (k, v) in loaded.__dict__.iteritems():
if k.lower().endswith("%shandler" % module):
return v
except:
raise KickstartVersionError(_("Unsupported version specified: %s") % version)
def makeVersion(version=DEVEL):
"""Return a new instance of the syntax handler for version. version can be
either a string or the matching constant. This function is useful for
standalone programs which just need to handle a specific version of
kickstart syntax (as provided by a command line argument, for example)
and need to instantiate the correct object.
"""
cl = returnClassForVersion(version)
return cl()