Skip to content

Commit 3c02311

Browse files
authored
Merge pull request #13 from makermelissa/main
Add Raspberry Pi OS 64-bit Detection
2 parents 264f418 + 6cfaeaf commit 3c02311

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

adafruit_shell.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def run_command(self, cmd, suppress_message=False, return_output=False):
8888
if not suppress_message:
8989
self.info(decoded_output)
9090
full_output += decoded_output
91-
except Exception as err: # pylint: disable=broad-except
91+
except Exception: # pylint: disable=broad-except
9292
pass
9393
finally:
9494
sys.stdout = original_stdout
@@ -294,7 +294,7 @@ def pattern_search(self, location, pattern, multi_line=False):
294294

295295
if self.exists(location) and not self.isdir(location):
296296
if multi_line:
297-
with open(location, "r+") as file:
297+
with open(location, "r+", encoding="utf-8") as file:
298298
if re.search(pattern, file.read(), flags=re.DOTALL):
299299
found = True
300300
else:
@@ -315,7 +315,7 @@ def pattern_replace(self, location, pattern, replace="", multi_line=False):
315315
if self.pattern_search(location, pattern, multi_line):
316316
if multi_line:
317317
regex = re.compile(pattern, flags=re.DOTALL)
318-
with open(location, "r+") as file:
318+
with open(location, "r+", encoding="utf-8") as file:
319319
data = file.read()
320320
file.seek(0)
321321
file.write(regex.sub(replace, data))
@@ -397,7 +397,7 @@ def write_text_file(self, path, content, append=True):
397397
content = "\n" + content
398398
else:
399399
mode = "w"
400-
with open(self.path(path), mode) as service_file:
400+
with open(self.path(path), mode, encoding="utf-8") as service_file:
401401
service_file.write(content)
402402

403403
@staticmethod
@@ -441,6 +441,13 @@ def is_armv8():
441441
"""
442442
return platform.machine() == "armv8l"
443443

444+
@staticmethod
445+
def is_arm64():
446+
"""
447+
Check if Platform.machine() returns ARM 64
448+
"""
449+
return platform.machine() == "aarch64"
450+
444451
@staticmethod
445452
def get_arch():
446453
"""Return a string containing the architecture"""
@@ -461,15 +468,17 @@ def get_os(self):
461468
)
462469
release = None
463470
if os.path.exists("/etc/os-release"):
464-
with open("/etc/os-release") as f:
471+
with open("/etc/os-release", encoding="utf-8") as f:
465472
if "Raspbian" in f.read():
466473
release = "Raspbian"
467474
if self.run_command("command -v apt-get", suppress_message=True):
468-
with open("/etc/os-release") as f:
475+
with open("/etc/os-release", encoding="utf-8") as f:
469476
release_file = f.read()
470477
for opsys in os_releases:
471478
if opsys in release_file:
472479
release = opsys
480+
if release == "Debian" and os.path.exists("/etc/rpi-issue"):
481+
release = "Raspbian"
473482
if os.path.isdir(os.path.expanduser("~/.kano-settings")) or os.path.isdir(
474483
os.path.expanduser("~/.kanoprofile")
475484
):
@@ -486,7 +495,7 @@ def get_raspbian_version(self):
486495
return None
487496
raspbian_releases = ("buster", "stretch", "jessie", "wheezy")
488497
if os.path.exists("/etc/os-release"):
489-
with open("/etc/os-release") as f:
498+
with open("/etc/os-release", encoding="utf-8") as f:
490499
release_file = f.read()
491500
if "/sid" in release_file:
492501
return "unstable"

0 commit comments

Comments
 (0)