[blivet][PATCH 3/3] Get rid of the code related to finding existing installations
Vratislav Podzimek
vpodzime at redhat.com
Fri Jan 23 14:18:18 UTC 2015
This has basically nothing to do with Blivet's area of interest.
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
blivet/__init__.py | 207 -----------------------------------------------------
1 file changed, 207 deletions(-)
diff --git a/blivet/__init__.py b/blivet/__init__.py
index fff7fb5..8f07a7e 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -478,11 +478,6 @@ class Blivet(object):
self.roots = []
if flags.installer_mode:
- try:
- self.roots = findExistingInstallations(self.devicetree)
- except Exception: # pylint: disable=broad-except
- log_exception_info(log.info, "failure detecting existing installations")
-
self.dumpState("initial")
if not flags.installer_mode:
@@ -2839,151 +2834,6 @@ class FSSet(object):
self._fstab_swaps = set(devices)
-def releaseFromRedhatRelease(fn):
- """
- Attempt to identify the installation of a Linux distribution via
- /etc/redhat-release. This file must already have been verified to exist
- and be readable.
-
- :param fn: an open filehandle on /etc/redhat-release
- :type fn: filehandle
- :returns: The distribution's name and version, or None for either or both
- if they cannot be determined
- :rtype: (string, string)
- """
- relName = None
- relVer = None
-
- with open(fn) as f:
- try:
- relstr = f.readline().strip()
- except (IOError, AttributeError):
- relstr = ""
-
- # get the release name and version
- # assumes that form is something
- # like "Red Hat Linux release 6.2 (Zoot)"
- (product, sep, version) = relstr.partition(" release ")
- if sep:
- relName = product
- relVer = version.split()[0]
-
- return (relName, relVer)
-
-def releaseFromOsRelease(fn):
- """
- Attempt to identify the installation of a Linux distribution via
- /etc/os-release. This file must already have been verified to exist
- and be readable.
-
- :param fn: an open filehandle on /etc/os-release
- :type fn: filehandle
- :returns: The distribution's name and version, or None for either or both
- if they cannot be determined
- :rtype: (string, string)
- """
- relName = None
- relVer = None
-
- with open(fn, "r") as f:
- parser = shlex.shlex(f)
-
- while True:
- key = parser.get_token()
- if key == parser.eof:
- break
- elif key == "NAME":
- # Throw away the "=".
- parser.get_token()
- relName = parser.get_token().strip("'\"")
- elif key == "VERSION_ID":
- # Throw away the "=".
- parser.get_token()
- relVer = parser.get_token().strip("'\"")
-
- return (relName, relVer)
-
-def getReleaseString():
- """
- Attempt to identify the installation of a Linux distribution by checking
- a previously mounted filesystem for several files. The filesystem must
- be mounted under the target physical root.
-
- :returns: The machine's arch, distribution name, and distribution version
- or None for any parts that cannot be determined
- :rtype: (string, string, string)
- """
- relName = None
- relVer = None
-
- try:
- relArch = util.capture_output(["arch"], root=_sysroot).strip()
- except OSError:
- relArch = None
-
- filename = "%s/etc/redhat-release" % getSysroot()
- if os.access(filename, os.R_OK):
- (relName, relVer) = releaseFromRedhatRelease(filename)
- else:
- filename = "%s/etc/os-release" % getSysroot()
- if os.access(filename, os.R_OK):
- (relName, relVer) = releaseFromOsRelease(filename)
-
- return (relArch, relName, relVer)
-
-def findExistingInstallations(devicetree):
- if not os.path.exists(getTargetPhysicalRoot()):
- util.makedirs(getTargetPhysicalRoot())
-
- roots = []
- for device in devicetree.leaves:
- if not device.format.linuxNative or not device.format.mountable or \
- not device.controllable:
- continue
-
- try:
- device.setup()
- except Exception: # pylint: disable=broad-except
- log_exception_info(log.warning, "setup of %s failed", [device.name])
- continue
-
- options = device.format.options + ",ro"
- try:
- device.format.mount(options=options, mountpoint=getSysroot())
- except Exception: # pylint: disable=broad-except
- log_exception_info(log.warning, "mount of %s as %s failed", [device.name, device.format.type])
- device.teardown()
- continue
-
- if not os.access(getSysroot() + "/etc/fstab", os.R_OK):
- device.teardown(recursive=True)
- continue
-
- try:
- (architecture, product, version) = getReleaseString()
- except ValueError:
- name = _("Linux on %s") % device.name
- else:
- # I'd like to make this finer grained, but it'd be very difficult
- # to translate.
- if not product or not version or not architecture:
- name = _("Unknown Linux")
- elif "linux" in product.lower():
- name = _("%(product)s %(version)s for %(arch)s") % \
- {"product": product, "version": version, "arch": architecture}
- else:
- name = _("%(product)s Linux %(version)s for %(arch)s") % \
- {"product": product, "version": version, "arch": architecture}
-
- (mounts, swaps) = parseFSTab(devicetree, chroot=_sysroot)
- device.teardown()
- if not mounts and not swaps:
- # empty /etc/fstab. weird, but I've seen it happen.
- continue
- roots.append(Root(mounts=mounts, swaps=swaps, name=name))
-
- return roots
-
class Root(object):
""" A Root represents an existing OS installation. """
def __init__(self, mounts=None, swaps=None, name=None):
@@ -3015,60 +2865,3 @@ class Root(object):
@property
def device(self):
return self.mounts.get("/")
-
-def parseFSTab(devicetree, chroot=None):
- """ parse /etc/fstab and return a tuple of a mount dict and swap list """
- if not chroot or not os.path.isdir(chroot):
- chroot = _sysroot
-
- mounts = {}
- swaps = []
- path = "%s/etc/fstab" % chroot
- if not os.access(path, os.R_OK):
- # XXX should we raise an exception instead?
- log.info("cannot open %s for read", path)
- return (mounts, swaps)
-
- blkidTab = BlkidTab(chroot=chroot)
- try:
- blkidTab.parse()
- log.debug("blkid.tab devs: %s", list(blkidTab.devices.keys()))
- except Exception: # pylint: disable=broad-except
- log_exception_info(log.info, "error parsing blkid.tab")
- blkidTab = None
-
- cryptTab = CryptTab(devicetree, blkidTab=blkidTab, chroot=chroot)
- try:
- cryptTab.parse(chroot=chroot)
- log.debug("crypttab maps: %s", list(cryptTab.mappings.keys()))
- except Exception: # pylint: disable=broad-except
- log_exception_info(log.info, "error parsing crypttab")
- cryptTab = None
-
- with open(path) as f:
- log.debug("parsing %s", path)
- for line in f.readlines():
-
- (line, _pound, _comment) = line.partition("#")
- fields = line.split(None, 4)
-
- if len(fields) < 5:
- continue
-
- (devspec, mountpoint, fstype, options, _rest) = fields
-
- # find device in the tree
- device = devicetree.resolveDevice(devspec,
- cryptTab=cryptTab,
- blkidTab=blkidTab,
- options=options)
-
- if device is None:
- continue
-
- if fstype != "swap":
- mounts[mountpoint] = device
- else:
- swaps.append(device)
-
- return (mounts, swaps)
--
2.1.0
More information about the anaconda-patches
mailing list