diff --git a/lib/python/Tools/Multiboot.py b/lib/python/Tools/Multiboot.py index 7691093897b..c739876e414 100644 --- a/lib/python/Tools/Multiboot.py +++ b/lib/python/Tools/Multiboot.py @@ -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 @@ -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 @@ -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: