From 95fa0e8c06f26bc2c4d3b5ab6afc772cd991e9dc Mon Sep 17 00:00:00 2001 From: acid-burn Date: Fri, 13 Feb 2009 11:47:46 +0100 Subject: add SoftwareManager and show it inside Setup Menu --- .../SystemPlugins/SoftwareManager/BackupRestore.py | 313 +++++++++++++++++++++ 1 file changed, 313 insertions(+) create mode 100755 lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py (limited to 'lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py') diff --git a/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py b/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py new file mode 100755 index 00000000..f92472d3 --- /dev/null +++ b/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py @@ -0,0 +1,313 @@ +from Screens.Screen import Screen +from Screens.MessageBox import MessageBox +from Screens.Console import Console +from Components.ActionMap import ActionMap, NumberActionMap +from Components.Pixmap import Pixmap +from Components.Label import Label +from Components.MenuList import MenuList +from Components.config import getConfigListEntry, configfile, ConfigSelection, ConfigSubsection, ConfigText, ConfigLocations +from Components.config import config +from Components.ConfigList import ConfigList,ConfigListScreen +from Components.FileList import MultiFileSelectList +from Plugins.Plugin import PluginDescriptor +from enigma import eTimer +from Tools.Directories import * +from os import popen, path, makedirs, listdir, access, stat, rename, remove, W_OK, R_OK +from time import gmtime, strftime, localtime +from datetime import date + + +config.plugins.configurationbackup = ConfigSubsection() +config.plugins.configurationbackup.backuplocation = ConfigText(default = '/media/hdd/', visible_width = 50, fixed_size = False) +config.plugins.configurationbackup.backupdirs = ConfigLocations(default=['/etc/enigma2/', '/etc/network/interfaces', '/etc/wpa_supplicant.conf']) + +def getBackupPath(): + backuppath = config.plugins.configurationbackup.backuplocation.value + if backuppath.endswith('/'): + return backuppath + 'backup' + else: + return backuppath + '/backup' + +def getBackupFilename(): + return "enigma2settingsbackup.tar.gz" + + +class BackupScreen(Screen, ConfigListScreen): + skin = """ + + + """ + + def __init__(self, session, runBackup = False): + Screen.__init__(self, session) + self.session = session + self.runBackup = runBackup + self["actions"] = ActionMap(["WizardActions", "DirectionActions"], + { + "ok": self.close, + "back": self.close, + "cancel": self.close, + }, -1) + self.finished_cb = None + self.backuppath = getBackupPath() + self.backupfile = getBackupFilename() + self.fullbackupfilename = self.backuppath + "/" + self.backupfile + self.list = [] + ConfigListScreen.__init__(self, self.list) + self.onLayoutFinish.append(self.layoutFinished) + if self.runBackup: + self.onShown.append(self.doBackup) + + def layoutFinished(self): + self.setWindowTitle() + + def setWindowTitle(self): + self.setTitle(_("Backup running...")) + + def doBackup(self): + try: + if (path.exists(self.backuppath) == False): + makedirs(self.backuppath) + self.backupdirs = ' '.join( config.plugins.configurationbackup.backupdirs.value ) + if path.exists(self.fullbackupfilename): + dt = str(date.fromtimestamp(stat(self.fullbackupfilename).st_ctime)) + self.newfilename = self.backuppath + "/" + dt + '-' + self.backupfile + if path.exists(self.newfilename): + remove(self.newfilename) + rename(self.fullbackupfilename,self.newfilename) + if self.finished_cb: + self.session.openWithCallback(self.finished_cb, Console, title = _("Backup running"), cmdlist = ["tar -czvf " + self.fullbackupfilename + " " + self.backupdirs],finishedCallback = self.backupFinishedCB,closeOnSuccess = True) + else: + self.session.open(Console, title = _("Backup running"), cmdlist = ["tar -czvf " + self.fullbackupfilename + " " + self.backupdirs],finishedCallback = self.backupFinishedCB, closeOnSuccess = True) + except OSError: + if self.finished_cb: + self.session.openWithCallback(self.finished_cb, MessageBox, _("Sorry your backup destination is not writeable.\nPlease choose an other one."), MessageBox.TYPE_INFO) + else: + self.session.openWithCallback(self.backupErrorCB,MessageBox, _("Sorry your backup destination is not writeable.\nPlease choose an other one."), MessageBox.TYPE_INFO) + + def backupFinishedCB(self,retval = None): + self.close(True) + + def backupErrorCB(self,retval = None): + self.close(False) + + def runAsync(self, finished_cb): + self.finished_cb = finished_cb + self.doBackup() + + +class BackupSelection(Screen): + skin = """ + + + + + + + + + """ + + def __init__(self, session): + Screen.__init__(self, session) + self.skin_path = plugin_path + self["key_red"] = Label(_("Cancel")) + self["key_green"] = Label(_("Save")) + self["key_yellow"] = Label() + + self.selectedFiles = config.plugins.configurationbackup.backupdirs.value + defaultDir = '/' + inhibitDirs = ["/bin", "/boot", "/dev", "/autofs", "/lib", "/proc", "/sbin", "/sys", "/hdd", "/tmp", "/mnt", "/media"] + self.filelist = MultiFileSelectList(self.selectedFiles, defaultDir, inhibitDirs = inhibitDirs ) + self["checkList"] = self.filelist + + self["actions"] = ActionMap(["DirectionActions", "OkCancelActions", "ShortcutActions"], + { + "cancel": self.exit, + "red": self.exit, + "yellow": self.changeSelectionState, + "green": self.saveSelection, + "ok": self.okClicked, + "left": self.left, + "right": self.right, + "down": self.down, + "up": self.up + }, -1) + if not self.selectionChanged in self["checkList"].onSelectionChanged: + self["checkList"].onSelectionChanged.append(self.selectionChanged) + self.onLayoutFinish.append(self.layoutFinished) + + def layoutFinished(self): + idx = 0 + self["checkList"].moveToIndex(idx) + self.setWindowTitle() + self.selectionChanged() + + def setWindowTitle(self): + self.setTitle(_("Select files/folders to backup...")) + + def selectionChanged(self): + current = self["checkList"].getCurrent()[0] + if current[2] is True: + self["key_yellow"].setText(_("Deselect")) + else: + self["key_yellow"].setText(_("Select")) + + def up(self): + self["checkList"].up() + + def down(self): + self["checkList"].down() + + def left(self): + self["checkList"].pageUp() + + def right(self): + self["checkList"].pageDown() + + def changeSelectionState(self): + self["checkList"].changeSelectionState() + self.selectedFiles = self["checkList"].getSelectedList() + + def saveSelection(self): + self.selectedFiles = self["checkList"].getSelectedList() + config.plugins.configurationbackup.backupdirs.value = self.selectedFiles + config.plugins.configurationbackup.backupdirs.save() + config.plugins.configurationbackup.save() + config.save() + self.close(None) + + def exit(self): + self.close(None) + + def okClicked(self): + if self.filelist.canDescent(): + self.filelist.descent() + + +class RestoreMenu(Screen): + skin = """ + + + + + + + """ + + def __init__(self, session, plugin_path): + Screen.__init__(self, session) + self.skin_path = plugin_path + + self["canceltext"] = Label(_("Cancel")) + self["restoretext"] = Label(_("Restore")) + self["restore"] = Pixmap() + self["cancel"] = Pixmap() + + self.sel = [] + self.val = [] + self.entry = False + self.exe = False + + self.path = "" + + self["actions"] = NumberActionMap(["SetupActions"], + { + "ok": self.KeyOk, + "cancel": self.keyCancel + }, -1) + + self["shortcuts"] = ActionMap(["ShortcutActions"], + { + "red": self.keyCancel, + "yellow": self.KeyOk, + }) + self.flist = [] + self["filelist"] = MenuList(self.flist) + self.fill_list() + self.onLayoutFinish.append(self.layoutFinished) + + def layoutFinished(self): + self.setWindowTitle() + + def setWindowTitle(self): + self.setTitle(_("Restore backups...")) + + + def fill_list(self): + self.flist = [] + self.path = getBackupPath() + if (path.exists(self.path) == False): + makedirs(self.path) + for file in listdir(self.path): + if (file.endswith(".tar.gz")): + self.flist.append((file)) + self.entry = True + self["filelist"].l.setList(self.flist) + + def KeyOk(self): + if (self.exe == False) and (self.entry == True): + self.sel = self["filelist"].getCurrent() + self.val = self.path + self.sel + self.session.openWithCallback(self.startRestore, MessageBox, _("Are you sure you want to restore\nfollowing backup:\n" + self.sel + "\nSystem will restart after the restore!")) + + def keyCancel(self): + self.close() + + def startRestore(self, ret = False): + if (ret == True): + self.exe = True + self.session.open(Console, title = _("Restore running"), cmdlist = ["tar -xzvf " + self.path + "/" + self.sel + " -C /", "killall -9 enigma2"]) + + def Exit(self): + self.close() + +class RestoreScreen(Screen, ConfigListScreen): + skin = """ + + + """ + + def __init__(self, session, runRestore = False): + Screen.__init__(self, session) + self.session = session + self.runRestore = runRestore + self["actions"] = ActionMap(["WizardActions", "DirectionActions"], + { + "ok": self.close, + "back": self.close, + "cancel": self.close, + }, -1) + self.finished_cb = None + self.backuppath = getBackupPath() + self.backupfile = getBackupFilename() + self.fullbackupfilename = self.backuppath + "/" + self.backupfile + self.list = [] + ConfigListScreen.__init__(self, self.list) + self.onLayoutFinish.append(self.layoutFinished) + if self.runRestore: + self.onShown.append(self.doRestore) + + def layoutFinished(self): + self.setWindowTitle() + + def setWindowTitle(self): + self.setTitle(_("Restore running...")) + + def doRestore(self): + if self.finished_cb: + self.session.openWithCallback(self.finished_cb, Console, title = _("Restore running"), cmdlist = ["tar -xzvf " + self.fullbackupfilename + " -C /", "killall -9 enigma2"]) + else: + self.session.open(Console, title = _("Restore running"), cmdlist = ["tar -xzvf " + self.fullbackupfilename + " -C /", "killall -9 enigma2"]) + + def backupFinishedCB(self,retval = None): + self.close(True) + + def backupErrorCB(self,retval = None): + self.close(False) + + def runAsync(self, finished_cb): + self.finished_cb = finished_cb + self.doRestore() + + \ No newline at end of file -- cgit v1.2.3 From da0da334b1314329d7d1f294d8df59acf66ac0d0 Mon Sep 17 00:00:00 2001 From: acid-burn Date: Fri, 13 Feb 2009 13:31:31 +0100 Subject: Remove double reboot question after upgrade small cleanups --- .../SystemPlugins/SoftwareManager/BackupRestore.py | 1 - .../SystemPlugins/SoftwareManager/plugin.py | 72 ++++++++-------------- 2 files changed, 25 insertions(+), 48 deletions(-) (limited to 'lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py') diff --git a/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py b/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py index f92472d3..947452e9 100755 --- a/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py +++ b/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py @@ -110,7 +110,6 @@ class BackupSelection(Screen): def __init__(self, session): Screen.__init__(self, session) - self.skin_path = plugin_path self["key_red"] = Label(_("Cancel")) self["key_green"] = Label(_("Save")) self["key_yellow"] = Label() diff --git a/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py b/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py index 1835a2ed..85d23284 100755 --- a/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py +++ b/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py @@ -79,7 +79,16 @@ class UpdatePluginMenu(Screen): } - + + + {"template": [ + MultiContentEntryText(pos = (2, 2), size = (230, 300), flags = RT_HALIGN_CENTER|RT_VALIGN_CENTER|RT_WRAP, text = 2), # index 0 is the MenuText, + ], + "fonts": [gFont("Regular", 20)], + "itemHeight": 230 + } + + """ def __init__(self, session, args = 0): @@ -105,8 +114,6 @@ class UpdatePluginMenu(Screen): self.list.append(("ipkg-source",_("Choose upgrade source"), _("\nEdit the upgrade source address." ) + self.oktext)) self["menu"] = List(self.list) - self["menu"].onSelectionChanged.append(self.selectionChanged) - self["description"] = Label() self["shortcuts"] = ActionMap(["ShortcutActions", "WizardActions"], { @@ -124,62 +131,38 @@ class UpdatePluginMenu(Screen): def layoutFinished(self): idx = 0 self["menu"].index = idx - self.loadDescription() def setWindowTitle(self): self.setTitle(_("Software manager...")) - def loadDescription(self): - if self["menu"].getCurrent()[0] == 'software-update': - self["description"].setText(self["menu"].getCurrent()[2] ) - if self["menu"].getCurrent()[0] == 'software-restore': - self["description"].setText(self["menu"].getCurrent()[2] ) - if self["menu"].getCurrent()[0] == 'ipkg-install': - self["description"].setText(self["menu"].getCurrent()[2] ) - if self["menu"].getCurrent()[0] == 'system-backup': - self["description"].setText(self["menu"].getCurrent()[2] ) - if self["menu"].getCurrent()[0] == 'system-restore': - self["description"].setText(self["menu"].getCurrent()[2] ) - if self["menu"].getCurrent()[0] == 'advanced': - self["description"].setText(self["menu"].getCurrent()[2] ) - if self["menu"].getCurrent()[0] == 'ipkg-source': - self["description"].setText(self["menu"].getCurrent()[2] ) - if self["menu"].getCurrent()[0] == 'ipkg-manager': - self["description"].setText(self["menu"].getCurrent()[2] ) - if self["menu"].getCurrent()[0] == 'advancedrestore': - self["description"].setText(self["menu"].getCurrent()[2] ) - if self["menu"].getCurrent()[0] == 'backuplocation': - self["description"].setText(self["menu"].getCurrent()[2] ) - if self["menu"].getCurrent()[0] == 'backupfiles': - self["description"].setText(self["menu"].getCurrent()[2] ) - def go(self): + current = self["menu"].getCurrent()[0] if self.menu == 0: - if (self["menu"].getCurrent()[0] == "software-restore"): + if (current == "software-restore"): self.session.open(ImageWizard) - if (self["menu"].getCurrent()[0] == "software-update"): + elif (current == "software-update"): self.session.openWithCallback(self.runUpgrade, MessageBox, _("Do you want to update your Dreambox?")+"\n"+_("\nAfter pressing OK, please wait!")) - if (self["menu"].getCurrent()[0] == "advanced"): + elif (current == "advanced"): self.session.open(UpdatePluginMenu, 1) - if (self["menu"].getCurrent()[0] == "system-backup"): + elif (current == "system-backup"): self.session.openWithCallback(self.backupDone,BackupScreen, runBackup = True) - if (self["menu"].getCurrent()[0] == "system-restore"): + elif (current == "system-restore"): if os_path.exists(self.fullbackupfilename): self.session.openWithCallback(self.startRestore, MessageBox, _("Are you sure you want to restore your Enigma2 backup?\nEnigma2 will restart after the restore")) else: self.session.open(MessageBox, _("Sorry no backups found!"), MessageBox.TYPE_INFO) if self.menu == 1: - if (self["menu"].getCurrent()[0] == "ipkg-manager"): + if (current == "ipkg-manager"): self.session.open(PacketManager, self.skin_path) - if (self["menu"].getCurrent()[0] == "ipkg-source"): + elif (current == "ipkg-source"): self.session.open(IPKGSource) - if (self["menu"].getCurrent()[0] == "ipkg-install"): + elif (current == "ipkg-install"): try: from Plugins.Extensions.MediaScanner.plugin import main main(self.session) except: self.session.open(MessageBox, _("Sorry MediaScanner is not installed!"), MessageBox.TYPE_INFO) - if (self["menu"].getCurrent()[0] == "backuplocation"): + elif (current == "backuplocation"): parts = [ (r.description, r.mountpoint, self.session) for r in harddiskmanager.getMountedPartitions(onlyhotplug = False)] for x in parts: if not access(x[1], F_OK|R_OK|W_OK) or x[1] == '/': @@ -189,17 +172,13 @@ class UpdatePluginMenu(Screen): parts.remove(x) if len(parts): self.session.openWithCallback(self.backuplocation_choosen, ChoiceBox, title = _("Please select medium to use as backup location"), list = parts) - if (self["menu"].getCurrent()[0] == "backupfiles"): + elif (current == "backupfiles"): self.session.openWithCallback(self.backupfiles_choosen,BackupSelection) - if (self["menu"].getCurrent()[0] == "advancedrestore"): + elif (current == "advancedrestore"): self.session.open(RestoreMenu, self.skin_path) - def selectionChanged(self): - self.loadDescription() - def backupfiles_choosen(self, ret): self.backupdirs = ' '.join( config.plugins.configurationbackup.backupdirs.value ) - self.loadDescription() def backuplocation_choosen(self, option): if option is not None: @@ -208,20 +187,19 @@ class UpdatePluginMenu(Screen): config.plugins.configurationbackup.save() config.save() self.createBackupfolders() - self.loadDescription() def runUpgrade(self, result): if result: - self.session.openWithCallback(self.runFinished,UpdatePlugin, self.skin_path) + self.session.open(UpdatePlugin, self.skin_path) - def runFinished(self): + """def runFinished(self): self.session.openWithCallback(self.reboot, MessageBox, _("Upgrade finished.") +" "+_("Do you want to reboot your Dreambox?"), MessageBox.TYPE_YESNO) def reboot(self, result): if result is None: return if result: - quitMainloop(3) + quitMainloop(3)""" def createBackupfolders(self): print "Creating backup folder if not already there..." -- cgit v1.2.3