2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4 from Screens.Console import Console
5 from Components.ActionMap import ActionMap, NumberActionMap
6 from Components.Pixmap import *
7 from Components.Pixmap import Pixmap
8 from Components.Label import Label
9 from Components.MenuList import MenuList
10 from Components.config import config, configSelection, configSelection, getConfigListEntry, configElement, ConfigSubsection, currentConfigSelectionElement
11 from Components.ConfigList import ConfigList
12 from Plugins.Plugin import PluginDescriptor
14 from Tools.NumericalTextInput import *
15 from Tools.Directories import *
24 "hdd" : "/media/hdd/backup",
25 "usb" : "/media/usb/backup",
26 "cf" : "/media/cf/backup"
29 class BackupSetup(Screen):
31 <screen position="100,100" size="400,400" title="Backup and Restore" >
32 <widget name="config" position="5,10" size="380,350" />
33 <widget name="ok" position="10,365" size="53,30" pixmap="~/green.png" />
34 <widget name="oktext" position="10,365" size="53,30" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" foregroundColor="black" />
35 <widget name="cancel" position="73,365" size="100,30" pixmap="~/red.png" />
36 <widget name="canceltext" position="73,365" size="100,30" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" foregroundColor="black" />
37 <widget name="restore" position="183,365" size="100,30" pixmap="~/yellow.png" />
38 <widget name="restoretext" position="183,365" size="100,30" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" foregroundColor="black" />
39 <widget name="backup" position="293,365" size="100,30" pixmap="~/blue.png" />
40 <widget name="backuptext" position="293,365" size="100,30" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" foregroundColor="black" />
44 self["config"].handleKey(config.key["prevElement"])
47 self["config"].handleKey(config.key["nextElement"])
49 def keyNumberGlobal(self, number):
50 print "You pressed number " + str(number)
51 if (self["config"].getCurrent()[1].parent.enabled == True):
52 self["config"].handleKey(config.key[str(number)])
55 for x in self["config"].list:
60 for x in self["config"].list:
64 def __init__(self, session, args = None):
65 Screen.__init__(self, session)
66 self.skin_path = plugin_path
68 self["oktext"] = Label(_("OK"))
69 self["canceltext"] = Label(_("Cancel"))
70 self["backuptext"] = Label(_("Backup"))
71 self["restoretext"] = Label(_("Restore"))
72 self["restore"] = Pixmap()
73 self["backup"] = Pixmap()
75 self["cancel"] = Pixmap()
79 self["config"] = ConfigList(self.list)
82 self["actions"] = NumberActionMap(["SetupActions"],
85 "cancel": self.keyCancel,
87 "right": self.keyRight
90 self["shortcuts"] = ActionMap(["ShortcutActions"],
92 "red": self.keyCancel,
93 "green": self.keySave,
95 "yellow": self.Restore,
99 def createSetup(self):
100 print "Creating BackupSetup"
102 self["config"] = ConfigList(self.list)
103 config.backup = ConfigSubsection()
104 config.backup.type = configElement("config.backup.type", configSelection, 0, (("full", _("full /etc directory")), ("settings", _("only /etc/enigma2 directory")), ("var", _("/var directory"))))
105 config.backup.location = configElement("config.backup.location", configSelection, 0, (("usb", _("USB Stick")), ("cf", _("CF Drive")), ("hdd", _("Harddisk"))))
106 self.list.append(getConfigListEntry(_("Backup Mode"), config.backup.type))
107 self.list.append(getConfigListEntry(_("Backup Location"), config.backup.location))
110 def createBackupfolders(self):
111 self.path = BackupPath[str(currentConfigSelectionElement(config.backup.location))]
112 print "BackupPath: ", str(self.path)
113 print "Creating Backup Folder if not already there..."
114 cmd = "[ ! -e " + self.path + " ] && mkdir " + self.path
115 print "Commandstring: " + str(cmd)
119 print "this will start the backup now!"
120 self.session.openWithCallback(self.runBackup, MessageBox, _("Do you want to backup now?\nAfter pressing OK, please wait!"))
123 print "this will start the restore now!"
124 self.session.open(RestoreMenu)
126 def runBackup(self, result):
128 self.createBackupfolders()
130 dt = datetime.date(d.tm_year, d.tm_mon, d.tm_mday)
131 print "Backup Time: " + str(dt)
132 self.path = BackupPath[str(currentConfigSelectionElement(config.backup.location))]
133 print "BackupPath: ", str(self.path)
134 if currentConfigSelectionElement(config.backup.type) == "full":
135 print "Backup Mode: Full"
136 self.session.open(Console, ["Backup running", "tar -czvf " + self.path + "/" + str(dt) + "_full_backup.tar.gz /etc/"])
137 if currentConfigSelectionElement(config.backup.type) == "settings":
138 print "Backup Mode: Settings"
139 self.session.open(Console, ["Backup running", "tar -czvf " + self.path + "/" + str(dt) + "_settings_backup.tar.gz /etc/enigma2/"])
140 if currentConfigSelectionElement(config.backup.type) == "var":
141 print "Backup Mode: var"
142 self.session.open(Console, ["Backup running", "tar -czvf " + self.path + "/" + str(dt) + "_var_backup.tar.gz /var/"])
145 class RestoreMenu(Screen):
147 <screen position="100,100" size="400,400" title="Restore Backups" >
148 <widget name="filelist" position="5,10" size="380,350" scrollbarMode="showOnDemand" />
149 <widget name="cancel" position="73,365" size="100,30" pixmap="~/red.png" />
150 <widget name="canceltext" position="73,365" size="100,30" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" foregroundColor="black" />
151 <widget name="restore" position="183,365" size="100,30" pixmap="~/yellow.png" />
152 <widget name="restoretext" position="183,365" size="100,30" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" foregroundColor="black" />
153 <widget name="text0" position="0,270" size="350,20" font="Regular;20" />
156 def __init__(self, session, args = None):
157 Screen.__init__(self, session)
158 self.skin_path = plugin_path
160 self['text0'] = Label("")
161 self["canceltext"] = Label(_("Cancel"))
162 self["restoretext"] = Label(_("Restore"))
163 self["restore"] = Pixmap()
164 self["cancel"] = Pixmap()
173 self["actions"] = NumberActionMap(["SetupActions"],
176 "cancel": self.keyCancel
179 self["shortcuts"] = ActionMap(["ShortcutActions"],
181 "red": self.keyCancel,
182 "yellow": self.KeyOk,
185 self["filelist"] = MenuList(self.flist)
190 self.path = BackupPath[str(currentConfigSelectionElement(config.backup.location))]
191 print "BackupPath: ", str(self.path)
192 dir = os.listdir(self.path)
194 bla = string.find(x, ".tar.gz")
196 self.flist.append((x))
198 self["filelist"].l.setList(self.flist)
203 if (self.exe == False) and (self.entry == True):
204 self.sel = self["filelist"].getCurrent()
205 self.val = self.path + self.sel
206 self.session.openWithCallback(self.startRestore, MessageBox, _("are you sure you want to restore\nfollowing backup:\n\n") + self.sel)
211 def startRestore(self, ret = False):
214 self['text0'].setText(_('One moment please...'))
215 print "Restore Location: " + str(self.path)
216 self.session.open(Console, ["Restore running", "tar -xzvf " + self.path + "/" + self.sel + " -C /"])
221 def BackupMain(session, **kwargs):
222 session.open(BackupSetup)
224 def Plugins(path, **kwargs):
227 return PluginDescriptor(name="Backup/Restore", description="Backup and Restore your Settings", icon="backup.png", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=BackupMain)