Skip to content

Commit c98c6a6

Browse files
authored
[About] * add rust version (#3591)
[About] * add rust version * getFileCompressionInfo switch from popen to pure python
1 parent a215800 commit c98c6a6

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

lib/python/Components/About.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,16 +342,44 @@ def getPythonVersionString():
342342
return _("Unknown")
343343

344344

345-
def getVersionFromOpkg(fileName):
346-
return next((line[9:].split("+")[0] for line in (fileReadLines(f"/var/lib/opkg/info/{fileName}.control", source=MODULE_NAME) or []) if line.startswith("Version:")), _("Not Installed"))
345+
def getRustVersion():
346+
try:
347+
major, minor = pyversion.split('.')[:2]
348+
so_path = f"/usr/lib/python{major}.{minor}/site-packages/bcrypt/_bcrypt.cpython-{major}{minor}-arm-linux-gnueabihf.so"
349+
350+
with open(so_path, "rb") as f:
351+
f.seek(428000)
352+
content = f.read(20000)
353+
354+
# Search for something like 'rustc-1.85.1' in the binary content
355+
match = search(rb'rustc-([0-9]+.[0-9]+(.[0-9]+)?)', content)
356+
if match:
357+
return match.group(1).decode("utf-8")
358+
except:
359+
pass
360+
361+
return _("Unknown")
347362

348363

349364
def getFileCompressionInfo():
350-
result = Popen("strings /bin/bash | grep '$Id: UPX.*Copyright'", stdout=PIPE, shell=True, text=True)
351-
# $Id: UPX 4.24 Copyright (C) 1996-2024 the UPX Team. All Rights Reserved. $
352-
output = result.communicate()[0]
353-
parts = output.strip().split() if result.returncode == 0 and output else []
354-
return f"{_("Enabled")} ({parts[1].lower()} {parts[2]})" if len(parts) >= 3 else _("Disabled")
365+
try:
366+
with open("/bin/bash", "rb") as f:
367+
f.seek(399000)
368+
content = f.read(1000)
369+
370+
# Search for something like 'Id: UPX 4.24 Copyright (C) 1996-2024 the UPX Team. All Rights Reserved.' in the binary content
371+
match = search(rb'Id: UPX.*Copyright', content)
372+
if match:
373+
parts = match.group(0).decode("utf-8").strip().split()
374+
return f"{_("Enabled")} ({parts[1].lower()} {parts[2]})" if len(parts) >= 3 else _("Disabled")
375+
except:
376+
pass
377+
378+
return _("Disabled")
379+
380+
381+
def getVersionFromOpkg(fileName):
382+
return next((line[9:].split("+")[0] for line in (fileReadLines(f"/var/lib/opkg/info/{fileName}.control", source=MODULE_NAME) or []) if line.startswith("Version:")), _("Not Installed"))
355383

356384

357385
# For modules that do "from About import about"

lib/python/Screens/Information.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ def displayInformation(self):
700700
info.append(formatLine("P1", _("Glibc version"), about.getGlibcVersion()))
701701
info.append(formatLine("P1", _("OpenSSL version"), about.getVersionFromOpkg("openssl")))
702702
info.append(formatLine("P1", _("Python version"), about.getPythonVersionString()))
703+
info.append(formatLine("P1", _("Rust version"), about.getRustVersion()))
703704
info.append(formatLine("P1", _("Samba version"), about.getVersionFromOpkg("samba")))
704705
info.append(formatLine("P1", _("GStreamer version"), about.getGStreamerVersionString().replace("GStreamer ", "")))
705706
info.append(formatLine("P1", _("FFmpeg version"), about.getVersionFromOpkg("ffmpeg")))

0 commit comments

Comments
 (0)