Merge pull request #13 from makermelissa/main

Add Raspberry Pi OS 64-bit Detection
This commit is contained in:
Melissa LeBlanc-Williams 2021-09-09 17:37:32 -07:00 committed by GitHub
commit 3c023111a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -88,7 +88,7 @@ class Shell:
if not suppress_message: if not suppress_message:
self.info(decoded_output) self.info(decoded_output)
full_output += decoded_output full_output += decoded_output
except Exception as err: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
pass pass
finally: finally:
sys.stdout = original_stdout sys.stdout = original_stdout
@ -294,7 +294,7 @@ class Shell:
if self.exists(location) and not self.isdir(location): if self.exists(location) and not self.isdir(location):
if multi_line: if multi_line:
with open(location, "r+") as file: with open(location, "r+", encoding="utf-8") as file:
if re.search(pattern, file.read(), flags=re.DOTALL): if re.search(pattern, file.read(), flags=re.DOTALL):
found = True found = True
else: else:
@ -315,7 +315,7 @@ class Shell:
if self.pattern_search(location, pattern, multi_line): if self.pattern_search(location, pattern, multi_line):
if multi_line: if multi_line:
regex = re.compile(pattern, flags=re.DOTALL) regex = re.compile(pattern, flags=re.DOTALL)
with open(location, "r+") as file: with open(location, "r+", encoding="utf-8") as file:
data = file.read() data = file.read()
file.seek(0) file.seek(0)
file.write(regex.sub(replace, data)) file.write(regex.sub(replace, data))
@ -397,7 +397,7 @@ class Shell:
content = "\n" + content content = "\n" + content
else: else:
mode = "w" mode = "w"
with open(self.path(path), mode) as service_file: with open(self.path(path), mode, encoding="utf-8") as service_file:
service_file.write(content) service_file.write(content)
@staticmethod @staticmethod
@ -441,6 +441,13 @@ class Shell:
""" """
return platform.machine() == "armv8l" return platform.machine() == "armv8l"
@staticmethod
def is_arm64():
"""
Check if Platform.machine() returns ARM 64
"""
return platform.machine() == "aarch64"
@staticmethod @staticmethod
def get_arch(): def get_arch():
"""Return a string containing the architecture""" """Return a string containing the architecture"""
@ -461,15 +468,17 @@ class Shell:
) )
release = None release = None
if os.path.exists("/etc/os-release"): if os.path.exists("/etc/os-release"):
with open("/etc/os-release") as f: with open("/etc/os-release", encoding="utf-8") as f:
if "Raspbian" in f.read(): if "Raspbian" in f.read():
release = "Raspbian" release = "Raspbian"
if self.run_command("command -v apt-get", suppress_message=True): if self.run_command("command -v apt-get", suppress_message=True):
with open("/etc/os-release") as f: with open("/etc/os-release", encoding="utf-8") as f:
release_file = f.read() release_file = f.read()
for opsys in os_releases: for opsys in os_releases:
if opsys in release_file: if opsys in release_file:
release = opsys release = opsys
if release == "Debian" and os.path.exists("/etc/rpi-issue"):
release = "Raspbian"
if os.path.isdir(os.path.expanduser("~/.kano-settings")) or os.path.isdir( if os.path.isdir(os.path.expanduser("~/.kano-settings")) or os.path.isdir(
os.path.expanduser("~/.kanoprofile") os.path.expanduser("~/.kanoprofile")
): ):
@ -486,7 +495,7 @@ class Shell:
return None return None
raspbian_releases = ("buster", "stretch", "jessie", "wheezy") raspbian_releases = ("buster", "stretch", "jessie", "wheezy")
if os.path.exists("/etc/os-release"): if os.path.exists("/etc/os-release"):
with open("/etc/os-release") as f: with open("/etc/os-release", encoding="utf-8") as f:
release_file = f.read() release_file = f.read()
if "/sid" in release_file: if "/sid" in release_file:
return "unstable" return "unstable"