class RunSoftwareUpdate(Screen, HelpableScreen): skin = """ <screen name="RunSoftwareUpdate" position="center,center" size="720,435" resolution="1280,720"> <widget name="update" position="10,10" size="700,400" font="Regular;20" halign="center" transparent="1" valign="center" /> <widget name="activity" position="10,420" size="700,5" /> </screen>""" def __init__(self, session, *args): Screen.__init__(self, session) HelpableScreen.__init__(self) self.setTitle(_("Software Update")) self.onTimerTick = [] self["update"] = ScrollLabel( _("Software update starting, please wait.\n\n")) self["activity"] = Slider(0, 100) self["actions"] = HelpableActionMap( self, ["OkCancelActions", "NavigationActions"], { "cancel": (self.keyCancel, _("Stop the update, if running, then exit")), "ok": (self.keyCancel, _("Stop the update, if running, then exit")), "top": (self.top, _("Move to first line / screen")), "pageUp": (self.pageUp, _("Move up a page / screen")), "up": (self.pageUp, _("Move up a page / screen")), # "first": (self.top, _("Move to first line / screen")), "left": (self.pageUp, _("Move up a page / screen")), "right": (self.pageDown, _("Move down a page / screen")), # "last": (self.bottom, _("Move to last line / screen")), "down": (self.pageDown, _("Move down a page / screen")), "pageDown": (self.pageDown, _("Move down a page / screen")), "bottom": (self.bottom, _("Move to last line / screen")) }, prio=0, description=_("Software Update Actions")) self.activity = 0 self.timer = eTimer() self.timer.callback.append(self.timeout) self.packageTotal = 0 self.downloadCount = 0 self.updateCount = 0 self.installCount = 0 self.removeCount = 0 self.deselectCount = 0 self.upgradeCount = 0 self.configureCount = 0 self.errorCount = 0 self.updateFlag = True self.opkg = OpkgComponent() self.opkg.addCallback(self.opkgCallback) self.onLayoutFinish.append(self.layoutFinished) def layoutFinished(self): self.opkg.startCmd(OpkgComponent.CMD_UPDATE) self.timer.start(25, True) def timeout(self): if self.activity < 0: self.timer.stop() self["activity"].hide() else: self.activity += 1 if self.activity == 100: self.activity = 0 self["activity"].setValue(self.activity) self.timer.start(100, True) for callback in self.onTimerTick: callback() def opkgCallback(self, event, parameter): if event == OpkgComponent.EVENT_DOWNLOAD: self.downloadCount += 1 if parameter.find( "_" ) == -1: # Only display the downloading of the feed packages. self["update"].appendText("%s: '%s'.\n" % (_("Downloading"), parameter)) elif event == OpkgComponent.EVENT_UPDATED: self.updateCount += 1 self["update"].appendText("%s: %s\n" % (_("Updated"), parameter)) elif event == OpkgComponent.EVENT_UPVERSION: self.upgradeCount += 1 self["update"].appendText("%s %s/%s: '%s'.\n" % (_("Updating"), self.upgradeCount, self.packageTotal, parameter)) elif event == OpkgComponent.EVENT_INSTALL: self.installCount += 1 self["update"].appendText("%s: '%s'.\n" % (_("Installing"), parameter)) elif event == OpkgComponent.EVENT_REMOVE: self.removeCount += 1 self["update"].appendText("%s: '%s'.\n" % (_("Removing"), parameter)) elif event == OpkgComponent.EVENT_CONFIGURING: self.configureCount += 1 self["update"].appendText("%s: '%s'.\n" % (_("Configuring"), parameter)) elif event == OpkgComponent.EVENT_MODIFIED: if config.plugins.softwaremanager.overwriteConfigFiles.value in ( "N", "Y"): self.opkg.write( True and config.plugins.softwaremanager.overwriteConfigFiles.value) else: self.session.openWithCallback( self.modificationCallback, MessageBox, _("Configuration file '%s' has been modified since it was installed, would you like to keep the modified version?" ) % parameter) elif event == OpkgComponent.EVENT_ERROR: self.errorCount += 1 elif event == OpkgComponent.EVENT_DONE: if self.updateFlag: self.updateFlag = False self.opkg.startCmd(OpkgComponent.CMD_UPGRADE_LIST) elif self.opkg.currentCommand == OpkgComponent.CMD_UPGRADE_LIST: self.packageTotal = len(self.opkg.getFetchedList()) if self.packageTotal: self.opkg.startCmd(OpkgComponent.CMD_UPGRADE, args={"testMode": False}) else: self.activity = -1 self["update"].appendText( "%s\n\n%s" % (_("No updates available."), _("Press OK on your remote control to continue."))) else: if self.errorCount == 0: self["update"].appendText("\n%s\n\n" % _("Update completed.")) self["update"].appendText( "%s\n" % ngettext("%d package was identified for upgrade.", "%d packages were identified for upgrade.", self.packageTotal) % self.packageTotal) self["update"].appendText("%s\n" % ngettext( "%d package was downloaded.", "%d packages were downloaded.", self.downloadCount) % self.downloadCount) self["update"].appendText( "%s\n" % ngettext("%d feed catalog package was updated.", "%d feed catalog packages were updated.", self.updateCount) % self.updateCount) self["update"].appendText("%s\n" % ngettext( "%d package was installed.", "%d packages were installed.", self.installCount) % self.installCount) self["update"].appendText("%s\n" % ngettext( "%d package was removed.", "%d packages were removed.", self.removeCount) % self.removeCount) self["update"].appendText("%s\n" % ngettext( "%d package was upgraded.", "%d packages were upgraded.", self.upgradeCount) % self.upgradeCount) self["update"].appendText("%s\n" % ngettext( "%d package was configured.", "%d packages were configured.", self.configureCount) % self.configureCount) if self.deselectCount: self["update"].appendText( "%s\n" % ngettext("%d package was deselected.", "%d packages were deselected.", self.deselectCount) % self.deselectCount) self["update"].appendText("\n%s\n" % _( "Deselected packages usually occur because those packaged are incompatible with existing packages. While this is mostly harmless it is possible that your %s %s may experience issues." ) % (displayBrand, displayModel)) else: error = _( "Your receiver might be unusable now. Please consult the manual for further assistance before rebooting your %s %s." ) % (displayBrand, displayModel) if self.upgradeCount == 0: error = _( "No updates were available. Please try again later." ) self["update"].appendText("%s: %s\n" % (_("Error"), error)) self.activity = -1 self["update"].appendText( "\n%s" % _("Press OK on your remote control to continue.")) def modificationCallback(self, answer): self.opkg.write("N" if answer else "Y") def keyCancel(self): if self.opkg.isRunning(): self.opkg.stop() self.opkg.removeCallback(self.opkgCallback) if self.upgradeCount != 0 and self.errorCount == 0: self.restoreMetrixHD() else: self.close() def keyCancelCallback(self, answer): if answer: self.session.open(TryQuitMainloop, retvalue=QUIT_REBOOT) self.close() def top(self): self["update"].moveTop() def pageUp(self): self["update"].pageUp() def pageDown(self): self["update"].pageDown() def bottom(self): self["update"].moveBottom() def createSummary(self): return RunSoftwareUpdateSummary def restoreMetrixHD( self ): # TODO: call this only after metrix update / move this to Metrix Plugin try: if config.skin.primary_skin.value == "MetrixHD/skin.MySkin.xml": if not exists("/usr/share/enigma2/MetrixHD/skin.MySkin.xml"): from Plugins.SystemPlugins.SoftwareManager.BackupRestore import RestoreMyMetrixHD self.session.openWithCallback(self.restoreMetrixHDCallback, RestoreMyMetrixHD) return elif config.plugins.MyMetrixLiteOther.EHDenabled.value != '0': from Plugins.Extensions.MyMetrixLite.ActivateSkinSettings import ActivateSkinSettings ActivateSkinSettings().RefreshIcons() except: pass self.restoreMetrixHDCallback() def restoreMetrixHDCallback(self, ret=None): self.session.openWithCallback( self.keyCancelCallback, MessageBox, _("Upgrade finished.") + " " + _("Do you want to reboot your %s %s?") % (displayBrand, displayModel))
class SoftwareUpdate(Screen, HelpableScreen, ProtectedScreen): FEED_UNKNOWN = 0 FEED_DISABLED = 1 FEED_UNSTABLE = 2 FEED_STABLE = 3 skin = [ """ <screen name="SoftwareUpdate" title="Software Update" position="center,center" size="%d,%d" > <widget name="traffic_off" position="%d,%d" size="%d,%d" alphatest="blend" pixmap="icons/traffic_off.png" scale="1" /> <widget name="traffic_red" position="%d,%d" size="%d,%d" alphatest="blend" pixmap="icons/traffic_red.png" scale="1" /> <widget name="traffic_yellow" position="%d,%d" size="%d,%d" alphatest="blend" pixmap="icons/traffic_yellow.png" scale="1" /> <widget name="traffic_green" position="%d,%d" size="%d,%d" alphatest="blend" pixmap="icons/traffic_green.png" scale="1" /> <widget name="feedstatus_off" position="%d,%d" size="%d,%d" font="Regular;%d" transparent="1" valign="center" /> <widget name="feedstatus_red" position="%d,%d" size="%d,%d" font="Regular;%d" transparent="1" valign="center" /> <widget name="feedstatus_yellow" position="%d,%d" size="%d,%d" font="Regular;%d" transparent="1" valign="center" /> <widget name="feedstatus_green" position="%d,%d" size="%d,%d" font="Regular;%d" transparent="1" valign="center" /> <widget name="package_text" position="%d,%d" size="%d,%d" font="Regular;%d" transparent="1" valign="center" /> <widget name="package_count" position="%d,%d" size="%d,%d" font="Regular;%d" halign="right" transparent="1" valign="center" /> <widget name="feedmessage" position="%d,%d" size="%d,%d" font="Regular;%d" transparent="1" /> <widget name="activity" position="%d,%d" size="%d,%d" /> <widget source="list" render="Listbox" position="%d,%d" size="%d,%d" scrollbarMode="showOnDemand"> <convert type="TemplatedMultiContent"> { "template": [ MultiContentEntryText(pos = (%d, %d), size = (%d, %d), font=0, flags = RT_HALIGN_LEFT | RT_VALIGN_CENTER, text = 0), # Index 0 is the name. MultiContentEntryText(pos = (%d, %d), size = (%d, %d), font=1, flags = RT_HALIGN_LEFT | RT_VALIGN_CENTER, text = 2), # Index 2 is the description. MultiContentEntryPixmapAlphaBlend(pos = (%d, %d), size = (%d, %d), flags = BT_SCALE, png = 4), # Index 4 is the status pixmap. MultiContentEntryPixmapAlphaBlend(pos = (%d, %d), size = (%d, %d), png = 5), # Index 5 is the div pixmap ], "fonts": [gFont("Regular", %d), gFont("Regular", %d)], "itemHeight": %d } </convert> </widget> <widget source="key_red" render="Label" position="%d,e-%d" size="%d,%d" backgroundColor="key_red" font="Regular;%d" foregroundColor="key_text" halign="center" valign="center"> <convert type="ConditionalShowHide" /> </widget> <widget source="key_green" render="Label" position="%d,e-%d" size="%d,%d" backgroundColor="key_green" font="Regular;%d" foregroundColor="key_text" halign="center" valign="center"> <convert type="ConditionalShowHide" /> </widget> <widget source="key_yellow" render="Label" position="%d,e-%d" size="%d,%d" backgroundColor="key_yellow" font="Regular;%d" foregroundColor="key_text" halign="center" valign="center"> <convert type="ConditionalShowHide" /> </widget> </screen>""", 650, 580, # SoftwareUpdate 10, 10, 36, 97, # traffic_off 10, 10, 36, 97, # traffic_red 10, 10, 36, 97, # traffic_yellow 10, 10, 36, 97, # traffic_green 60, 46, 200, 30, 20, # feedstatus_off 60, 14, 200, 30, 20, # feedstatus_red 60, 46, 200, 30, 20, # feedstatus_yellow 60, 78, 200, 30, 20, # feedstatus_green 330, 10, 250, 30, 25, # package_text 590, 10, 50, 30, 25, # package_count 330, 50, 310, 50, 20, # feedmessage 330, 102, 310, 5, # activity 10, 120, 630, 400, # list 10, 0, 535, 30, # Index 0 - name 20, 30, 515, 20, # Index 2 - description 560, 0, 48, 48, # Index 4 - status pixmap 5, 48, 630, 2, # Index 5 - div pixmap 22, 15, # fonts 50, # itemHeight 10, 50, 180, 40, 20, # key_red 200, 50, 180, 40, 20, # key_green 390, 50, 180, 40, 20 # key_yellow ] def __init__(self, session, *args): Screen.__init__(self, session) HelpableScreen.__init__(self) ProtectedScreen.__init__(self) Screen.setTitle(self, _("Software Update")) self.onCheckTrafficLight = [] self.updateList = [] self["list"] = List(self.updateList, enableWrapAround=True) self["key_red"] = StaticText(_("Cancel")) self["key_green"] = StaticText("") self["key_yellow"] = StaticText("") self["traffic_off"] = Pixmap() self["traffic_red"] = Pixmap() self["traffic_red"].hide() self["traffic_yellow"] = Pixmap() self["traffic_yellow"].hide() self["traffic_green"] = Pixmap() self["traffic_green"].hide() self["feedstatus_off"] = Label(_("Status unavailable!")) self["feedstatus_off"].hide() self["feedstatus_red"] = Label("< %s" % _("Feed disabled!")) self["feedstatus_red"].hide() self["feedstatus_yellow"] = Label("< %s" % _("Feed unstable!")) self["feedstatus_yellow"].hide() self["feedstatus_green"] = Label("< %s" % _("Feed stable.")) self["feedstatus_green"].hide() self["feedmessage"] = Label() self["package_text"] = Label(_("Updates available:")) self["package_count"] = Label("?") self["activity"] = Slider(0, 100) cancelMsg = _("Cancel / Close the software update screen") updateMsg = _("Proceed with the update") self["actions"] = HelpableActionMap( self, ["OkCancelActions", "ColorActions", "NavigationActions"], { "cancel": (self.keyCancel, cancelMsg), "red": (self.keyCancel, cancelMsg), "top": (self.top, _("Move to first line / screen")), "pageUp": (self.pageUp, _("Move up a page / screen")), "up": (self.up, _("Move up a line")), # "first": (self.top, _("Move to first line / screen")), "left": (self.pageUp, _("Move up a page / screen")), "right": (self.pageDown, _("Move down a page / screen")), # "last": (self.bottom, _("Move to last line / screen")), "down": (self.down, _("Move down a line")), "pageDown": (self.pageDown, _("Move down a page / screen")), "bottom": (self.bottom, _("Move to last line / screen")) }, prio=0, description=_("Software Update Actions")) self["updateActions"] = HelpableActionMap( self, ["OkCancelActions", "ColorActions"], { "ok": (self.keyUpdate, updateMsg), "green": (self.keyUpdate, updateMsg) }, prio=0, description=_("Software Update Actions")) self["updateActions"].setEnabled(False) self["refreshActions"] = HelpableActionMap( self, ["ColorActions"], { "yellow": (self.keyRefresh, _("Refresh the update-able package list")) }, prio=0, description=_("Software Update Actions")) self["refreshActions"].setEnabled(False) self.activity = 0 self.feedState = self.FEED_UNKNOWN self.updateFlag = True self.packageCount = 0 self.timer = eTimer() self.timer.callback.append(self.timeout) self.timer.callback.append(self.checkTrafficLight) self.opkg = OpkgComponent() self.opkg.addCallback(self.opkgCallback) self.onLayoutFinish.append(self.layoutFinished) def isProtected(self): return config.ParentalControl.setuppinactive.value and \ (not config.ParentalControl.config_sections.main_menu.value and not config.ParentalControl.config_sections.configuration.value or hasattr(self.session, "infobar") and self.session.infobar is None) and \ config.ParentalControl.config_sections.software_update.value def layoutFinished(self): self["list"].master.master.instance.allowNativeKeys(False) self.setStatus("update") self.opkg.startCmd(OpkgComponent.CMD_UPDATE) self.timer.start(25, True) def timeout(self): if self.activity < 0: self.timer.stop() self["activity"].hide() else: self.activity += 1 if self.activity == 100: self.activity = 0 self["activity"].setValue(self.activity) self.timer.start(100, True) def checkTrafficLight(self): self.timer.callback.remove(self.checkTrafficLight) try: # status = dict(load(urlopen("%s/%s.php" % (BoxInfo.getItem("feedsurl"), BoxInfo.getItem("model")), timeout=5))) # message = status.get("message") # status = status.get("status") status = "" message = "" with urlopen("http://ampel.mynonpublic.com/Ampel/index.php") as fd: tmpStatus = fd.read() if b"rot.png" in tmpStatus: status = "YELLOW" if exists("/etc/.beta") else "RED" elif b"gelb.png" in tmpStatus: status = "YELLOW" elif b"gruen.png" in tmpStatus: status = "GREEN" self["traffic_off"].hide() if status == "RED": self["traffic_red"].show() self["feedstatus_red"].show() self.feedState = self.FEED_DISABLED elif status == "YELLOW": self["traffic_yellow"].show() self["feedstatus_yellow"].show() self.feedState = self.FEED_UNSTABLE elif status == "GREEN": self["traffic_green"].show() self["feedstatus_green"].show() self.feedState = self.FEED_STABLE if message: self["feedmessage"].setText(_(message)) except Exception as err: print( "[SoftwareUpdate] Error: Unable to get server status! (%s)" % str(err)) self["feedstatus_off"].show() for callback in self.onCheckTrafficLight: callback() def opkgCallback(self, event, parameter): if event == OpkgComponent.EVENT_ERROR: self.setStatus("error") self.activity = -1 elif event == OpkgComponent.EVENT_DONE: if self.updateFlag: self.updateFlag = False self.opkg.startCmd(OpkgComponent.CMD_UPGRADE_LIST) else: self.updateList = [] fetchedList = self.opkg.getFetchedList() count = len(fetchedList) if count > 0: upgradeablePng = LoadPixmap(cached=True, path=resolveFilename( SCOPE_GUISKIN, "icons/upgradeable.png")) divPng = LoadPixmap(cached=True, path=resolveFilename( SCOPE_GUISKIN, "div-h.png")) for fetched in fetchedList: oldVer = fetched[1] if fetched[1] else _( "Current version unknown") newVer = fetched[2] if fetched[2] else _( "Updated version unknown") self.updateList.append( (fetched[0], fetched[1], "%s -> %s" % (oldVer, newVer), "upgradeable", upgradeablePng, divPng)) if self.updateList: self.updateList.sort( key=lambda x: x[0]) # Sort by package name. self["list"].setList(self.updateList) else: self.setStatus("noupdate") elif count == 0: self.setStatus("noupdate") else: self.setStatus("error") self.packageCount = len(self.updateList) print("[SoftwareUpdate] %d packages available for update." % self.packageCount) self["package_count"].setText(str(self.packageCount)) for callback in self.onCheckTrafficLight: callback() if self.packageCount: if self.feedState == self.FEED_DISABLED: self["key_red"].setText(_("Close")) self["key_green"].setText("") self["updateActions"].setEnabled(False) else: self["key_red"].setText(_("Cancel")) self["key_green"].setText(_("Update")) self["updateActions"].setEnabled(True) else: self["key_red"].setText(_("Close")) self["key_yellow"].setText(_("Refresh")) self["refreshActions"].setEnabled(True) self.activity = -1 def setStatus(self, status): if status == "update": imagePath = resolveFilename(SCOPE_GUISKIN, "icons/upgrade.png") name = _("Package list update") description = _("Downloading latest update list. Please wait...") elif status == "error": imagePath = resolveFilename(SCOPE_GUISKIN, "icons/remove.png") name = _("Download error") description = _( "There was an error downloading the update list. Please try again." ) elif status == "noupdate": imagePath = resolveFilename(SCOPE_GUISKIN, "icons/installed.png") name = _("Nothing to upgrade") description = _("There are no updates available.") statusPng = LoadPixmap(cached=True, path=imagePath) divPng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_GUISKIN, "div-h.png")) self["list"].setList([(name, "", description, "", statusPng, divPng)]) def keyCancel(self): if self.opkg.isRunning(): self.opkg.stop() self.opkg.removeCallback(self.opkgCallback) self.close() def keyUpdate(self): self.opkg.removeCallback(self.opkgCallback) updateLimit = BoxInfo.getItem("UpdateLimit", 200) if self.packageCount <= updateLimit: self.keyUpdateCallback(2) else: print( "[SoftwareUpdate] Warning: There are %d packages available, more than the %d maximum recommended, for an update!" % (self.packageCount, updateLimit)) message = [ _("Warning: There are %d update packages!") % self.packageCount, _("There is a risk that your %s %s will not boot or may malfunction after such a large on-line update." ) % (displayBrand, displayModel), _("You should flash a new image!"), _("What would you like to do?") ] message = "\n\n".join(message) optionList = [(_("Cancel the update"), 0), (_("Perform an on-line flash instead"), 1), (_("Continue with the on-line update"), 2)] self.session.openWithCallback(self.keyUpdateCallback, MessageBox, message, list=optionList, default=0) def keyUpdateCallback(self, answer): if answer == 1: from Screens.FlashManager import FlashManager # This must be here to ensure the plugin is initialized. self.session.open(FlashManager) elif answer == 2: self.session.open(RunSoftwareUpdate) self.close() def keyRefresh(self): self.timer.callback.append(self.checkTrafficLight) self["key_red"].setText(_("Cancel")) self["key_green"].setText("") self["key_yellow"].setText("") self["updateActions"].setEnabled(False) self["refreshActions"].setEnabled(False) self["package_count"].setText("?") self["traffic_off"].show() self["traffic_red"].hide() self["traffic_yellow"].hide() self["traffic_green"].hide() self["feedstatus_off"].hide() self["feedstatus_red"].hide() self["feedstatus_yellow"].hide() self["feedstatus_green"].hide() self["feedmessage"].setText("") self.activity = 0 self["activity"].setValue(self.activity) self["activity"].show() self.setStatus("update") self.opkg.startCmd(OpkgComponent.CMD_UPDATE) self.timer.start(25, True) def top(self): self["list"].top() def pageUp(self): self["list"].pageUp() def up(self): self["list"].up() def down(self): self["list"].down() def pageDown(self): self["list"].pageDown() def bottom(self): self["list"].bottom() def createSummary(self): return SoftwareUpdateSummary
class ShowSoftcamPackages(Screen): skin = """ <screen name="ShowSoftcamPackages" position="center,center" size="630,500" resolution="1280,720"> <widget source="list" render="Listbox" position="10,10" size="620,420" enableWrapAround="1" scrollbarMode="showOnDemand"> <convert type="TemplatedMultiContent"> { "template": [ MultiContentEntryText(pos = (5, 1), size = (540, 28), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 0 is the name MultiContentEntryText(pos = (5, 26), size = (540, 20), font=1, flags = RT_HALIGN_LEFT, text = 2), # index 2 is the description MultiContentEntryPixmapAlphaBlend(pos = (545, 2), size = (48, 48), png = 4), # index 3 is the status pixmap MultiContentEntryPixmapAlphaBlend(pos = (5, 50), size = (510, 2), png = 5), # index 4 is the div pixmap ], "fonts": [gFont("Regular", 22),gFont("Regular", 14)], "itemHeight": 52 } </convert> </widget> <widget source="key_red" render="Label" position="10,e-50" size="140,40" backgroundColor="key_red" font="Regular;20" foregroundColor="key_text" halign="center" valign="center"> <convert type="ConditionalShowHide" /> </widget> <widget source="key_green" render="Label" position="160,e-50" size="140,40" backgroundColor="key_green" font="Regular;20" foregroundColor="key_text" halign="center" valign="center"> <convert type="ConditionalShowHide" /> </widget> <widget source="key_yellow" render="Label" position="310,e-50" size="140,40" backgroundColor="key_yellow" font="Regular;20" foregroundColor="key_text" halign="center" valign="center"> <convert type="ConditionalShowHide" /> </widget> </screen>""" def __init__(self, session, args=None): Screen.__init__(self, session) self.setTitle(_("Install Softcams")) self["actions"] = HelpableActionMap(self, ["OkCancelActions", "NavigationActions", "ColorActions"], { "cancel": (self.keyCancel, _("Stop the update, if running, then exit")), "ok": (self.keyOk, _("Install/Remove plugin")), "green": (self.keyOk, _("Install/Remove plugin")), "top": (self.top, _("Move to first line / screen")), "pageUp": (self.pageUp, _("Move up a page / screen")), "up": (self.pageUp, _("Move up a page / screen")), # "first": (self.top, _("Move to first line")), "left": (self.pageUp, _("Move up a page / screen")), "right": (self.pageDown, _("Move down a page / screen")), # "last": (self.bottom, _("Move to last line")), "down": (self.pageDown, _("Move down a page / screen")), "pageDown": (self.pageDown, _("Move down a page / screen")), "bottom": (self.bottom, _("Move to last line / screen")), "yellow": (self.keyRefresh, _("Refresh the update-able package list")) }, prio=0, description=_("Software Update Actions")) self["list"] = List([]) self["list"].onSelectionChanged.append(self.selectionChanged) self["key_red"] = StaticText(_("Close")) self["key_yellow"] = StaticText(_("Reload")) self["key_green"] = StaticText(_("Install")) self.installpackage = None self.opkg = OpkgComponent() self.opkg.addCallback(self.opkgCallback) self.onLayoutFinish.append(self.layoutFinished) def opkgCallback(self, event, parameter): if event == OpkgComponent.EVENT_DONE: if self.opkg.currentCommand == OpkgComponent.CMD_UPDATE: self.rebuildList() elif self.opkg.currentCommand == OpkgComponent.CMD_LIST: self.Flist = self.opkg.getFetchedList() self.opkg.startCmd(OpkgComponent.CMD_LIST_INSTALLED, args={"package": "enigma2-plugin-softcams-*"}) elif self.opkg.currentCommand == OpkgComponent.CMD_LIST_INSTALLED: self.Elist = self.opkg.getFetchedList() if len(self.Flist) > 0: self.buildPacketList() else: self.setStatus('error') elif self.opkg.currentCommand == OpkgComponent.CMD_INSTALL: self.session.open(MessageBox, _("Install Finished."), MessageBox.TYPE_INFO, timeout=5) self.rebuildList() elif self.opkg.currentCommand == OpkgComponent.CMD_REMOVE: self.session.open(MessageBox, _("Remove Finished."), MessageBox.TYPE_INFO, timeout=5) self.rebuildList() elif event == OpkgComponent.EVENT_ERROR: if self.opkg.currentCommand == OpkgComponent.CMD_INSTALL: self.session.open(MessageBox, _("Install Failed !!"), MessageBox.TYPE_ERROR, timeout=10) elif self.opkg.currentCommand == OpkgComponent.CMD_REMOVE: self.session.open(MessageBox, _("Remove Failed !!"), MessageBox.TYPE_ERROR, timeout=10) else: self.setStatus("error") def layoutFinished(self): self.rebuildList() def selectionChanged(self): cur = self["list"].getCurrent() if cur and len(cur) > 3: self["key_green"].text = _("Install") if cur[3] == "installable" else _("Remove") def keyOk(self, returnValue=None): cur = self["list"].getCurrent() if cur: self.installpackage = cur[0] if cur[3] == "installable": self.session.openWithCallback(self.runInstall, MessageBox, "%s%s - %s\n%s" % (_("Do you want to install the package:\n"), cur[0], cur[1], _("\nPress OK on your remote control to continue."))) else: self.session.openWithCallback(self.runUnInstall, MessageBox, "%s%s - %s\n%s" % (_("Do you want to remove the package:\n"), cur[0], cur[1], _("\nPress OK on your remote control to continue."))) def runInstall(self, result): if result and self.installpackage: self.opkg.startCmd(OpkgComponent.CMD_INSTALL, {"package": self.installpackage}) def runUnInstall(self, result): if result and self.installpackage: self.opkg.startCmd(OpkgComponent.CMD_REMOVE, {"package": self.installpackage}) def keyCancel(self): if self.opkg.isRunning(): self.opkg.stop() self.opkg.removeCallback(self.opkgCallback) self.close() def setStatus(self, status=None): if status: image = "upgrade" if status == "update": name = _("Package list update") description = _("Downloading latest update list. Please wait...") elif status == "list": name = _("Package list") description = _("Getting Softcam list. Please wait...") elif status == "error": image = "remove" name = _("Download error") description = _("There was an error downloading the update list. Please try again.") imagePath = resolveFilename(SCOPE_GUISKIN, "icons/%s.png" % image) divPng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_GUISKIN, "div-h.png")) statusPng = LoadPixmap(cached=True, path=imagePath) self['list'].setList([(name, "", description, "", statusPng, divPng)]) def keyRefresh(self): self.setStatus("update") self.opkg.startCmd(OpkgComponent.CMD_UPDATE) def rebuildList(self): self.Flist = [] self.Elist = [] self.setStatus("list") self.opkg.startCmd(OpkgComponent.CMD_LIST, args={"package": "enigma2-plugin-softcams-*"}) def buildPacketList(self): plist = [] excludeList = [x[0] for x in self.Elist] divpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_GUISKIN, "div-h.png")) installedpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_GUISKIN, "icons/installed.png")) installablepng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_GUISKIN, "icons/installable.png")) if len(self.Flist) > 0: for x in self.Flist: if len(x) > 1: state = "installable" if x[0] not in excludeList else "installed" image = installablepng if x[0] not in excludeList else installedpng name = x[0] version = x[1] description = "" if len(x) > 2: description = x[2] plist.append((name, version, _(description), state, image, divpng)) self['list'].setList(plist) else: self.setStatus('error') def top(self): self["list"].top() def pageUp(self): self["list"].pageUp() def up(self): self["list"].up() def down(self): self["list"].down() def pageDown(self): self["list"].pageDown() def bottom(self): self["list"].bottom()
class SoftwareTools(PackageInfoHandler): lastDownloadDate = None NetworkConnectionAvailable = None list_updating = False available_updates = 0 available_updatelist = [] available_packetlist = [] installed_packetlist = {} def __init__(self): aboutInfo = about.getImageVersionString() if aboutInfo.startswith("dev-"): self.ImageVersion = 'Experimental' else: self.ImageVersion = 'Stable' self.language = language.getLanguage( )[:2] # getLanguage returns e.g. "fi_FI" for "language_country" PackageInfoHandler.__init__(self, self.statusCallback, neededTag='ALL_TAGS', neededFlag=self.ImageVersion) self.directory = resolveFilename(SCOPE_METADIR) self.list = List([]) self.NotifierCallback = None self.Console = Console() self.UpdateConsole = Console() self.cmdList = [] self.unwanted_extensions = ('-dbg', '-dev', '-doc', '-staticdev', '-src') self.opkg = OpkgComponent() self.opkg.addCallback(self.opkgCallback) def statusCallback(self, status, progress): pass def startSoftwareTools(self, callback=None): if callback is not None: self.NotifierCallback = callback iNetwork.checkNetworkState(self.checkNetworkCB) def checkNetworkCB(self, data): if data is not None: if data <= 2: self.NetworkConnectionAvailable = True self.getUpdates() else: self.NetworkConnectionAvailable = False self.getUpdates() def getUpdates(self, callback=None): if self.lastDownloadDate is None: if self.NetworkConnectionAvailable == True: self.lastDownloadDate = time() if self.list_updating is False and callback is None: self.list_updating = True self.opkg.startCmd(OpkgComponent.CMD_UPDATE) elif self.list_updating is False and callback is not None: self.list_updating = True self.NotifierCallback = callback self.opkg.startCmd(OpkgComponent.CMD_UPDATE) elif self.list_updating is True and callback is not None: self.NotifierCallback = callback else: self.list_updating = False if callback is not None: callback(False) elif self.NotifierCallback is not None: self.NotifierCallback(False) else: if self.NetworkConnectionAvailable == True: self.lastDownloadDate = time() if self.list_updating is False and callback is None: self.list_updating = True self.opkg.startCmd(OpkgComponent.CMD_UPDATE) elif self.list_updating is False and callback is not None: self.list_updating = True self.NotifierCallback = callback self.opkg.startCmd(OpkgComponent.CMD_UPDATE) elif self.list_updating is True and callback is not None: self.NotifierCallback = callback else: if self.list_updating and callback is not None: self.NotifierCallback = callback self.startOpkgListAvailable() else: self.list_updating = False if callback is not None: callback(False) elif self.NotifierCallback is not None: self.NotifierCallback(False) def opkgCallback(self, event, param): if event == OpkgComponent.EVENT_ERROR: self.list_updating = False if self.NotifierCallback is not None: self.NotifierCallback(False) elif event == OpkgComponent.EVENT_DONE: if self.list_updating: self.startOpkgListAvailable() pass def startOpkgListAvailable(self, callback=None): if callback is not None: self.list_updating = True if self.list_updating: if not self.UpdateConsole: self.UpdateConsole = Console() cmd = self.opkg.opkg + " list" self.UpdateConsole.ePopen(cmd, self.OpkgListAvailableCB, callback) def OpkgListAvailableCB(self, result, retval, extra_args=None): (callback) = extra_args if result: if self.list_updating: self.available_packetlist = [] for x in result.splitlines(): tokens = x.split(' - ') name = tokens[0].strip() if not any( name.endswith(x) for x in self.unwanted_extensions): l = len(tokens) version = l > 1 and tokens[1].strip() or "" descr = l > 2 and tokens[2].strip() or "" self.available_packetlist.append( [name, version, descr]) if callback is None: self.startInstallMetaPackage() else: if self.UpdateConsole: if not self.UpdateConsole.appContainers: callback(True) else: self.list_updating = False if self.UpdateConsole: if not self.UpdateConsole.appContainers: if callback is not None: callback(False) def startInstallMetaPackage(self, callback=None): if callback is not None: self.list_updating = True if self.list_updating: if self.NetworkConnectionAvailable == True: if not self.UpdateConsole: self.UpdateConsole = Console() cmd = self.opkg.opkg + " install enigma2-meta enigma2-plugins-meta enigma2-skins-meta" self.UpdateConsole.ePopen(cmd, self.InstallMetaPackageCB, callback) else: self.InstallMetaPackageCB(True) def InstallMetaPackageCB(self, result, retval=None, extra_args=None): (callback) = extra_args if result: self.fillPackagesIndexList() if callback is None: self.startOpkgListInstalled() else: if self.UpdateConsole: if not self.UpdateConsole.appContainers: callback(True) else: self.list_updating = False if self.UpdateConsole: if not self.UpdateConsole.appContainers: if callback is not None: callback(False) def startOpkgListInstalled(self, callback=None): if callback is not None: self.list_updating = True if self.list_updating: if not self.UpdateConsole: self.UpdateConsole = Console() cmd = self.opkg.opkg + " list_installed" self.UpdateConsole.ePopen(cmd, self.OpkgListInstalledCB, callback) def OpkgListInstalledCB(self, result, retval, extra_args=None): (callback) = extra_args if result: self.installed_packetlist = {} for x in result.splitlines(): tokens = x.split(' - ') name = tokens[0].strip() if not any(name.endswith(x) for x in self.unwanted_extensions): l = len(tokens) version = l > 1 and tokens[1].strip() or "" self.installed_packetlist[name] = version for package in self.packagesIndexlist[:]: if not self.verifyPrerequisites(package[0]["prerequisites"]): self.packagesIndexlist.remove(package) for package in self.packagesIndexlist[:]: attributes = package[0]["attributes"] if "packagetype" in attributes: if attributes["packagetype"] == "internal": self.packagesIndexlist.remove(package) if callback is None: self.countUpdates() else: if self.UpdateConsole: if not self.UpdateConsole.appContainers: callback(True) else: self.list_updating = False if self.UpdateConsole: if not self.UpdateConsole.appContainers: if callback is not None: callback(False) def countUpdates(self, callback=None): self.available_updates = 0 self.available_updatelist = [] for package in self.packagesIndexlist[:]: attributes = package[0]["attributes"] packagename = attributes["packagename"] for x in self.available_packetlist: if x[0] == packagename: if packagename in self.installed_packetlist: if self.installed_packetlist[packagename] != x[1]: self.available_updates += 1 self.available_updatelist.append([packagename]) self.list_updating = False if self.UpdateConsole: if not self.UpdateConsole.appContainers: if callback is not None: callback(True) callback = None elif self.NotifierCallback is not None: self.NotifierCallback(True) self.NotifierCallback = None def startOpkgUpdate(self, callback=None): if not self.Console: self.Console = Console() cmd = self.opkg.opkg + " update" self.Console.ePopen(cmd, self.OpkgUpdateCB, callback) def OpkgUpdateCB(self, result, retval, extra_args=None): (callback) = extra_args if result: if self.Console: if not self.Console.appContainers: if callback is not None: callback(True) callback = None def cleanupSoftwareTools(self): self.list_updating = False if self.NotifierCallback is not None: self.NotifierCallback = None self.opkg.stop() if self.Console is not None: self.Console.killAll() if self.UpdateConsole is not None: self.UpdateConsole.killAll() def verifyPrerequisites(self, prerequisites): if "hardware" in prerequisites: hardware_found = False for hardware in prerequisites["hardware"]: if hardware == getBoxType(): hardware_found = True if not hardware_found: return False return True
class SoftwarePanel(Screen): def __init__(self, session, *args): Screen.__init__(self, session) Screen.setTitle(self, _("Openeight Software Panel")) skin = """ <screen name="SoftwarePanel" position="center,center" size="650,605" title="Software Panel"> <widget name="a_off" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/ExtrasPanel/pics/aoff.png" position="10,10" zPosition="1" size="36,97" alphatest="on" /> <widget name="a_red" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/ExtrasPanel/pics/ared.png" position="10,10" zPosition="1" size="36,97" alphatest="on" /> <widget name="a_yellow" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/ExtrasPanel/pics/ayellow.png" position="10,10" zPosition="1" size="36,97" alphatest="on" /> <widget name="a_green" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/ExtrasPanel/pics/agreen.png" position="10,10" zPosition="1" size="36,97" alphatest="on" /> <widget name="feedstatusRED" position="60,14" size="200,30" zPosition="1" font="Regular;25" halign="left" transparent="1" /> <widget name="feedstatusYELLOW" position="60,46" size="200,30" zPosition="1" font="Regular;25" halign="left" transparent="1" /> <widget name="feedstatusGREEN" position="60,78" size="200,30" zPosition="1" font="Regular;25" halign="left" transparent="1" /> <widget name="packagetext" position="276,50" size="247,30" zPosition="1" font="Regular;25" halign="right" transparent="1" /> <widget name="packagenr" position="529,50" size="69,30" zPosition="1" font="Regular;25" halign="left" transparent="1" /> <widget source="list" render="Listbox" position="10,120" size="630,365" scrollbarMode="showOnDemand"> <convert type="TemplatedMultiContent"> {"template": [ MultiContentEntryText(pos = (5, 1), size = (540, 28), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 0 is the name MultiContentEntryText(pos = (5, 26), size = (540, 20), font=1, flags = RT_HALIGN_LEFT, text = 2), # index 2 is the description MultiContentEntryPixmapAlphaTest(pos = (545, 2), size = (48, 48), png = 4), # index 4 is the status pixmap MultiContentEntryPixmapAlphaTest(pos = (5, 50), size = (610, 2), png = 5), # index 4 is the div pixmap ], "fonts": [gFont("Regular", 22),gFont("Regular", 14)], "itemHeight": 52 } </convert> </widget> <ePixmap pixmap="skin_default/buttons/red.png" position="30,560" size="138,40" alphatest="blend" /> <widget name="key_green_pic" pixmap="skin_default/buttons/green.png" position="180,560" size="138,40" alphatest="blend" /> <ePixmap pixmap="skin_default/buttons/yellow.png" position="333,560" size="138,40" alphatest="blend" /> <ePixmap pixmap="skin_default/buttons/blue.png" position="481,560" size="138,40" alphatest="blend" /> <widget name="key_red" position="38,570" size="124,26" zPosition="1" font="Regular;17" halign="center" transparent="1" /> <widget name="key_green" position="188,570" size="124,26" zPosition="1" font="Regular;17" halign="center" transparent="1" /> <widget name="key_yellow" position="340,570" size="124,26" zPosition="1" font="Regular;17" halign="center" transparent="1" /> <widget name="key_blue" position="491,570" size="124,26" zPosition="1" font="Regular;17" halign="center" transparent="1" /> </screen> """ self.skin = skin self.list = [] self.statuslist = [] self["list"] = List(self.list) self['a_off'] = Pixmap() self['a_red'] = Pixmap() self['a_yellow'] = Pixmap() self['a_green'] = Pixmap() self['key_green_pic'] = Pixmap() self['key_red_pic'] = Pixmap() self['key_red'] = Label(_("Cancel")) self['key_green'] = Label(_("Update")) self['key_yellow'] = Label(_("")) self['packagetext'] = Label(_("Updates Available:")) self['packagenr'] = Label("0") self['feedstatusRED'] = Label("< " + _("feed status")) self['feedstatusYELLOW'] = Label("< " + _("feed status")) self['feedstatusGREEN'] = Label("< " + _("feed status")) self['key_green'].hide() self['key_green_pic'].hide() self.update = False self.packages = 0 self.trafficLight = 0 self.opkg = OpkgComponent() self.opkg.addCallback(self.opkgCallback) self["actions"] = ActionMap([ "OkCancelActions", "DirectionActions", "ColorActions", "SetupActions" ], { "cancel": self.Exit, "green": self.Green, "yellow": self.showCommitLog }, -2) self.onLayoutFinish.append(self.layoutFinished) def Exit(self): self.opkg.stop() self.close() def Green(self): if self.packages > 0 and self.trafficLight > 0: if self.trafficLight == 1: # yellow message = _( "The current image might not be stable.\nFor more information see %s." ) % ("http://octagon-forum.eu") picon = MessageBox.TYPE_WARNING elif self.trafficLight == 2: # red message = _( "The current image is not stable.\nFor more information see %s." ) % ("http://octagon-forum.eu") picon = MessageBox.TYPE_ERROR self.session.open(MessageBox, message, type=MessageBox.TYPE_ERROR, picon=picon, timeout=15, close_on_any_key=True) return elif self.trafficLight == 3: # unknown message = _( "The status of the current image could not be checked because %s can not be reached." ) % ("http://octagon-forum.eu") picon = MessageBox.TYPE_ERROR message += "\n" + _("Do you want to update your receiver?") self.session.openWithCallback(self.startActualUpdate, MessageBox, message, default=False, picon=picon) elif self.packages > 0: self.startActualUpdate(True) def showCommitLog(self): self.session.open(CommitInfo) def startActualUpdate(self, answer): if answer: from Plugins.SystemPlugins.SoftwareManager.plugin import UpdatePlugin self.session.open(UpdatePlugin) self.close() def layoutFinished(self): self.checkTrafficLight() self.rebuildList() def UpdatePackageNr(self): self.packages = len(self.list) print self.packages print "packagenr" + str(self.packages) self["packagenr"].setText(str(self.packages)) if self.packages == 0: self['key_green'].hide() self['key_green_pic'].hide() else: self['key_green'].show() self['key_green_pic'].show() def checkTrafficLight(self): print "checkTrafficLight" from urllib import urlopen import socket self['a_red'].hide() self['a_yellow'].hide() self['a_green'].hide() self['feedstatusRED'].hide() self['feedstatusYELLOW'].hide() self['feedstatusGREEN'].hide() currentTimeoutDefault = socket.getdefaulttimeout() socket.setdefaulttimeout(3) try: urlOpeneight = "http://feed.openeight.de/status" d = urlopen(urlOpeneight) self.trafficLight = int(d.read()) if self.trafficLight == 2: self['a_off'].hide() self['a_red'].show() self['feedstatusRED'].show() elif self.trafficLight == 1: self['a_off'].hide() self['a_yellow'].show() self['feedstatusYELLOW'].show() elif self.trafficLight == 0: self['a_off'].hide() self['a_green'].show() self['feedstatusGREEN'].show() except: self.trafficLight = 3 self['a_off'].show() socket.setdefaulttimeout(currentTimeoutDefault) def setStatus(self, status=None): if status: self.statuslist = [] divpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/div-h.png")) if status == 'update': statuspng = LoadPixmap( cached=True, path=resolveFilename( SCOPE_CURRENT_PLUGIN, "SystemPlugins/SoftwareManager/upgrade.png")) self.statuslist.append( (_("Package list update"), '', _("Trying to download a new updatelist. Please wait..."), '', statuspng, divpng)) elif status == 'error': statuspng = LoadPixmap( cached=True, path=resolveFilename( SCOPE_CURRENT_PLUGIN, "SystemPlugins/SoftwareManager/remove.png")) self.statuslist.append(( _("Error"), '', _("There was an error downloading the updatelist. Please try again." ), '', statuspng, divpng)) elif status == 'noupdate': statuspng = LoadPixmap( cached=True, path=resolveFilename( SCOPE_CURRENT_PLUGIN, "SystemPlugins/SoftwareManager/installed.png")) self.statuslist.append((_("Nothing to upgrade"), '', _("There are no updates available."), '', statuspng, divpng)) self['list'].setList(self.statuslist) def rebuildList(self): self.setStatus('update') self.opkg.startCmd(OpkgComponent.CMD_UPDATE) def opkgCallback(self, event, param): if event == OpkgComponent.EVENT_ERROR: self.setStatus('error') elif event == OpkgComponent.EVENT_DONE: if self.update == False: self.update = True self.opkg.startCmd(OpkgComponent.CMD_UPGRADE_LIST) else: self.buildPacketList() pass def buildEntryComponent(self, name, version, description, state): divpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/div-h.png")) if not description: description = "No description available." if state == 'installed': installedpng = LoadPixmap( cached=True, path=resolveFilename( SCOPE_CURRENT_PLUGIN, "SystemPlugins/SoftwareManager/installed.png")) return ((name, version, _(description), state, installedpng, divpng)) elif state == 'upgradeable': upgradeablepng = LoadPixmap( cached=True, path=resolveFilename( SCOPE_CURRENT_PLUGIN, "SystemPlugins/SoftwareManager/upgradeable.png")) return ((name, version, _(description), state, upgradeablepng, divpng)) else: installablepng = LoadPixmap( cached=True, path=resolveFilename( SCOPE_CURRENT_PLUGIN, "SystemPlugins/SoftwareManager/installable.png")) return ((name, version, _(description), state, installablepng, divpng)) def buildPacketList(self): self.list = [] fetchedList = self.opkg.getFetchedList() if len(fetchedList) > 0: for x in fetchedList: try: self.list.append( self.buildEntryComponent(x[0], x[1], x[2], "upgradeable")) except: print "[SOFTWAREPANEL] " + x[ 0] + " no valid architecture, ignoring !!" self['list'].setList(self.list) elif len(fetchedList) == 0: self.setStatus('noupdate') else: self.setStatus('error') self.UpdatePackageNr()