add backup suite plugin.
[vuplus_dvbapp] / lib / python / Plugins / Extensions / BackupSuiteUSB / plugin.py
1 # for localized messages
2 from . import _
3 from Plugins.Plugin import PluginDescriptor
4 from Screens.Console import Console
5 from Screens.MessageBox import MessageBox 
6 from Components.Language import language
7 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_LANGUAGE
8 from os import environ as os_environ
9 import gettext
10
11 def localeInit():
12         lang = language.getLanguage()[:2] # getLanguage returns e.g. "fi_FI" for "language_country"
13         os_environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it!
14         gettext.bindtextdomain("BackupSuite", resolveFilename(SCOPE_PLUGINS, "Extensions/BackupSuiteHDD/locale"))
15
16 def _(txt):
17         t = gettext.dgettext("BackupSuite", txt)
18         if t == txt:
19                 print "[BackupSuite] fallback to default translation for", txt
20                 t = gettext.gettext(txt)
21         return t
22
23 localeInit()
24 language.addCallback(localeInit)
25
26
27 def runbackup(session, result):
28         if result:
29                 session.open(Console, title = _("Full back-up to USB"), cmdlist = [_("sh '/usr/lib/enigma2/python/Plugins/Extensions/BackupSuiteUSB/backup.sh' en_EN")])
30
31
32 def main(session, **kwargs):
33         session.openWithCallback(lambda r: runbackup(session, r), MessageBox, _("Do you want to make a back-up on USB?\n\nThis only takes a few minutes depending on the used filesystem and is fully automatic.\n\nMake sure you first insert an USB flash drive before you select Yes.") , MessageBox.TYPE_YESNO, timeout = 20, default = True)
34
35 def Plugins(**kwargs):
36         return [PluginDescriptor(name=_("Full back-up to USB"), 
37                         description = _("Full 1:1 back-up direct on USB"), 
38                         where = PluginDescriptor.WHERE_PLUGINMENU, 
39                         fnc = main, 
40                         icon="plugin.png")]