[master][PATCH] Cleanup arch.py
Mark Hamzy
hamzy at us.ibm.com
Fri Jul 12 18:44:59 UTC 2013
Clean up arch.py to have a common style, consistent indentation, removed the obvious
C to Python rewrite, and removed the globals and function short circuiting.
---
blivet/arch.py | 126 ++++++++++++++++++++-------------------------------------
1 file changed, 44 insertions(+), 82 deletions(-)
diff --git a/blivet/arch.py b/blivet/arch.py
index 12cb30d..8b2bf30 100644
--- a/blivet/arch.py
+++ b/blivet/arch.py
@@ -33,46 +33,23 @@ from .flags import flags
# 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.
+# @return The PPC machine type, or None if not PPC.
def getPPCMachine():
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,6 +62,8 @@ def getPPCMachine():
'PS3' : 'PS3',
'PowerNV' : 'pSeries'
}
+ machine = None
+ platform = None
f = open('/proc/cpuinfo', 'r')
lines = f.readlines()
@@ -96,89 +75,88 @@ def getPPCMachine():
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,))
+
+ return None
## Get the powermac machine ID.
-# @return The powermac machine id, or 0 if not PPC.
+# @return The powermac machine id, or None if not PPC.
def getPPCMacID():
- machine = None
-
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
+ if line.find('machine') != -1:
+ 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.
+# @return The powermac generation, or None if not powermac.
def getPPCMacGen():
# 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
+ if line.find('pmac-generation') != -1:
+ 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.
+# @return True if so, False otherwise.
def getPPCMacBook():
if not isPPC():
- return 0
+ return False
if getPPCMachine() != "PMac":
- return 0
+ return False
f = open('/proc/cpuinfo', 'r')
buf = f.read()
f.close()
+
+ #@TBD - Search for 'book' anywhere in cpuinfo? Shouldn't this be more restrictive?
return 'book' in buf.lower()
## Get the ARM processor variety.
-# @return The ARM processor variety type, or 0 if not ARM.
+# @return The ARM processor variety type, or None if not ARM.
def getARMMachine():
if not isARM():
- return 0
+ return None
if flags.arm_platform:
return flags.arm_platform
@@ -186,19 +164,14 @@ 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
if not isPPC():
return cell
@@ -208,19 +181,14 @@ def isCell():
f.close()
for line in lines:
- if 'Cell' in line:
- cell = True
+ if 'Cell' in line:
+ cell = True
return cell
-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
-
if not isX86():
mactel = False
elif not os.path.isfile(DMI_CHASSIS_VENDOR):
@@ -230,20 +198,14 @@ 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
# 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
--
1.8.1.4
More information about the anaconda-patches
mailing list