1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Screens.Console import Console
4 from Components.ActionMap import ActionMap, NumberActionMap
5 from Components.Pixmap import Pixmap
6 from Components.Label import Label
7 from Components.MenuList import MenuList
8 from Components.config import getConfigListEntry, configfile, ConfigSelection, ConfigSubsection, ConfigText, ConfigLocations
9 from Components.config import config
10 from Components.ConfigList import ConfigList,ConfigListScreen
11 from Components.FileList import MultiFileSelectList
12 from Plugins.Plugin import PluginDescriptor
13 from enigma import eTimer
14 from Tools.Directories import *
15 from os import popen, path, makedirs, listdir, access, stat, rename, remove, W_OK, R_OK
16 from time import gmtime, strftime, localtime
17 from datetime import date
20 config.plugins.configurationbackup = ConfigSubsection()
21 config.plugins.configurationbackup.backuplocation = ConfigText(default = '/media/hdd/', visible_width = 50, fixed_size = False)
22 config.plugins.configurationbackup.backupdirs = ConfigLocations(default=['/etc/enigma2/', '/etc/network/interfaces', '/etc/wpa_supplicant.conf'])
25 backuppath = config.plugins.configurationbackup.backuplocation.value
26 if backuppath.endswith('/'):
27 return backuppath + 'backup'
29 return backuppath + '/backup'
31 def getBackupFilename():
32 return "enigma2settingsbackup.tar.gz"
35 class BackupScreen(Screen, ConfigListScreen):
37 <screen position="135,144" size="350,310" title="Backup running..." >
38 <widget name="config" position="10,10" size="330,250" transparent="1" scrollbarMode="showOnDemand" />
41 def __init__(self, session, runBackup = False):
42 Screen.__init__(self, session)
43 self.session = session
44 self.runBackup = runBackup
45 self["actions"] = ActionMap(["WizardActions", "DirectionActions"],
51 self.finished_cb = None
52 self.backuppath = getBackupPath()
53 self.backupfile = getBackupFilename()
54 self.fullbackupfilename = self.backuppath + "/" + self.backupfile
56 ConfigListScreen.__init__(self, self.list)
57 self.onLayoutFinish.append(self.layoutFinished)
59 self.onShown.append(self.doBackup)
61 def layoutFinished(self):
64 def setWindowTitle(self):
65 self.setTitle(_("Backup running..."))
69 if (path.exists(self.backuppath) == False):
70 makedirs(self.backuppath)
71 self.backupdirs = ' '.join( config.plugins.configurationbackup.backupdirs.value )
72 if path.exists(self.fullbackupfilename):
73 dt = str(date.fromtimestamp(stat(self.fullbackupfilename).st_ctime))
74 self.newfilename = self.backuppath + "/" + dt + '-' + self.backupfile
75 if path.exists(self.newfilename):
76 remove(self.newfilename)
77 rename(self.fullbackupfilename,self.newfilename)
79 self.session.openWithCallback(self.finished_cb, Console, title = _("Backup running"), cmdlist = ["tar -czvf " + self.fullbackupfilename + " " + self.backupdirs],finishedCallback = self.backupFinishedCB,closeOnSuccess = True)
81 self.session.open(Console, title = _("Backup running"), cmdlist = ["tar -czvf " + self.fullbackupfilename + " " + self.backupdirs],finishedCallback = self.backupFinishedCB, closeOnSuccess = True)
84 self.session.openWithCallback(self.finished_cb, MessageBox, _("Sorry your backup destination is not writeable.\nPlease choose an other one."), MessageBox.TYPE_INFO)
86 self.session.openWithCallback(self.backupErrorCB,MessageBox, _("Sorry your backup destination is not writeable.\nPlease choose an other one."), MessageBox.TYPE_INFO)
88 def backupFinishedCB(self,retval = None):
91 def backupErrorCB(self,retval = None):
94 def runAsync(self, finished_cb):
95 self.finished_cb = finished_cb
99 class BackupSelection(Screen):
101 <screen position="135,125" size="450,310" title="Select files/folders to backup...">
102 <widget name="checkList" position="10,10" size="430,250" transparent="1" scrollbarMode="showOnDemand" />
103 <ePixmap position="0,265" zPosition="1" size="135,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
104 <widget name="key_red" position="0,265" zPosition="2" size="135,40" halign="center" valign="center" font="Regular;22" transparent="1" shadowColor="black" shadowOffset="-1,-1" />
105 <ePixmap position="135,265" zPosition="1" size="135,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
106 <widget name="key_green" position="135,265" zPosition="2" size="135,40" halign="center" valign="center" font="Regular;22" transparent="1" shadowColor="black" shadowOffset="-1,-1" />
107 <ePixmap position="270,265" zPosition="1" size="135,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
108 <widget name="key_yellow" position="270,265" zPosition="2" size="135,40" halign="center" valign="center" font="Regular;22" transparent="1" shadowColor="black" shadowOffset="-1,-1" />
111 def __init__(self, session):
112 Screen.__init__(self, session)
113 self["key_red"] = Label(_("Cancel"))
114 self["key_green"] = Label(_("Save"))
115 self["key_yellow"] = Label()
117 self.selectedFiles = config.plugins.configurationbackup.backupdirs.value
119 inhibitDirs = ["/bin", "/boot", "/dev", "/autofs", "/lib", "/proc", "/sbin", "/sys", "/hdd", "/tmp", "/mnt", "/media"]
120 self.filelist = MultiFileSelectList(self.selectedFiles, defaultDir, inhibitDirs = inhibitDirs )
121 self["checkList"] = self.filelist
123 self["actions"] = ActionMap(["DirectionActions", "OkCancelActions", "ShortcutActions"],
127 "yellow": self.changeSelectionState,
128 "green": self.saveSelection,
129 "ok": self.okClicked,
135 if not self.selectionChanged in self["checkList"].onSelectionChanged:
136 self["checkList"].onSelectionChanged.append(self.selectionChanged)
137 self.onLayoutFinish.append(self.layoutFinished)
139 def layoutFinished(self):
141 self["checkList"].moveToIndex(idx)
142 self.setWindowTitle()
143 self.selectionChanged()
145 def setWindowTitle(self):
146 self.setTitle(_("Select files/folders to backup..."))
148 def selectionChanged(self):
149 current = self["checkList"].getCurrent()[0]
150 if current[2] is True:
151 self["key_yellow"].setText(_("Deselect"))
153 self["key_yellow"].setText(_("Select"))
156 self["checkList"].up()
159 self["checkList"].down()
162 self["checkList"].pageUp()
165 self["checkList"].pageDown()
167 def changeSelectionState(self):
168 self["checkList"].changeSelectionState()
169 self.selectedFiles = self["checkList"].getSelectedList()
171 def saveSelection(self):
172 self.selectedFiles = self["checkList"].getSelectedList()
173 config.plugins.configurationbackup.backupdirs.value = self.selectedFiles
174 config.plugins.configurationbackup.backupdirs.save()
175 config.plugins.configurationbackup.save()
183 if self.filelist.canDescent():
184 self.filelist.descent()
187 class RestoreMenu(Screen):
189 <screen position="135,144" size="450,300" title="Restore backups..." >
190 <widget name="filelist" position="10,10" size="430,240" scrollbarMode="showOnDemand" />
191 <widget name="cancel" position="120,255" size="100,40" pixmap="~/red.png" transparent="1" alphatest="on" />
192 <widget name="canceltext" position="0,0" size="0,0" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" foregroundColor="black" />
193 <widget name="restore" position="230,255" size="100,40" pixmap="~/yellow.png" transparent="1" alphatest="on" />
194 <widget name="restoretext" position="0,0" size="0,0" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" foregroundColor="black" />
197 def __init__(self, session, plugin_path):
198 Screen.__init__(self, session)
199 self.skin_path = plugin_path
201 self["canceltext"] = Label(_("Cancel"))
202 self["restoretext"] = Label(_("Restore"))
203 self["restore"] = Pixmap()
204 self["cancel"] = Pixmap()
213 self["actions"] = NumberActionMap(["SetupActions"],
216 "cancel": self.keyCancel
219 self["shortcuts"] = ActionMap(["ShortcutActions"],
221 "red": self.keyCancel,
222 "yellow": self.KeyOk,
225 self["filelist"] = MenuList(self.flist)
227 self.onLayoutFinish.append(self.layoutFinished)
229 def layoutFinished(self):
230 self.setWindowTitle()
232 def setWindowTitle(self):
233 self.setTitle(_("Restore backups..."))
238 self.path = getBackupPath()
239 if (path.exists(self.path) == False):
241 for file in listdir(self.path):
242 if (file.endswith(".tar.gz")):
243 self.flist.append((file))
245 self["filelist"].l.setList(self.flist)
248 if (self.exe == False) and (self.entry == True):
249 self.sel = self["filelist"].getCurrent()
250 self.val = self.path + self.sel
251 self.session.openWithCallback(self.startRestore, MessageBox, _("Are you sure you want to restore\nfollowing backup:\n" + self.sel + "\nSystem will restart after the restore!"))
256 def startRestore(self, ret = False):
259 self.session.open(Console, title = _("Restore running"), cmdlist = ["tar -xzvf " + self.path + "/" + self.sel + " -C /", "killall -9 enigma2"])
264 class RestoreScreen(Screen, ConfigListScreen):
266 <screen position="135,144" size="350,310" title="Restore running..." >
267 <widget name="config" position="10,10" size="330,250" transparent="1" scrollbarMode="showOnDemand" />
270 def __init__(self, session, runRestore = False):
271 Screen.__init__(self, session)
272 self.session = session
273 self.runRestore = runRestore
274 self["actions"] = ActionMap(["WizardActions", "DirectionActions"],
278 "cancel": self.close,
280 self.finished_cb = None
281 self.backuppath = getBackupPath()
282 self.backupfile = getBackupFilename()
283 self.fullbackupfilename = self.backuppath + "/" + self.backupfile
285 ConfigListScreen.__init__(self, self.list)
286 self.onLayoutFinish.append(self.layoutFinished)
288 self.onShown.append(self.doRestore)
290 def layoutFinished(self):
291 self.setWindowTitle()
293 def setWindowTitle(self):
294 self.setTitle(_("Restore running..."))
298 self.session.openWithCallback(self.finished_cb, Console, title = _("Restore running"), cmdlist = ["tar -xzvf " + self.fullbackupfilename + " -C /", "killall -9 enigma2"])
300 self.session.open(Console, title = _("Restore running"), cmdlist = ["tar -xzvf " + self.fullbackupfilename + " -C /", "killall -9 enigma2"])
302 def backupFinishedCB(self,retval = None):
305 def backupErrorCB(self,retval = None):
308 def runAsync(self, finished_cb):
309 self.finished_cb = finished_cb