Skip to content

Commit

Permalink
[Multiboot] use enigma.info for image details (#4038)
Browse files Browse the repository at this point in the history
  • Loading branch information
Huevos committed Jul 22, 2024
1 parent e303d73 commit a005a09
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions lib/python/Tools/Multiboot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from Components.SystemInfo import BoxInfo
from Components.SystemInfo import BoxInfo, BoxInformation
from Components.Console import Console
from Tools.Directories import fileHas, fileExists
from datetime import datetime
import os
import glob
import tempfile
Expand Down Expand Up @@ -35,6 +36,29 @@ def getparam(line, param):
return line.replace("userdataroot", "rootuserdata").rsplit('%s=' % param, 1)[1].split(' ', 1)[0]


def createInfo(slot, imagedir="/"):
BoxInfoInstance = BoxInformation(root=imagedir) if getCurrentImage() != slot else BoxInfo
Creator = BoxInfoInstance.getItem("distro", "").capitalize()
BuildImgVersion = BoxInfoInstance.getItem("imgversion")
BuildType = BoxInfoInstance.getItem("imagetype", "")[0:3]
BuildVer = BoxInfoInstance.getItem("imagebuild")
BuildDate = VerDate(imagedir)
BuildDev = str(idb).zfill(3) if BuildType and BuildType != "rel" and (idb := BoxInfoInstance.getItem("imagedevbuild")) else ""
return " ".join([str(x).strip() for x in (Creator, BuildImgVersion, BuildType, BuildVer, BuildDev, "(%s)" % BuildDate) if x and str(x).strip()])


def VerDate(imagedir):
date1 = date2 = date3 = "00000000"
if fileExists(os.path.join(imagedir, "var/lib/opkg/status")):
date1 = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "var/lib/opkg/status")).st_mtime).strftime("%Y-%m-%d")
date2 = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/enigma2")).st_mtime).strftime("%Y-%m-%d")
if fileExists(os.path.join(imagedir, "usr/share/bootlogo.mvi")):
date3 = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/share/bootlogo.mvi")).st_mtime).strftime("%Y-%m-%d")
date = max(date1, date2, date3) # this is comparing strings
date = datetime.strptime(date, '%Y-%m-%d').strftime("%d-%m-%Y")
return date


def getMultibootslots():
bootslots = {}
mode12found = False
Expand Down Expand Up @@ -139,18 +163,16 @@ def getImagelist():
Console().ePopen('mount %s %s' % (BoxInfo.getItem("canMultiBoot")[slot]['device'], tmp.dir))
imagedir = os.sep.join(filter(None, [tmp.dir, BoxInfo.getItem("canMultiBoot")[slot].get('rootsubdir', '')]))
if os.path.isfile(os.path.join(imagedir, 'usr/bin/enigma2')):
try:
from datetime import datetime
date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "var/lib/opkg/status")).st_mtime).strftime('%Y-%m-%d')
if date.startswith("1970"):
date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/share/bootlogo.mvi")).st_mtime).strftime('%Y-%m-%d')
date = max(date, datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/enigma2")).st_mtime).strftime('%Y-%m-%d'))
except:
date = _("Unknown")
try:
imagelist[slot] = {'imagename': "%s (%s)" % (open(os.path.join(imagedir, "etc/issue")).readlines()[0].capitalize().strip()[:-6], date)}
except IndexError:
imagelist[slot] = {'imagename': _("Unknown image")}
if os.path.isfile(os.path.join(imagedir, "usr/lib/enigma.info")):
print("[multiboot] [GetImagelist] using enigma.info")
imagelist[slot] = {'imagename': createInfo(slot, imagedir=imagedir)}
else:
print("[multiboot] [GetImagelist] using etc/issue")
date = VerDate(imagedir)
try:
imagelist[slot] = {'imagename': "%s (%s)" % (open(os.path.join(imagedir, "etc/issue")).readlines()[0].capitalize().strip()[:-6], date)}
except IndexError:
imagelist[slot] = {'imagename': _("Unknown image")}
elif os.path.isfile(os.path.join(imagedir, 'usr/bin/enigma2.bak')):
imagelist[slot] = {'imagename': _("Deleted image")}
else:
Expand Down

0 comments on commit a005a09

Please sign in to comment.