[PATCH] Stop using /usr/bin/env (#987028)
by Brian C. Lane
From: "Brian C. Lane" <bcl(a)redhat.com>
---
Makefile | 2 +-
setup.py | 2 +-
src/sbin/livemedia-creator | 2 +-
src/sbin/lorax | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index 1015e4b..2bb8902 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-PYTHON ?= /usr/bin/env python
+PYTHON ?= /usr/bin/python
DESTDIR ?= /
PKGNAME = lorax
diff --git a/setup.py b/setup.py
index c4141f1..4d5b543 100644
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#!/usr/bin/python
from distutils.core import setup
from glob import glob
diff --git a/src/sbin/livemedia-creator b/src/sbin/livemedia-creator
index f6947b9..da0ac8f 100755
--- a/src/sbin/livemedia-creator
+++ b/src/sbin/livemedia-creator
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
#
# Live Media Creator
#
diff --git a/src/sbin/lorax b/src/sbin/lorax
index 2337f95..a571c0b 100755
--- a/src/sbin/lorax
+++ b/src/sbin/lorax
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#!/usr/bin/python
#
# lorax
--
1.8.3.1
10 years, 9 months
[master/rhel7] Fix driver disk path for inst.dd= method (#987513)
by Brian C. Lane
From: "Brian C. Lane" <bcl(a)redhat.com>
When inst.dd=<device> was passed it was looking for arch next to rhdd3
instead of under /rpms/
Resolves: rhbz#987513
---
dracut/driver-updates | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/dracut/driver-updates b/dracut/driver-updates
index 00c97ef..1800087 100755
--- a/dracut/driver-updates
+++ b/dracut/driver-updates
@@ -232,8 +232,9 @@ def find_dd(mnt="/media/DD"):
dd_repos = []
arch = os.uname()[4]
for root, dirs, files in os.walk(mnt, followlinks=True):
- if "rhdd3" in files and arch in dirs:
- dd_repos.append(root+"/"+arch)
+ if "rhdd3" in files and "rpms" in dirs and \
+ os.path.exists(root+"/rpms/"+arch):
+ dd_repos.append(root+"/rpms/"+arch)
log.debug("Found repos - %s" % " ".join(dd_repos))
return dd_repos
--
1.8.3.1
10 years, 9 months
[PATCH] Verify user ready to proceed with installation in TUI. (#975793)
by Samantha N. Bueno
Another for rhel7-branch as well.
I feel like a better-worded message could be shown to users, so please
feel free to offer suggestions.
====
Show a message and prompt user with yes/no dialog to verify they
are ready to proceed before beginning installation.
This also alters the YesNoDialog so that it doesn't always center text.
Resolves: rhbz#975793
---
pyanaconda/ui/tui/hubs/__init__.py | 8 +++++++-
pyanaconda/ui/tui/tuiobject.py | 3 ++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/pyanaconda/ui/tui/hubs/__init__.py b/pyanaconda/ui/tui/hubs/__init__.py
index 14e6957..e05020e 100644
--- a/pyanaconda/ui/tui/hubs/__init__.py
+++ b/pyanaconda/ui/tui/hubs/__init__.py
@@ -19,7 +19,7 @@
# Red Hat Author(s): Martin Sivak <msivak(a)redhat.com>
#
from .. import simpleline as tui
-from pyanaconda.ui.tui.tuiobject import TUIObject
+from pyanaconda.ui.tui.tuiobject import TUIObject, YesNoDialog
from pyanaconda.ui.tui.spokes import collect_spokes
from pyanaconda.ui import common
@@ -110,4 +110,10 @@ class TUIHub(TUIObject, common.Hub):
if not spoke.completed and spoke.mandatory:
print(_("Please complete all spokes before continuing"))
return False
+ else:
+ msg = _("Proceeding will begin installation.\nReady to continue?")
+ question = YesNoDialog(self._app, msg)
+ self._app.switch_screen_modal(question)
+ if not question.answer:
+ return None
return key
diff --git a/pyanaconda/ui/tui/tuiobject.py b/pyanaconda/ui/tui/tuiobject.py
index e2c96f7..f68887f 100644
--- a/pyanaconda/ui/tui/tuiobject.py
+++ b/pyanaconda/ui/tui/tuiobject.py
@@ -73,7 +73,8 @@ class YesNoDialog(tui.UIScreen):
def refresh(self, args = None):
tui.UIScreen.refresh(self, args)
text = tui.TextWidget(self._message)
- self._window.append(tui.CenterWidget(text))
+# self._window.append(tui.CenterWidget(text))
+ self._window.append(text)
self._window.append(u"")
return True
--
1.8.3.1
10 years, 9 months
[PATCH] Add support for NFS as install source in TUI. (#971298)
by Samantha N. Bueno
Note: should go into rhel7-branch also.
Resolves: rhbz#971298
---
pyanaconda/ui/tui/spokes/source.py | 68 ++++++++++++++++++++++++++++++++++----
1 file changed, 62 insertions(+), 6 deletions(-)
diff --git a/pyanaconda/ui/tui/spokes/source.py b/pyanaconda/ui/tui/spokes/source.py
index cd5f718..3714364 100644
--- a/pyanaconda/ui/tui/spokes/source.py
+++ b/pyanaconda/ui/tui/spokes/source.py
@@ -32,6 +32,7 @@ from pyanaconda.constants import THREAD_SOURCE_WATCHER, THREAD_SOFTWARE_WATCHER,
from pyanaconda.constants import THREAD_PAYLOAD_MD, THREAD_STORAGE, THREAD_CHECK_SOFTWARE
import re
+from .... import time
import logging
LOG = logging.getLogger("anaconda")
@@ -44,7 +45,7 @@ class SourceSpoke(EditTUISpoke):
title = _("Installation source")
category = "source"
- _protocols = (_("Closest mirror"), "http://", "https://", "ftp://")
+ _protocols = (_("Closest mirror"), "http://", "https://", "ftp://", "nfs")
# default to 'closest mirror', as done in the GUI
_selection = 1
@@ -80,6 +81,8 @@ class SourceSpoke(EditTUISpoke):
""" Return a string describing repo url or lack of one. """
if self.data.method.method == "url":
return self.data.method.url or self.data.method.mirrorlist
+ elif self.data.method.method == "nfs":
+ return _("NFS server %s") % self.data.method.server
elif self.data.method.method == "cdrom":
return _("CD/DVD drive")
elif self.payload.baseRepo:
@@ -125,6 +128,7 @@ class SourceSpoke(EditTUISpoke):
text = [TextWidget(m) for m in _methods]
def _prep(i, w):
+ """ Mangle our text to make it look pretty on screen. """
number = TextWidget("%2d)" % (i + 1))
return ColumnWidget([(4, [number]), (None, [w])], 1)
@@ -142,9 +146,6 @@ class SourceSpoke(EditTUISpoke):
num = int(key)
if args == 2:
# network install
- ## FIXME: setting self._selection reeks a bit of redundancy
- ## now that some of this has been rewritten, so it should be
- ## done away with entirely in the future, at some point
self._selection = num
if self._selection == 1:
# closest mirror
@@ -160,6 +161,15 @@ class SourceSpoke(EditTUISpoke):
self.apply()
self.close()
return True
+ elif self._selection == 5:
+ # nfs
+ self.data.method.method = "nfs"
+ newspoke = SpecifyNFSRepoSpoke(self.app, self.data, self.storage,
+ self.payload, self.instclass, self._selection, self.errors)
+ self.app.switch_screen_modal(newspoke)
+ self.apply()
+ self.close()
+ return True
else:
if num == 1:
# iso selected, just set some vars and return to main hub
@@ -176,10 +186,14 @@ class SourceSpoke(EditTUISpoke):
def getRepoMetadata(self):
""" Pull down yum repo metadata """
+ # unfortunately, this sleep is needed in order to prevent a tb
+ # anaconda needs to try and mount our nfs dir (if we're using nfs)
+ # before kicking off all of the yum crap
+ time.sleep(1)
try:
self.payload.updateBaseRepo(fallback=False, checkmount=False)
- except PayloadError as err:
- LOG.error("PayloadError: %s" % (err,))
+ except (OSError, PayloadError) as err:
+ LOG.error("Error: %s" % (err,))
self.errors.append(_("Failed to set up installation source"))
else:
self.payload.gatherRepoMetadata()
@@ -240,3 +254,45 @@ class SpecifyRepoSpoke(EditTUISpoke):
# protocol either unknown or entry already starts with a protocol
# specification
self.data.method.url = self.args.url
+
+class SpecifyNFSRepoSpoke(EditTUISpoke):
+ """ Specify the repo URL here if closest mirror not selected. """
+ title = _("Specify Repo Options")
+ category = "source"
+
+ edit_fields = [
+ Entry(_("Repo url"), "url", re.compile(".*$"), True),
+ Entry(_("NFS mount options"), "opts", re.compile(".*$"), True)
+ ]
+
+ def __init__(self, app, data, storage, payload, instclass, selection, errors):
+ EditTUISpoke.__init__(self, app, data, storage, payload, instclass)
+ self.selection = selection
+ self.args = self.data.method
+ self.errors = errors
+
+
+ def refresh(self, args=None):
+ """ Refresh window. """
+ return EditTUISpoke.refresh(self, args)
+
+ @property
+ def indirect(self):
+ return True
+
+ def apply(self):
+ """ Apply our changes. """
+ if self.args.url == "" or not ':' in self.args.url:
+ return False
+
+ if self.args.url.startswith("nfs://"):
+ self.args.url = self.args.url.strip("nfs://")
+
+ try:
+ (self.data.method.server, self.data.method.dir) = self.args.url.split(":", 2)
+ except ValueError as err:
+ LOG.error("ValueError: %s" % (err,))
+ self.errors.append("Failed to set up installation source")
+ return
+
+ self.data.method.opts = self.args.opts or ""
--
1.7.11.7
10 years, 9 months
[rhel6-branch][PATCH] Enable the AMD IOMMU driver if tboot is installed. (#928144)
by David Shea
If tboot is installed, enable the AMD iommu driver in the kernel
parameters in the same way that we enable the Intel iommu driver.
The AMD iommu driver is disabled by default in RHEL 6 due to stability
issues with some BIOSes after suspend and resume. This kernel parameter
has no effect on systems without AMD-Vi.
---
booty/x86.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/booty/x86.py b/booty/x86.py
index f2e0047..a753201 100644
--- a/booty/x86.py
+++ b/booty/x86.py
@@ -367,7 +367,7 @@ class x86BootloaderInfo(efiBootloaderInfo):
else: # normal kernel
if self.trusted_boot:
f.write('\tkernel %stboot.gz logging=vga,serial,memory\n' % (cfPath))
- f.write('\tmodule %s ro%s intel_iommu=on' % (kernelFile, realroot))
+ f.write('\tmodule %s ro%s intel_iommu=on amd_iommu=on' % (kernelFile, realroot))
if self.args.get():
f.write(' %s' % self.args.get())
f.write('\n')
--
1.8.3.1
10 years, 9 months
[PATCH] Fix crash while parsing ntp servers from DHCP6 (#969303)
by David Shea
This removes anaconda's attempt to collect NTP servers through
NetworkManager's DHCP6 options. The reasons for this are as follows:
- NetworkManager does not currently request NTP or SNTP options. When
using a DHCP6 that honors OPTION_ORO (e.g., ISC dhcpd6), no time
servers will be returned
- dhclient does not support the NTP server option (dhcp6 option 56,
RFC 5908). If a server does return an OPTION_NTP_SERVER block, it
will not be parsed and NetworkManager will only be aware of the
presence of an unknown option 56.
It is possible to use the OPTION_SNTP_SERVER data, which is formated in
the same way the IPv4 DHCP NTP server option data. To use this we would
need to create /etc/NetworkManager/dhclient6.conf containing "also
request dhcp6.sntp-servers" and fix the option parsing code in nm.py to
pull the right value out of the Dhcp6Config.Options dictionary. However,
it's probably not worth it, since obviously no one was using DHCP6
options at all, because it would have crashed.
---
pyanaconda/nm.py | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/pyanaconda/nm.py b/pyanaconda/nm.py
index 0932a2e..56c59d4 100644
--- a/pyanaconda/nm.py
+++ b/pyanaconda/nm.py
@@ -284,15 +284,7 @@ def nm_ntp_servers_from_dhcp():
for ip in ntp_servers_string.split(" "):
ntp_servers.append(ip)
- # harvest NTP servers from DHCPv6
- dhcp6_path = nm_device_property(device, "Dhcp6Config")
- dhcp6_proxy = _get_proxy(object_path=dhcp6_path,
- interface_name="org.freedesktop.NetworkManager.DHCP6Config")
- options = dhcp6_proxy.get_cached_property("Options")
- if options is not None:
- # NTP server addresses returned by DHCP are whitespace delimited
- for ip in options.unpack().split(" "):
- ntp_servers.append(ip)
+ # NetworkManager does not request NTP/SNTP options for DHCP6
return ntp_servers
def _device_settings(name):
--
1.8.3.1
10 years, 9 months
[rhel6-branch][PATCH] Limit the maximum swap size to 10 % of disk space
by Vratislav Podzimek
On e.g. virtual machines with smalls disks and high amount of
memory it doesn't make sense to create large swap space leaving
only a little for the system and user data.
Also change a comment to a docstring and document parameters.
Resolves: rhbz#878907
Related: rhbz#879232
Signed-off-by: Vratislav Podzimek <vpodzime(a)redhat.com>
---
iutil.py | 28 ++++++++++++++++++++++++----
kickstart.py | 18 ++++++++++++++++--
storage/partitioning.py | 14 ++++++++++++++
3 files changed, 54 insertions(+), 6 deletions(-)
diff --git a/iutil.py b/iutil.py
index 4553816..eaf2136 100644
--- a/iutil.py
+++ b/iutil.py
@@ -40,6 +40,9 @@ import logging
log = logging.getLogger("anaconda")
program_log = logging.getLogger("program")
+# maximum ratio of swap size to disk size (10 %)
+MAX_SWAP_DISK_RATIO = 0.1
+
#Python reimplementation of the shell tee process, so we can
#feed the pipe output into two places at the same time
class tee(threading.Thread):
@@ -450,10 +453,17 @@ def memInstalled():
return long(mem)
-## Suggest the size of the swap partition that will be created.
-# @param quiet Should size information be logged?
-# @return A tuple of the minimum and maximum swap size, in megabytes.
-def swapSuggestion(quiet=0, hibernation=False):
+def swapSuggestion(quiet=0, hibernation=False, disk_space=None):
+ """
+ Suggest the size of the swap partition that will be created.
+
+ @param quiet: Should size information be logged?
+ @param hibernation: Suggest size of the swap partition to support hibernation?
+ @param disk_space: Total disk space available
+ @return: A tuple of the minimum and maximum swap size, in megabytes.
+
+ """
+
mem = memInstalled()/1024
mem = ((mem/16)+1)*16
if not quiet:
@@ -479,6 +489,16 @@ def swapSuggestion(quiet=0, hibernation=False):
else:
log.info("Ignoring --hibernation option on systems with 64 GB of RAM or more")
+ if disk_space is not None:
+ max_swap = int(disk_space * MAX_SWAP_DISK_RATIO)
+ if swap > max_swap:
+ log.info("Suggested swap size (%(swap)d M) exceeds %(percent)d %% of "
+ "disk space, using %(percent)d %% of disk space (%(size)d M) "
+ "instead." % {"percent": MAX_SWAP_DISK_RATIO*100,
+ "swap": swap,
+ "size": max_swap})
+ swap = max_swap
+
if not quiet:
log.info("Swap attempt of %sM", swap)
diff --git a/kickstart.py b/kickstart.py
index e4b960a..0ee6621 100644
--- a/kickstart.py
+++ b/kickstart.py
@@ -481,11 +481,18 @@ class LogVolData(commands.logvol.RHEL6_LogVolData):
# we might have truncated or otherwise changed the specified vg name
vgname = anaconda.id.ksdata.onPart.get(self.vgname, self.vgname)
+ disk_space = 0
+ for disk in storage.disks:
+ if not storage.clearPartDisks \
+ or disk.name in storage.clearPartDisks:
+ disk_space += disk.size
+
if self.mountpoint == "swap":
type = "swap"
self.mountpoint = ""
if self.recommended or self.hibernation:
- (self.size, self.maxSizeMB) = iutil.swapSuggestion(hibernation=self.hibernation)
+ (self.size, self.maxSizeMB) = \
+ iutil.swapSuggestion(hibernation=self.hibernation, disk_space=disk_space)
self.grow = True
else:
if self.fstype != "":
@@ -752,11 +759,18 @@ class PartitionData(commands.partition.RHEL6_PartData):
if self.disk == "":
raise KickstartValueError, formatErrorMsg(self.lineno, msg="Specified BIOS disk %s cannot be determined" % self.onbiosdisk)
+ disk_space = 0
+ for disk in storage.disks:
+ if not storage.clearPartDisks \
+ or disk.name in storage.clearPartDisks:
+ disk_space += disk.size
+
if self.mountpoint == "swap":
type = "swap"
self.mountpoint = ""
if self.recommended or self.hibernation:
- (self.size, self.maxSizeMB) = iutil.swapSuggestion(hibernation=self.hibernation)
+ (self.size, self.maxSizeMB) = \
+ iutil.swapSuggestion(hibernation=self.hibernation, disk_space=disk_space)
self.grow = True
# if people want to specify no mountpoint for some reason, let them
diff --git a/storage/partitioning.py b/storage/partitioning.py
index e20a18f..16b5823 100644
--- a/storage/partitioning.py
+++ b/storage/partitioning.py
@@ -244,6 +244,20 @@ def doAutoPartition(anaconda):
# sanity check the individual devices
log.warning("not sanity checking devices because I don't know how yet")
+ # get a new swap suggestion, now that we know the total disk space we're
+ # gonna use
+ disk_space = 0
+ for disk in anaconda.id.storage.disks:
+ if not anaconda.id.storage.clearPartDisks \
+ or disk.name in anaconda.id.storage.clearPartDisks:
+ disk_space += disk.size
+
+ (min_size, max_size) = iutil.swapSuggestion(disk_space=disk_space)
+ for request in anaconda.id.storage.autoPartitionRequests:
+ if request.fstype == "swap":
+ request.size = min_size
+ request.maxSize= max_size
+
# run the autopart function to allocate and grow partitions
try:
doPartitioning(anaconda.id.storage,
--
1.7.11.7
10 years, 9 months
[PATCH] Allow logging into multiple iscsi nodes at once (#975831).
by Chris Lumens
This just changes the radio buttons to checkmarks and uses the same credentials
for all checked.
---
pyanaconda/ui/gui/spokes/advstorage/iscsi.glade | 3 +--
pyanaconda/ui/gui/spokes/advstorage/iscsi.py | 6 +-----
2 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/pyanaconda/ui/gui/spokes/advstorage/iscsi.glade b/pyanaconda/ui/gui/spokes/advstorage/iscsi.glade
index 0d63450..911d904 100644
--- a/pyanaconda/ui/gui/spokes/advstorage/iscsi.glade
+++ b/pyanaconda/ui/gui/spokes/advstorage/iscsi.glade
@@ -648,8 +648,8 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
- <property name="xalign">0</property>
<property name="use_underline">True</property>
+ <property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
@@ -711,7 +711,6 @@
<object class="GtkTreeViewColumn" id="nodeSelectedColumn">
<child>
<object class="GtkCellRendererToggle" id="nodeSelectedRenderer">
- <property name="radio">True</property>
<signal name="toggled" handler="on_row_toggled" swapped="no"/>
</object>
<attributes>
diff --git a/pyanaconda/ui/gui/spokes/advstorage/iscsi.py b/pyanaconda/ui/gui/spokes/advstorage/iscsi.py
index 095c388..a183c85 100644
--- a/pyanaconda/ui/gui/spokes/advstorage/iscsi.py
+++ b/pyanaconda/ui/gui/spokes/advstorage/iscsi.py
@@ -325,13 +325,9 @@ class ISCSIDialog(GUIObject):
if not path:
return
- # First, mark all rows as unselected.
- for row in self._store:
- row[0] = False
-
# Then, go back and mark just this row as selected.
itr = self._store.get_iter(path)
- self._store[itr][0] = True
+ self._store[itr][0] = not self._store[itr][0]
def _login(self, credentials):
for row in self._store:
--
1.8.1.2
10 years, 9 months
[master][PATCH] Cleanup arch.py reredux
by Mark Hamzy
Clean up arch.py to have a common style, consistent indentation, removed the obvious
C to Python rewrite, removed the globals and function short circuiting, and import
the logger.
---
blivet/arch.py | 221 +++++++++++++++++++++++++--------------------------------
1 file changed, 95 insertions(+), 126 deletions(-)
diff --git a/blivet/arch.py b/blivet/arch.py
index 12cb30d..1e96e95 100644
--- a/blivet/arch.py
+++ b/blivet/arch.py
@@ -30,49 +30,29 @@ import os
from .flags import flags
+import logging
+log = logging.getLogger("blivet")
+
# DMI information paths
DMI_CHASSIS_VENDOR = "/sys/class/dmi/id/chassis_vendor"
-## Get the SPARC machine variety type.
-# @return The SPARC machine type, or 0 if not SPARC.
-def getSparcMachine():
- if not isSparc():
- return 0
-
- machine = None
-
-
- f = open('/proc/cpuinfo', 'r')
- lines = f.readlines()
- f.close()
- for line in lines:
- if line.find('type') != -1:
- machine = line.split(':')[1].strip()
- return machine
-
- return None
-
-## Get the PPC machine variety type.
-# @return The PPC machine type, or 0 if not PPC.
def getPPCMachine():
+ """:return: The PPC machine type, or None if not PPC.
+ :rtype: string"""
if not isPPC():
- return 0
-
- ppcMachine = None
- machine = None
- platform = None
+ return None
# ppc machine hash
# Note: This is a substring match!
ppcType = { 'Mac' : 'PMac',
'Book' : 'PMac',
- 'CHRP IBM' : 'pSeries',
+ 'CHRP' : 'pSeries',
+ 'CHRP IBM' : 'pSeries', # @TODO the CHRP entry above should match this
'Pegasos' : 'Pegasos',
'Efika' : 'Efika',
'iSeries' : 'iSeries',
'pSeries' : 'pSeries',
'PReP' : 'PReP',
- 'CHRP' : 'pSeries',
'Amiga' : 'APUS',
'Gemini' : 'Gemini',
'Shiner' : 'ANS',
@@ -85,100 +65,96 @@ def getPPCMachine():
'PS3' : 'PS3',
'PowerNV' : 'pSeries'
}
+ machine = None
+ platform = None
- f = open('/proc/cpuinfo', 'r')
- lines = f.readlines()
- f.close()
- for line in lines:
- if line.find('machine') != -1:
- machine = line.split(':')[1]
- elif line.find('platform') != -1:
- platform = line.split(':')[1]
+ with open('/proc/cpuinfo', 'r') as f:
+ for line in f:
+ if 'machine' in line:
+ machine = line.split(':')[1]
+ elif 'platform' in line:
+ platform = line.split(':')[1]
for part in (machine, platform):
- if ppcMachine is None and part is not None:
- for type in ppcType.items():
- if part.find(type[0]) != -1:
- ppcMachine = type[1]
+ if part is None:
+ continue
- if ppcMachine is None:
- log.warning("Unable to find PowerPC machine type")
- elif ppcMachine == 0:
- log.warning("Unknown PowerPC machine type: %s" %(ppcMachine,))
+ for type in ppcType.items():
+ if type[0] in part:
+ return type[1]
- return ppcMachine
+ log.warning("Unknown PowerPC machine type: %s platform: %s" % (machine, platform,))
-## Get the powermac machine ID.
-# @return The powermac machine id, or 0 if not PPC.
-def getPPCMacID():
- machine = None
+ return None
+def getPPCMacID():
+ """:return: The powermac machine type, or None if not PPC or a powermac.
+ :rtype: string"""
if not isPPC():
- return 0
+ return None
if getPPCMachine() != "PMac":
- return 0
+ return None
- f = open('/proc/cpuinfo', 'r')
- lines = f.readlines()
- f.close()
- for line in lines:
- if line.find('machine') != -1:
- machine = line.split(':')[1]
- machine = machine.strip()
- return machine
+ with open('/proc/cpuinfo', 'r') as f:
+ for line in f:
+ if 'machine' in line:
+ machine = line.split(':')[1]
+ return machine.strip()
log.warning("No Power Mac machine id")
- return 0
+ return None
-## Get the powermac generation.
-# @return The powermac generation, or 0 if not powermac.
def getPPCMacGen():
+ """:return: The PPC generation, or None if not PPC or a powermac.
+ :rtype: string"""
# XXX: should NuBus be here?
# Note: This is a substring match!
pmacGen = ['OldWorld', 'NewWorld', 'NuBus']
if not isPPC():
- return 0
+ return None
if getPPCMachine() != "PMac":
- return 0
+ return None
- f = open('/proc/cpuinfo', 'r')
- lines = f.readlines()
- f.close()
gen = None
- for line in lines:
- if line.find('pmac-generation') != -1:
- gen = line.split(':')[1]
- break
+ with open('/proc/cpuinfo', 'r') as f:
+ for line in f:
+ if 'pmac-generation' in line:
+ gen = line.split(':')[1]
+ break
if gen is None:
log.warning("Unable to find pmac-generation")
+ return None
for _type in pmacGen:
- if _type in gen:
- return _type
+ if _type in gen:
+ return _type
log.warning("Unknown Power Mac generation: %s" %(gen,))
- return 0
+ return None
-## Determine if the hardware is an iBook or PowerBook
-# @return 1 if so, 0 otherwise.
def getPPCMacBook():
+ """:return: True if the hardware is an iBook or PowerBook, False otherwise.
+ :rtype: string"""
if not isPPC():
- return 0
+ return False
if getPPCMachine() != "PMac":
- return 0
+ return False
- f = open('/proc/cpuinfo', 'r')
- buf = f.read()
- f.close()
- return 'book' in buf.lower()
+ #@TBD - Search for 'book' anywhere in cpuinfo? Shouldn't this be more restrictive?
+ with open('/proc/cpuinfo', 'r') as f:
+ for line in f:
+ if 'book' in line.lower():
+ return True
+
+ return False
-## Get the ARM processor variety.
-# @return The ARM processor variety type, or 0 if not ARM.
def getARMMachine():
+ """:return: The ARM processor variety type, or None if not ARM.
+ :rtype: string"""
if not isARM():
- return 0
+ return None
if flags.arm_platform:
return flags.arm_platform
@@ -186,41 +162,27 @@ def getARMMachine():
armMachine = os.uname()[2].rpartition('.' )[2]
if armMachine.startswith('arm'):
+ # @TBD - Huh? Don't you want the arm machine name here?
return None
else:
return armMachine
-
-cell = None
-## Determine if the hardware is the Cell platform.
-# @return True if so, False otherwise.
def isCell():
- global cell
- if cell is not None:
- return cell
-
- cell = False
+ """:return: True if the hardware is the Cell platform, False otherwise.
+ :rtype: boolean"""
if not isPPC():
- return cell
-
- f = open('/proc/cpuinfo', 'r')
- lines = f.readlines()
- f.close()
+ return False
- for line in lines:
- if 'Cell' in line:
- cell = True
+ with open('/proc/cpuinfo', 'r') as f:
+ for line in f:
+ if 'Cell' in line:
+ return True
- return cell
+ return False
-mactel = None
-## Determine if the hardware is an Intel-based Apple Mac.
-# @return True if so, False otherwise.
def isMactel():
- global mactel
- if mactel is not None:
- return mactel
-
+ """:return: True if the hardware is an Intel-based Apple Mac, False otherwise.
+ :rtype: boolean"""
if not isX86():
mactel = False
elif not os.path.isfile(DMI_CHASSIS_VENDOR):
@@ -230,24 +192,22 @@ def isMactel():
mactel = ("apple" in buf.lower())
return mactel
-efi = None
-## Determine if the hardware supports EFI.
-# @return True if so, False otherwise.
def isEfi():
- global efi
- if efi is not None:
- return efi
-
- efi = False
+ """:return: True if the hardware supports EFI, False otherwise.
+ :rtype: boolean"""
# XXX need to make sure efivars is loaded...
if os.path.exists("/sys/firmware/efi"):
- efi = True
-
- return efi
+ return True
+ else:
+ return False
# Architecture checking functions
def isX86(bits=None):
+ """:return: True if the hardware supports X86, False otherwise.
+ :rtype: boolean
+ :param bits: The number of bits used to define a memory address.
+ :type bits: int"""
arch = os.uname()[4]
# x86 platforms include:
@@ -272,6 +232,10 @@ def isX86(bits=None):
return False
def isPPC(bits=None):
+ """:return: True if the hardware supports PPC, False otherwise.
+ :rtype: boolean
+ :param bits: The number of bits used to define a memory address.
+ :type bits: int"""
arch = os.uname()[4]
if bits is None:
@@ -287,21 +251,28 @@ def isPPC(bits=None):
return False
def isS390():
+ """:return: True if the hardware supports PPC, False otherwise.
+ :rtype: boolean"""
return os.uname()[4].startswith('s390')
def isIA64():
+ """:return: True if the hardware supports IA64, False otherwise.
+ :rtype: boolean"""
return os.uname()[4] == 'ia64'
def isAlpha():
+ """:return: True if the hardware supports Alpha, False otherwise.
+ :rtype: boolean"""
return os.uname()[4].startswith('alpha')
-def isSparc():
- return os.uname()[4].startswith('sparc')
-
def isARM():
+ """:return: True if the hardware supports ARM, False otherwise.
+ :rtype: boolean"""
return os.uname()[4].startswith('arm')
def getArch():
+ """:return: The hardware architecture
+ :rtype: string"""
if isX86(bits=32):
return 'i386'
elif isX86(bits=64):
@@ -312,8 +283,6 @@ def getArch():
return 'ppc64'
elif isAlpha():
return 'alpha'
- elif isSparc():
- return 'sparc'
elif isARM():
return 'arm'
else:
--
1.8.1.4
10 years, 9 months
Re: [master][PATCH] Cleanup arch.py reredux
by Mark Hamzy
> It also seems like this module would be a good candidate for some tests,
> except that it reads from /proc/cpuinfo
Yeah, I thought about testing. Is there some way to fake that out?
Thanks vpodzime for the cosmetic fixes, BTW!
--
Mark
You must be the change you wish to see in the world. -- Mahatma Gandhi
Never let the future disturb you. You will meet it, if you have to, with
the same weapons of reason which today arm you against the present. --
Marcus Aurelius
10 years, 9 months