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"
35 class BackupSetup(Screen):
37 <screen position="100,100" size="400,400" title="Backup and Restore" >
38 <widget name="config" position="5,10" size="380,350" />
39 <widget name="ok" position="10,365" size="53,30" pixmap="~/green.png" />
40 <widget name="oktext" position="10,365" size="53,30" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" foregroundColor="black" />
41 <widget name="cancel" position="73,365" size="100,30" pixmap="~/red.png" />
42 <widget name="canceltext" position="73,365" size="100,30" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" foregroundColor="black" />
43 <widget name="restore" position="183,365" size="100,30" pixmap="~/yellow.png" />
44 <widget name="restoretext" position="183,365" size="100,30" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" foregroundColor="black" />
45 <widget name="backup" position="293,365" size="100,30" pixmap="~/blue.png" />
46 <widget name="backuptext" position="293,365" size="100,30" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" foregroundColor="black" />
50 self["config"].handleKey(config.key["prevElement"])
53 self["config"].handleKey(config.key["nextElement"])
55 def keyNumberGlobal(self, number):
56 print "You pressed number " + str(number)
57 if (self["config"].getCurrent()[1].parent.enabled == True):
58 self["config"].handleKey(config.key[str(number)])
61 for x in self["config"].list:
66 for x in self["config"].list:
70 def __init__(self, session, args = None):
71 Screen.__init__(self, session)
72 self.skin_path = plugin_path
74 self["oktext"] = Label(_("OK"))
75 self["canceltext"] = Label(_("Cancel"))
76 self["backuptext"] = Label(_("Backup"))
77 self["restoretext"] = Label(_("Restore"))
78 self["restore"] = Pixmap()
79 self["backup"] = Pixmap()
81 self["cancel"] = Pixmap()
85 self["config"] = ConfigList(self.list)
88 self["actions"] = NumberActionMap(["SetupActions"],
91 "cancel": self.keyCancel,
93 "right": self.keyRight
96 self["shortcuts"] = ActionMap(["ShortcutActions"],
98 "red": self.keyCancel,
99 "green": self.keySave,
101 "yellow": self.Restore,
105 def createSetup(self):
106 print "Creating BackupSetup"
108 self["config"] = ConfigList(self.list)
109 config.backup = ConfigSubsection()
110 config.backup.type = configElement("config.backup.type", configSelection, 0, (("full", _("full /etc directory")), ("settings", _("only /etc/enigma2 directory")), ("var", _("/var directory")), ("skin", _("/usr/share/enigma2 directory"))))
111 config.backup.location = configElement("config.backup.location", configSelection, 0, (("usb", _("USB Stick")), ("cf", _("CF Drive")), ("hdd", _("Harddisk"))))
112 self.list.append(getConfigListEntry(_("Backup Mode"), config.backup.type))
113 self.list.append(getConfigListEntry(_("Backup Location"), config.backup.location))
115 def createBackupfolders(self):
116 self.path = BackupPath[str(currentConfigSelectionElement(config.backup.location))]
117 print "Creating Backup Folder if not already there..."
118 if (os.path.exists(str(self.path)) == False):
119 os.makedirs(str(self.path))
122 print "this will start the backup now!"
123 self.session.openWithCallback(self.runBackup, MessageBox, _("Do you want to backup now?\nAfter pressing OK, please wait!"))
126 print "this will start the restore now!"
127 self.session.open(RestoreMenu)
129 def runBackup(self, result):
131 if os.path.ismount(MountPoints[str(currentConfigSelectionElement(config.backup.location))]):
132 self.createBackupfolders()
134 dt = datetime.date(d.tm_year, d.tm_mon, d.tm_mday)
135 self.path = BackupPath[str(currentConfigSelectionElement(config.backup.location))]
136 if currentConfigSelectionElement(config.backup.type) == "full":
137 print "Backup Mode: Full"
138 self.session.open(Console, title = "Backup running", cmdlist = ["tar -czvf " + self.path + "/" + str(dt) + "_full_backup.tar.gz /etc/"])
139 if currentConfigSelectionElement(config.backup.type) == "settings":
140 print "Backup Mode: Settings"
141 self.session.open(Console, title = "Backup running", cmdlist = ["tar -czvf " + self.path + "/" + str(dt) + "_settings_backup.tar.gz /etc/enigma2/"])
142 if currentConfigSelectionElement(config.backup.type) == "var":
143 print "Backup Mode: var"
144 self.session.open(Console, title = "Backup running", cmdlist = [ "tar -czvf " + self.path + "/" + str(dt) + "_var_backup.tar.gz /var/"])
145 if currentConfigSelectionElement(config.backup.type) == "skin":
146 print "Backup Mode: skin"
147 self.session.open(Console, title ="Backup running", cmdlist = [ "tar -czvf " + self.path + "/" + str(dt) + "_skin_backup.tar.gz /usr/share/enigma2/"])
149 self.session.open(MessageBox, _("Sorry your Backup destination does not exist\n\nPlease choose an other one."), MessageBox.TYPE_INFO)
151 class RestoreMenu(Screen):
153 <screen position="100,100" size="400,400" title="Restore Backups" >
154 <widget name="filelist" position="5,10" size="380,350" scrollbarMode="showOnDemand" />
155 <widget name="cancel" position="73,365" size="100,30" pixmap="~/red.png" />
156 <widget name="canceltext" position="73,365" size="100,30" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" foregroundColor="black" />
157 <widget name="restore" position="183,365" size="100,30" pixmap="~/yellow.png" />
158 <widget name="restoretext" position="183,365" size="100,30" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" foregroundColor="black" />
161 def __init__(self, session, args = None):
162 Screen.__init__(self, session)
163 self.skin_path = plugin_path
165 self["canceltext"] = Label(_("Cancel"))
166 self["restoretext"] = Label(_("Restore"))
167 self["restore"] = Pixmap()
168 self["cancel"] = Pixmap()
177 self["actions"] = NumberActionMap(["SetupActions"],
180 "cancel": self.keyCancel
183 self["shortcuts"] = ActionMap(["ShortcutActions"],
185 "red": self.keyCancel,
186 "yellow": self.KeyOk,
189 self["filelist"] = MenuList(self.flist)
195 self.path = BackupPath[str(currentConfigSelectionElement(config.backup.location))]
196 if (os.path.exists(str(self.path)) == False):
197 os.makedirs(str(self.path))
198 for file in os.listdir(str(self.path)):
199 if (file.endswith(".tar.gz")):
200 self.flist.append((file))
202 self["filelist"].l.setList(self.flist)
205 if (self.exe == False) and (self.entry == True):
206 self.sel = self["filelist"].getCurrent()
207 self.val = self.path + self.sel
208 self.session.openWithCallback(self.startRestore, MessageBox, _("are you sure you want to restore\nfollowing backup:\n" + self.sel + "\nEnigma2 will restart after the restore"))
213 def startRestore(self, ret = False):
216 self.session.open(Console, title = "Restore running", cmdlist = ["tar -xzvf " + self.path + "/" + self.sel + " -C /", "killall enigma2"])
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)