[blivet][PATCH 1/5] Add support for returning machine word length

Martin Kolman mkolman at redhat.com
Thu Nov 7 17:52:11 UTC 2013


Add support for returning machine word length to
the arch module.

This is needed as some filesystems, such as tmpfs,
have maximum filesystem size that depends on the
machine word size.

Related: rhbz#918621
Signed-off-by: Martin Kolman <mkolman at redhat.com>
---
 blivet/arch.py | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/blivet/arch.py b/blivet/arch.py
index 9fa7826..b63dc9f 100644
--- a/blivet/arch.py
+++ b/blivet/arch.py
@@ -25,9 +25,17 @@
 #            Dennis Gilmore <dgilmore at ausil.us>
 #            David Marlin <dmarlin at redhat.com>
 #
+from __future__ import absolute_import
+# The absolute_import is needed so that we can
+# import the "platform" module from the Python
+# standard library but not the local blivet module
+# that is also called "platform".
 
 import os
 
+import logging
+log = logging.getLogger("blivet")
+
 from .flags import flags
 
 # DMI information paths
@@ -318,3 +326,26 @@ def getArch():
         return 'arm'
     else:
         return os.uname()[4]
+
+def bits():
+    """Return an integer representing the length
+    of the "word" used by the current architecture
+    -> it is usually either 32 or 64
+
+    :return: number of bits for the current architecture
+    or None if the number could not be determined
+    :rtype: integer or None
+    """
+    try:
+        import platform
+        bits = platform.architecture()[0]
+        # the string is in the format:
+        # "<number>bit"
+        # so we remove the bit suffix and convert the
+        # number to an integer
+        bits = bits.replace("bit", "")
+        bits = int(bits)
+        return bits
+    except Exception as e:
+        log.error("architecture word size detection failed: %s" % e)
+        return None
-- 
1.8.3.1



More information about the anaconda-patches mailing list