Repository URL to install this package:
|
Version:
5.0-r2 ▾
|
enigma2-plugin-extensions-dbackup
/
usr
/
lib
/
enigma2
/
python
/
Plugins
/
Extensions
/
dBackup
/
plugin.py
|
|---|
# -*- coding: UTF-8 -*-
from __future__ import print_function
from __future__ import division
#
# dBackup3 Plugin by gutemine
#
from Components.ActionMap import ActionMap, HelpableActionMap
from Components.Label import Label
from Components.config import config, configfile, ConfigSubsection, ConfigText, ConfigBoolean, ConfigInteger, ConfigSelectionNumber, ConfigSelection, getConfigListEntry, ConfigSlider
from Components.ConfigList import ConfigListScreen
from Screens.HelpMenu import HelpableScreen
from Plugins.Plugin import PluginDescriptor
from Tools.Notifications import AddNotification
from Components.Pixmap import Pixmap
from Screens.Screen import Screen
from Screens.MessageBox import MessageBox
from Screens.InputBox import InputBox
from Components.Input import Input
from Screens.ChoiceBox import ChoiceBox
from Components.AVSwitch import AVSwitch
from Components.SystemInfo import SystemInfo
from Screens.Console import Console
from Components.MenuList import MenuList
from Components.Slider import Slider
from Components.Sources.Clock import Clock
from Components.Sources.StaticText import StaticText
from enigma import ePoint, eLCD, fbClass, eRCInput, eDBoxLCD, getDesktop, quitMainloop, eConsoleAppContainer, eDVBVolumecontrol, eTimer, eActionMap, eBackgroundFileEraser
from Tools.LoadPixmap import LoadPixmap
from shutil import rmtree as rmtree
import Screens.Standby
import sys
import struct
import stat
import time
from os import path as os_path, remove as os_remove, rmdir as os_rmdir, rename as os_rename, symlink as os_symlink, mkdir as os_mkdir, statvfs as os_statvfs
from twisted.web import resource, http
import gettext
import datetime
import shutil
import gm
from glob import glob
dbackup_version = gm.version()
dbackup_plugindir = "/usr/lib/enigma2/python/Plugins/Extensions/dBackup"
dbackup_busy = "/tmp/gm"
dbackup_boottmp="/tmp/boottmp.txt"
# add local language file
dbackup_sp = config.osd.language.value.split("_")
dbackup_language = dbackup_sp[0]
if os_path.exists("%s/locale/%s" % (dbackup_plugindir, dbackup_language)):
_ = gettext.Catalog("dbackup", "%s/locale" % dbackup_plugindir, dbackup_sp).gettext
yes_no_descriptions = {False: _("no"), True: _("yes")}
try:
from enigma import IntList
osd_alpha_range = IntList()
except:
config.av.osd_alpha = ConfigSlider(default=240, increment=12, limits=(0, 240))
config.plugins.dbackup = ConfigSubsection()
if os_path.exists("/media/hdd/backup"):
config.plugins.dbackup.backuplocation = ConfigText(
default="/media/hdd/backup", fixed_size=True, visible_width=20
)
else:
config.plugins.dbackup.backuplocation = ConfigText(
default="/data/backup", fixed_size=True, visible_width=25
)
config.plugins.dbackup.maxlen = ConfigSelectionNumber(32, 64, 1, default=36)
ok_text = _("Please press OK to continue.").rstrip(".")
tar_options = []
tar_options.append(("tar", ok_text))
config.plugins.dbackup.tar = ConfigSelection(default="tar", choices=tar_options)
xz_options = []
xz_options.append(("xz", ok_text))
config.plugins.dbackup.xz = ConfigSelection(default="xz", choices=xz_options)
pigz_options = []
pigz_options.append(("pigz", ok_text))
config.plugins.dbackup.pigz = ConfigSelection(default="pigz", choices=pigz_options)
pixz_options = []
pixz_options.append(("pixz", ok_text))
config.plugins.dbackup.pixz = ConfigSelection(default="pixz", choices=pixz_options)
pbzip2_options = []
pbzip2_options.append(("pbzip2", ok_text))
config.plugins.dbackup.pbzip2 = ConfigSelection(
default="pbzip2", choices=pbzip2_options
)
config.plugins.uboot = ConfigSubsection()
uboot_options = []
uboot_options.append((_("ubootmenu"), ok_text))
config.plugins.uboot.menu = ConfigSelection(
default="ubootmenu", choices=uboot_options
)
config.plugins.uboot.timeout = ConfigSelectionNumber(-1, 30, 1, default=5)
config.plugins.uboot.naming = ConfigBoolean(
default=False, descriptions=yes_no_descriptions
)
# disabled until further notice !!!
#config.plugins.uboot.sdcard = ConfigBoolean(
# default=False, descriptions=yes_no_descriptions
#)
p = open("/proc/cmdline")
cmd = p.read()
p.close()
partitions = []
uboot_images = []
for x in range(0, 8):
part="/dev/mmcblk0p%d" % (x + 5)
partition = "/dev/mmcblk0p%d" % (x + 5)
if x == 0:
partlabel = "/dev/disk/by-partlabel/dreambox-rootfs"
else:
partlabel = "/dev/disk/by-partlabel/dreambox-rootfs%d" % x
# cprint(partition)
if os_path.exists(partlabel) and os_path.exists(partition):
if config.plugins.uboot.naming.value:
name = gm.getlabel(partition)
else:
name = "Dreambox Image %d" % x
if cmd.find(partition) == -1:
uboot_images.append((str(x), "[%s]" % partition, name))
else:
uboot_images.append((str(x), "@%s@" % partition, name))
config.plugins.uboot.image = ConfigSelection(
default="0", choices=uboot_images
)
config.plugins.uboot.details = ConfigBoolean(
default=False, descriptions=yes_no_descriptions
)
config.plugins.uboot.lock = ConfigBoolean(
default=False, descriptions=yes_no_descriptions
)
config.plugins.uboot.repeat = ConfigBoolean(
default=False, descriptions=yes_no_descriptions
)
font_options = []
font_options.append((_("1"), _("very small")))
font_options.append((_("2"), _("small")))
font_options.append((_("3"), _("normal")))
config.plugins.uboot.font = ConfigSelection(
default="3", choices=font_options
)
preview_options = []
preview_options.append((_("ubootpreview"), ok_text))
config.plugins.uboot.preview = ConfigSelection(
default="ubootpreview", choices=preview_options
)
# config.plugins.dbackup.dataerase = ConfigBoolean(default=False, descriptions=yes_no_descriptions)
config.plugins.dbackup.backupaskdir = ConfigBoolean(
default=True, descriptions=yes_no_descriptions
)
config.plugins.dbackup.backupsettings = ConfigBoolean(
default=False, descriptions=yes_no_descriptions
)
dbackup_visible=28
config.plugins.dbackup.delay = ConfigSelectionNumber(0, 60, 1, default=0)
config.plugins.dbackup.prefix = ConfigText(
default="dreambox ", fixed_size=True, visible_width=dbackup_visible
)
automatic_options = []
automatic_options.append(("idle", _("Idle")))
automatic_options.append(("boot", _("Startup")))
automatic_options.append(("message", _("Message")))
config.plugins.dbackup.automatic = ConfigSelection(
default="idle", choices=automatic_options
)
config.plugins.dbackup.lastbackup = ConfigInteger(default=0, limits=(0, 2000000000))
config.plugins.dbackup.cleanlastbackup = ConfigSelectionNumber(0, 100, 5, default=0)
days_options = []
days_options.append(("0", _("never")))
days_options.append(("8888", _("always")))
for days in range(1, 31):
days_options.append((str(days), str(days)))
config.plugins.dbackup.latestbackup = ConfigSelection(default="0", choices=days_options)
# config.plugins.dbackup.aptclean = ConfigBoolean(default = True, descriptions=yes_no_descriptions)
config.plugins.dbackup.epgdb = ConfigBoolean(
default=True, descriptions=yes_no_descriptions
)
config.plugins.dbackup.mediadb = ConfigBoolean(
default=True, descriptions=yes_no_descriptions
)
if os_path.exists("/var/lib/dpkg/status"):
config.plugins.dbackup.webinterface = ConfigBoolean(
default=True, descriptions=yes_no_descriptions
)
else:
config.plugins.dbackup.webinterface = ConfigBoolean(
default=False, descriptions=yes_no_descriptions
)
config.plugins.dbackup.settings = ConfigBoolean(
default=False, descriptions=yes_no_descriptions
)
config.plugins.dbackup.timers = ConfigBoolean(
default=False, descriptions=yes_no_descriptions
)
display_options = []
display_options.append(("clock", _("Clock")))
display_options.append(("dbackup", _("dBackup")))
display_options.append(("dreambox", _("Dreambox")))
display_options.append(("nothing", _("nothing")))
config.plugins.dbackup.displayentry = ConfigSelection(
default="clock", choices=display_options
)
config.plugins.dbackup.showinsettings = ConfigBoolean(
default=True, descriptions=yes_no_descriptions
)
config.plugins.dbackup.showinextensions = ConfigBoolean(
default=True, descriptions=yes_no_descriptions
)
config.plugins.dbackup.showinplugins = ConfigBoolean(
default=True, descriptions=yes_no_descriptions
)
dbackup_recovering = []
dbackup_recovering.append(("webif", _("Webinterface")))
dbackup_recovering.append(("factory", _("Factory reset")))
dbackup_recovering.append(("both", _("both")))
dbackup_recovering.append(("none", _("none")))
if os_path.exists("/var/lib/dpkg/status"):
config.plugins.dbackup.recovering = ConfigSelection(
default="both", choices=dbackup_recovering
)
else:
config.plugins.dbackup.recovering = ConfigSelection(
default="none", choices=dbackup_recovering
)
config.plugins.dbackup.transparency = ConfigSlider(
default=0, increment=5, limits=(0, 255)
)
backuptools = []
backuptools.append(("tar.gz", _("tar.gz")))
if os_path.exists("/usr/bin/xz"):
rp = os_path.realpath("/usr/bin/xz")
if not rp.startswith("/bin/busybox"):
backuptools.append(("tar.xz", _("tar.xz")))
if os_path.exists("/usr/bin/pbzip2"):
backuptools.append(("tar.bz2", _("tar.bz2")))
config.plugins.dbackup.backuptool = ConfigSelection(
default="tar.gz", choices=backuptools
)
s_options = []
s_options.append(("0", _("none")))
s_options.append(("1", "1"))
s_options.append(("2", "2"))
s_options.append(("3", "3"))
s_options.append(("4", "4"))
s_options.append(("5", "5"))
s_options.append(("6", "6"))
s_options.append(("7", "7"))
s_options.append(("8", "8"))
s_options.append(("10", "10"))
if os_path.exists("/var/lib/dpkg/status"):
config.plugins.dbackup.fadetime = ConfigSelection(default="5", choices=s_options)
else:
config.plugins.dbackup.fadetime = ConfigSelection(default="0", choices=s_options)
config.plugins.dbackup.overwrite = ConfigBoolean(
default=False, descriptions=yes_no_descriptions
)
fileupload_string = _("Select tar.* image for flashing")
partition_string = _("Select partition for flashing")
disclaimer_header = _("Disclaimer")
info_header = _("Info")
disclaimer_string = _(
"This way of flashing your Dreambox is not supported by DMM.\n\nYou are using it completely at you own risk!\nIf you want to flash your Dreambox safely use the Recovery Webinterface!\n\nMay the Power button be with you!"
)
disclaimer_wstring = disclaimer_string.replace("\n", "<br>")
plugin_string = _("Dreambox Backup Plugin by gutemine %s") % dbackup_version
if os_path.exists("/var/lib/dpkg/status"):
flashing_string = _("Flashing")
else:
flashing_string = "Flashing"
backup_string = _("Backup")
exit_string = _("Exit")
setup_string = _("Configuring")
running_string = _("dBackup is busy ...")
backupimage_string = _("Enter Backup Imagename")
backupdirectory_string = _("Enter Backup Path")
unsupported_string = _("Sorry, currently not supported on this Dreambox type")
notar_string = _("Sorry, no correct tar.*z file selected")
nopartition_string = _("Sorry, no partition selected")
nopz_string = _("Sorry, no pigz binary found")
nopixz_string = _("Sorry, no pixz binary found")
noxz_string = _("Sorry, no xz binary found")
nobz_string = _("Sorry, no pbzip2 binary found")
noboxtype_string = _("Sorry, no %s image") % gm.boxtype()
refresh_string = _("Refresh")
mounted_string = _("Nothing mounted at %s")
noflashing_string = _("Sorry, Flashing works only in Flash")
nowebif_string = _("Sorry, dBackup webinterface is currently disabled")
support_string = _("Kit of this Plugin from https://repo.fury.io/gm3/")
header_string = ""
header_string += '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'
header_string += '"http://www.w3.org/TR/html4/loose.dtd">'
header_string += "<head><title>%s</title>" % plugin_string
header_string += '<link rel="shortcut icon" type="/web-data/image/x-icon" href="/web-data/img/favicon.ico">'
header_string += '<meta content="text/html; charset=UTF-8" http-equiv="content-type">'
header_string += '</head><body bgcolor="black">'
header_string += '<font face="Tahoma, Arial, Helvetica" color="yellow">'
header_string += '<font size="3" color="yellow">'
dbackup_backbutton = _("use back button in browser and try again!")
dbackup_flashing = ""
dbackup_flashing += header_string
dbackup_flashing += "<br>%s ...<br><br>" % flashing_string
dbackup_flashing += (
'<br><img src="/web-data/img/dbackup.png" alt="%s ..."/><br><br>'
% (flashing_string)
)
dbackup_backuping = ""
dbackup_backuping += header_string
dbackup_backuping += "<br>%s<br><br>" % running_string
dbackup_backuping += '<br><img src="/web-data/img/ring.png" alt="%s ..."/><br><br>' % (
backup_string
)
dbackup_backuping += '<br><form method="GET">'
dbackup_backuping += (
'<input name="command" type="submit" size="100px" title="%s" value="%s">'
% (refresh_string, "Refresh")
)
dbackup_backuping += "</form>"
global dbackup_progress
dbackup_progress = "0"
global dbackup_configuring
dbackup_configuring = False
global dbackup_duration
dbackup_duration = 0
global dbackup_file
dbackup_file = None
YELLOWC = "\033[33m"
ENDC = "\033[m"
def cprint(text):
print(YELLOWC + "[dBACKUP] " + text + ENDC)
sz_w = getDesktop(0).size().width()
class dBackupSummary(Screen):
skin = (
"""<screen name="dBackupSummary" position="0,0" size="132,64" id="1">
<widget font="Display;12" halign="center" position="6,0" render="Label" size="120,12" source="titletext" valign="center"/>
<widget font="Display;12" halign="center" position="6,13" render="Label" size="120,12" source="duration" valign="center" />
<widget name="slider" position="6,26" size="120,8" borderWidth="1" borderColor="white" foregoundColor="white" transparent="1"/>
<widget font="Display;26" halign="center" position="6,35" render="Label" size="120,28" source="displayentry" foregroundColor="white" valign="center"/>
</screen>""",
"""<screen name="dBackupSummary" position="0,0" size="96,64" id="2">
<widget font="Display;15" halign="center" position="0,0" render="Label" size="96,30" source="titletext" transparent="1" valign="center" />
<widget backgroundColor="dark" borderWidth="1" position="0,34" size="96,8" name="slider" transparent="1" />
<widget font="Display;15" halign="center" position="0,46" render="Label" size="96,15" source="duration" transparent="1" valign="center" foregroundColor="yellow" />
</screen>""",
"""<screen name="dBackupSummary" position="0,0" size="400,240" id="3">
<ePixmap pixmap="skin_default/display_bg.png" position="0,0" size="400,240" zPosition="-1" />
<widget font="Display;48" halign="center" position="center,5" render="Label" size="380,100" source="titletext" transparent="1" valign="top" />
<widget font="Display;48" halign="center" position="center,60" render="Label" size="100,50" source="duration" transparent="1" valign="center" foregroundColor="yellow" />
<widget backgroundColor="dark" borderWidth="1" pixmap="skin_default/progress.png" position="center,112" size="380,15" name="slider" transparent="1" />
<widget font="Display;72" halign="center" position="center,140" render="Label" size="380,84" source="displayentry" transparent="1" foregroundColor="white" valign="center" />
</screen>""",
"""<screen name="dBackupSummary" position="0,0" size="240,86" id="100">
<widget font="Display;14" halign="center" position="12,0" render="Label" size="220,24" source="titletext" valign="center"/>
<widget font="Display;14" halign="center" position="12,16" render="Label" size="220,24" source="duration" valign="center" />
<widget name="slider" position="12,36" size="220,10" borderWidth="1" borderColor="white" foregoundColor="white" transparent="1"/>
<widget font="Display;28" halign="center" position="12,48" render="Label" size="220,32" source="displayentry" foregroundColor="white" valign="center"/>
</screen>""",
)
def __init__(self, session, parent):
Screen.__init__(self, session, parent=parent)
self.slider = Slider(0, 1024)
self["slider"] = self.slider
self["slider"].hide()
self.clock = Clock()
self.boxtype = gm.boxtype()
global dbackup_progress
dbackup_progress = "0"
# LCD skin
if config.plugins.dbackup.displayentry.value == "clock":
self["displayentry"] = StaticText(
time.strftime("%H:%M", time.localtime(self.clock.time))
)
elif config.plugins.dbackup.displayentry.value == "dbackup":
self["displayentry"] = StaticText(_("dBackup"))
elif config.plugins.dbackup.displayentry.value == "dreambox":
self["displayentry"] = StaticText(self.boxtype)
else:
self["displayentry"] = StaticText(" ")
self["titletext"] = StaticText(backup_string + " & " + flashing_string)
self["size"] = StaticText(" ")
self["duration"] = StaticText(" ")
self.onLayoutFinish.append(self.byLayoutEnd)
def byLayoutEnd(self):
global dbackup_progress
self.slider.setValue(int(dbackup_progress))
self.ClockTimer = eTimer()
if os_path.exists("/var/lib/dpkg/status"):
self.ClockTimer_conn = self.ClockTimer.timeout.connect(self.updateClock)
else:
self.ClockTimer.callback.append(self.updateClock)
if config.plugins.dbackup.displayentry.value == "clock":
self.ClockTimer.start(1000, True)
def updateClock(self):
if config.plugins.dbackup.displayentry.value == "clock":
self["displayentry"].setText(
time.strftime("%H:%M", time.localtime(self.clock.time))
)
self.ClockTimer.start(1000, True)
else:
self.ClockTimer.stop()
class dBackup(Screen, HelpableScreen):
if sz_w == 2560:
skin = """
<screen name="dBackup" position="center,240" size="1600,160" title="Flashing" >
<widget name="logo" position="20,10" size="200,80" />
<widget backgroundColor="#9f1313" font="Regular;38" halign="center" name="buttonred" position="240,10" foregroundColor="white" shadowColor="black" shadowOffset="-3,-3" size="300,80" valign="center" />
<widget backgroundColor="#1f771f" font="Regular;38" halign="center" name="buttongreen" position="560,10" foregroundColor="white" shadowColor="black" shadowOffset="-3,-3" size="300,80" valign="center" />
<widget backgroundColor="#a08500" font="Regular;38" halign="center" name="buttonyellow" position="880,10" foregroundColor="white" shadowColor="black" shadowOffset="-3,-3" size="300,80" valign="center" />
<widget backgroundColor="#18188b" font="Regular;38" halign="center" name="buttonblue" position="1200,10" foregroundColor="white" shadowColor="black" shadowOffset="-3,-3" size="300,80" valign="center" />
<widget name="info" position="1510,10" size="80,40" alphatest="on" />
<widget name="menu" position="1510,50" size="80,40" alphatest="on" />
<eLabel backgroundColor="grey" position="10,100" size="1580,2" />
<widget name="slider" position="120,124" size="1320,10"/>
<widget source="size" render="Label" size="100,60" position="10,100" font="Regular;28" halign="center" valign="center" />
<widget source="duration" render="Label" size="100,60" position="1506,100" font="Regular;28" halign="center" valign="center" />
</screen>"""
elif sz_w == 1920:
skin = """
<screen name="dBackup" position="center,170" size="1200,120" title="Flashing" >
<widget name="logo" position="20,10" size="150,60" />
<widget backgroundColor="#9f1313" font="Regular;30" halign="center" name="buttonred" position="180,10" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="225,60" valign="center" />
<widget backgroundColor="#1f771f" font="Regular;30" halign="center" name="buttongreen" position="425,10" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="225,60" valign="center" />
<widget backgroundColor="#a08500" font="Regular;30" halign="center" name="buttonyellow" position="660,10" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="225,60" valign="center" />
<widget backgroundColor="#18188b" font="Regular;30" halign="center" name="buttonblue" position="895,10" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="225,60" valign="center" />
<widget name="info" position="1125,10" size="60,30" alphatest="on" />
<widget name="menu" position="1125,40" size="60,30" alphatest="on" />
<eLabel backgroundColor="grey" position="10,80" size="1180,1" />
<widget name="slider" position="100,95" size="1000,10"/>
<widget source="size" render="Label" size="80,45" position="10,73" font="Regular;24" halign="center" valign="center" />
<widget source="duration" render="Label" size="80,45" position="1120,73" font="Regular;24" halign="center" valign="center" />
</screen>"""
else:
skin = """
<screen name="dBackup" position="center,120" size="800,80" title="Flashing" >
<widget name="logo" position="10,5" size="100,40" />
<widget backgroundColor="#9f1313" font="Regular;19" halign="center" name="buttonred" position="120,5" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="150,40" valign="center" />
<widget backgroundColor="#1f771f" font="Regular;19" halign="center" name="buttongreen" position="280,5" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="150,40" valign="center" />
<widget backgroundColor="#a08500" font="Regular;19" halign="center" name="buttonyellow" position="440,5" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="150,40" valign="center" />
<widget backgroundColor="#18188b" font="Regular;19" halign="center" name="buttonblue" position="600,5" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="150,40" valign="center" />
<widget name="info" position="755,5" size="40,20" alphatest="on" />
<widget name="menu" position="755,25" size="40,20" alphatest="on" />
<eLabel backgroundColor="grey" position="5,50" size="790,1" />
<widget name="slider" position="60,62" size="660,5"/>
<widget source="size" render="Label" size="50,30" position="5,50" font="Regular;14" halign="center" valign="center" />
<widget source="duration" render="Label" size="50,30" position="753,50" font="Regular;14" halign="center" valign="center" />
</screen>"""
def __init__(self, session, args=0):
Screen.__init__(self, session)
HelpableScreen.__init__(self)
self.skin = dBackup.skin
self.boxtype = gm.boxtype()
self.onShown.append(self.setWindowTitle)
self.onLayoutFinish.append(self.byLayoutEnd)
self["logo"] = Pixmap()
self["buttonred"] = Label(exit_string)
self["buttongreen"] = Label(backup_string)
self["buttonyellow"] = Label(flashing_string)
self["buttonblue"] = Label(_("Delete"))
self["menu"] = Pixmap()
self["info"] = Pixmap()
self.slider = Slider(0, 1024)
self["slider"] = self.slider
self["size"] = StaticText(" ")
self["duration"] = StaticText(" ")
global dbackup_progress
global dbackup_confguring
dbackup_configuring=False
global dbackup_duration
if dbackup_file == None:
dbackup_progress = "0"
dbackup_duration = 0
else:
dbackup_progress = gm.progress(dbackup_file)
dbackup_duration = gm.duration(dbackup_file)
self.maxlen = int(config.plugins.dbackup.maxlen.value)
self.dimmed = config.av.osd_alpha.value
self.onShow.append(self.connectHighPrioAction)
self.onHide.append(self.disconnectHighPrioAction)
self.TimerBackup = eTimer()
self.TimerBackup.stop()
if os_path.exists("/var/lib/dpkg/status"):
self.TimerBackup_conn = self.TimerBackup.timeout.connect(
self.backupFinishedCheck
)
else:
self.TimerBackup.callback.append(self.backupFinishedCheck)
self.TimerBackup.start(1000, True)
self.DimmingTimer = eTimer()
if os_path.exists("/var/lib/dpkg/status"):
self.DimmingTimer_conn = self.DimmingTimer.timeout.connect(self.doDimming)
else:
self.DimmingTimer.callback.append(self.doDimming)
self["ColorActions"] = HelpableActionMap(
self,
"ColorActions",
{
"green": (self.backup, backup_string),
"red": (self.leaving, exit_string),
"yellow": (self.flash, flashing_string),
"blue": (self.deleting, _("Delete") + " " + backup_string),
},
-5,
)
self["ChannelSelectEPGActions"] = HelpableActionMap(
self,
"ChannelSelectEPGActions",
{
"showEPGList": (self.lastbackup, _("Backup") + " " + _("Information")),
},
-4,
)
self["InfobarMenuActions"] = HelpableActionMap(
self,
"InfobarMenuActions",
{
"mainMenu": (self.config, _("Settings")),
},
-4,
)
self["SetupActions"] = HelpableActionMap(
self,
"SetupActions",
{
"cancel": (self.leaving, exit_string),
"ok": (self.okPressed, _("OK")),
"deleteForward": (self.deleting, _("Delete") + " " + backup_string),
"deleteBackward": (self.deleting, _("Delete") + " " + backup_string),
"menu": (self.config, _("Settings")),
},
-5,
)
#
# for new RC use Audio key as Help key alternative
#
self["InfobarAudioSelectionActions"] = HelpableActionMap(
self,
"InfobarAudioSelectionActions",
{
"audioSelection": (self.audioPressed, _("Help")),
},
-3,
)
def audioPressed(self):
cprint("AUDIO pressed")
# Device Types
TYPE_STANDARD = "dreambox remote control (native)"
TYPE_ADVANCED = "dreambox advanced remote control (native)"
TYPE_KEYBOARD = "dreambox ir keyboard"
# Advanced remote or standard?
if config.misc.rcused.value == 0:
self.remotetype = TYPE_ADVANCED
else:
self.remotetype = TYPE_STANDARD
self.eam = eActionMap.getInstance()
# press the key with the desired flag
keycode = 138 # HELP key
cprint("NOW WRITES OUT: %i = HELP" % (keycode))
self.eam.keyPressed(self.remotetype, keycode, 0)
# release the key
self.eam.keyPressed(self.remotetype, keycode, 1)
def createSummary(self):
return dBackupSummary
def connectHighPrioAction(self):
self.highPrioActionSlot = eActionMap.getInstance().bindAction(
"", -0x7FFFFFFF, self.doUnhide
)
def disconnectHighPrioAction(self):
self.highPrioActionSlot = None
self.highPrioAction = None
def setWindowTitle(self):
global dbackup_progress
if os_path.exists(dbackup_busy):
try: # will fail if mount is busy
os_rmdir(dbackup_busy)
except:
pass
if os_path.exists(dbackup_busy):
self["logo"].instance.setPixmapFromFile("%s/ring.png" % dbackup_plugindir)
else:
self["logo"].instance.setPixmapFromFile(
"%s/dbackup.png" % dbackup_plugindir
)
self["slider"].setValue(int(dbackup_progress))
self["menu"].instance.setPixmapFromFile(gm.getpicon("menu"))
self["info"].instance.setPixmapFromFile(gm.getpicon("info"))
self.setTitle(
backup_string
+ " & "
+ flashing_string
+ " %s @ %s" % (dbackup_version, self.boxtype)
)
self.session.summary["titletext"].setText(
backup_string + " & " + flashing_string
)
# update LCD displayentry
# cprint("=== onShow MainScreen")
if config.plugins.dbackup.displayentry.value == "clock":
self.session.summary["displayentry"].setText(
time.strftime("%H:%M", time.localtime(self.session.summary.clock.time))
)
self.session.summary.ClockTimer.start(1000, True)
if config.plugins.dbackup.displayentry.value == "dbackup":
self.session.summary["displayentry"].setText(_("dBackup"))
elif config.plugins.dbackup.displayentry.value == "nothing":
self.session.summary["displayentry"].setText(" ")
elif config.plugins.dbackup.displayentry.value == "dreambox":
self.session.summary["displayentry"].setText(self.boxtype)
else:
if not os_path.exists(dbackup_busy):
self.session.summary["displayentry"].setText(" ")
def byLayoutEnd(self):
global dbackup_progress
self["logo"].instance.setPixmapFromFile("%s/dbackup.png" % dbackup_plugindir)
self["slider"].setValue(int(dbackup_progress))
def leaving(self):
self.DimmingTimer.stop()
self.forcedexit([1, 1])
def lastbackup(self):
if int(config.plugins.dbackup.lastbackup.value) > 0:
timestr = time.strftime(
"%Y-%m-%d %H:%M",
time.localtime(int(config.plugins.dbackup.lastbackup.value)),
)
text = _("Last Backup") + ": " + timestr
if int(config.plugins.dbackup.latestbackup.value) > 0:
timestr = time.strftime(
"%Y-%m-%d %H:%M",
time.localtime(
int(config.plugins.dbackup.lastbackup.value)
+ (int(config.plugins.dbackup.latestbackup.value) * 3600 * 24)
),
)
autoBackupType = [
x
for x in automatic_options
if config.plugins.dbackup.automatic.value == x[0]
][0][1]
text += (
"\n\n"
+ _("Next Backup")
+ ": "
+ timestr
+ " ("
+ str(autoBackupType)
+ ")"
)
self.session.open(MessageBox, text, MessageBox.TYPE_INFO)
else:
text = _("Last Backup") + " " + _("not found")
self.session.open(MessageBox, text, MessageBox.TYPE_WARNING)
def deleting(self):
self.session.openWithCallback(
self.askForDelete,
ChoiceBox,
_("select Image for deleting"),
self.getImageList(),
)
def askForDelete(self, source):
if source == None:
return
else:
self.delimage = source[1].rstrip()
self.session.openWithCallback(
self.ImageDelete,
MessageBox,
_("deleting %s ?") % (self.delimage),
MessageBox.TYPE_YESNO,
)
def ImageDelete(self, answer):
if answer == None:
return
if answer:
cprint("DELETING %s" % self.delimage)
os_remove(self.delimage)
else:
return
def forcedexit(self, status):
# if status[0] > 0:
self.doUnhide(0, 0)
self.close()
def doHide(self):
if int(config.plugins.dbackup.fadetime.value) == 0:
return
if config.plugins.dbackup.transparency.value < config.av.osd_alpha.value:
cprint("hiding")
self.dimmed = config.av.osd_alpha.value
delta = (
int(config.av.osd_alpha.value)
- int(config.plugins.dbackup.transparency.value)
) / 5
self.step = int(1000 * int(config.plugins.dbackup.fadetime.value) // delta)
cprint("doHide delta transparency %d step time %d" % (delta, self.step))
try:
self.DimmingTimer.start(self.step, True)
except:
pass
else:
cprint("no hiding")
def doDimming(self):
global dbackup_configuring
self.DimmingTimer.stop()
if fbClass.getInstance().islocked() or dbackup_configuring: # Flashing or in Setup !!!
self.doUnhide(0, 0)
else:
if self.dimmed > 5:
self.dimmed = self.dimmed - 5
else:
self.dimmed = 0
# print(self.dimmed)
if os_path.exists("/proc/stb/video/alpha"):
f = open("/proc/stb/video/alpha", "w")
else: # dreamone, dreamtwo, dreamseven
f = open(
"/sys/devices/platform/meson-fb/graphics/fb0/osd_plane_alpha", "w"
)
f.write("%i" % self.dimmed)
f.close()
# continue dimming ?
if self.dimmed > config.plugins.dbackup.transparency.value:
self.DimmingTimer.start(self.step, True)
else:
# do final choosen transparency
if os_path.exists("/proc/stb/video/alpha"):
f = open("/proc/stb/video/alpha", "w")
else: # dreamone, dreamtwo, dreamseven
f = open(
"/sys/devices/platform/meson-fb/graphics/fb0/osd_plane_alpha",
"w",
)
f.write("%i" % config.plugins.dbackup.transparency.value)
f.close()
def doUnhide(self, key, flag):
global dbackup_configuring
if fbClass.getInstance().islocked() or dbackup_configuring: # Flashing or Preview !!!
cprint("FLASHING LOCKED")
# last reset needed
if os_path.exists("/proc/stb/video/alpha"):
f = open("/proc/stb/video/alpha", "w")
else: # dreamone, dreamtwo, dreamseven
f = open(
"/sys/devices/platform/meson-fb/graphics/fb0/osd_plane_alpha", "w"
)
f.write("%i" % (config.av.osd_alpha.value))
f.close()
return
cprint("unhiding")
if config.plugins.dbackup.transparency.value < config.av.osd_alpha.value:
# reset needed
if os_path.exists("/proc/stb/video/alpha"):
f = open("/proc/stb/video/alpha", "w")
else: # dreamone, dreamtwo, dreamseven
f = open(
"/sys/devices/platform/meson-fb/graphics/fb0/osd_plane_alpha", "w"
)
f.write("%i" % (config.av.osd_alpha.value))
f.close()
if os_path.exists(dbackup_busy):
self.doHide()
else:
cprint("no unhiding")
return 0
def flash(self):
booted = gm.booted()
if booted != "Flash":
self.session.open(MessageBox, noflashing_string, MessageBox.TYPE_ERROR)
else:
if os_path.exists(dbackup_busy):
self.session.open(MessageBox, running_string, MessageBox.TYPE_ERROR)
else:
self.partition = None
if gm.isgpt():
self.session.openWithCallback(
self.askForPartition,
ChoiceBox,
partition_string,
self.getPartitionList(True),
)
else:
self.session.openWithCallback(
self.askForImage,
ChoiceBox,
fileupload_string,
self.getImageList(True),
)
def askForPartition(self, partition):
if partition == None:
self.session.open(MessageBox, nopartition_string, MessageBox.TYPE_ERROR)
else:
self.partition = partition[1]
self.session.openWithCallback(
self.askForImage, ChoiceBox, fileupload_string, self.getImageList(True)
)
def askForImage(self, image):
if image == None:
self.session.open(MessageBox, notar_string, MessageBox.TYPE_ERROR)
else:
cprint("flashing ...")
self.flashname = image[0]
self.flashfile = image[1]
self.flashdirectory = self.flashfile.replace(self.flashname, "")
if (
self.flashname.find(self.boxtype) == -1
and self.flashname.find(self.boxtype.replace("dream", "")) == -1
and self.flashname.find("-dreambox") == -1
):
self.session.open(MessageBox, noboxtype_string, MessageBox.TYPE_ERROR)
else:
if os_path.exists(dbackup_busy):
dbackup_progress = gm.progress()
if self.flashfile.endswith("tar.xz") and not os_path.exists(
"/usr/bin/xz"
):
self.session.open(MessageBox, noxz_string, MessageBox.TYPE_ERROR)
elif self.flashfile.endswith("tar.bz2") and not os_path.exists(
"/usr/bin/pbzip2"
):
self.session.open(MessageBox, nobz_string, MessageBox.TYPE_ERROR)
else:
naming = gm.trim(
self.flashname.replace("-" + self.boxtype, "")
.replace(self.boxtype + "-", "")
.replace("-dreambox", "")
.replace("-one", "")
.replace("-two", "")
.replace(".rootfs", "")
.replace("-deb", "")
.replace("_mmc", "")
.replace("-bak", "")
.replace("-image", ""),
self.maxlen,
False,
False,
False,
)
cprint("proposed name: %s" % naming)
if gm.isgpt() and config.plugins.uboot.naming.value:
self.session.openWithCallback(
self.askForNaming,
InputBox,
title=_("Enter Backup Imagename"),
text=naming,
maxSize=True,
visible_width=self.maxlen,
type=Input.TEXT,
)
else:
self.askForNaming()
def askForNaming(self, target=None):
if target == None:
self.naming = None
else:
self.naming = gm.trim(target, 0, False, False, False)
self.session.openWithCallback(
self.startFlash,
MessageBox,
_("Are you sure that you want to flash now %s ?") % (self.flashfile),
MessageBox.TYPE_YESNO,
)
def getPartitionList(self, partition=False):
p = open("/proc/cmdline")
cmd = p.read()
p.close()
partitions = []
cprint(cmd)
for x in range(0, 8):
partition = "/dev/mmcblk0p%d" % (x + 5)
if x == 0:
partlabel = "/dev/disk/by-partlabel/dreambox-rootfs"
else:
partlabel = "/dev/disk/by-partlabel/dreambox-rootfs%d" % x
# cprint(partition)
if os_path.exists(partlabel) and os_path.exists(partition):
if config.plugins.uboot.naming.value:
name = gm.getlabel(partition)
else:
name = "Dreambox Image %d" % x
if cmd.find(partition) == -1:
partitions.append(("%s [%s]" % (partition, name), partition))
else:
partitions.append(("%s @%s@" % (partition, name), partition))
if os_path.exists("/dev/mmcblk1") and os_path.exists(
"/dev/disk/by-partlabel/DREAMBOOT"
):
if cmd.find("/dev/mmcblk1p2") == -1:
partitions.append(
("/dev/mmcblk1p2 [Dreambox Image SD]", "/dev/mmcblk1p2")
)
else:
partitions.append(
("/dev/mmcblk1p2 @Dreambox Image SD@", "/dev/mmcblk1p2")
)
return partitions
def getImageList(self, flash=False):
backups = []
list = gm.backups()
for name in list:
name2 = (
name.replace("/media/sd/backup/", "")
.replace("/media/usb/backup/", "")
.replace("/media/hdd/backup/", "")
.replace("/data/backup/", "")
.replace(".tar.gz", "")
.replace(".tar.xz", "")
.replace(".tar.bz2", "")
.replace(".zip", "")
)
backups.append((name2, name))
backups.sort(reverse=True)
return backups
def startFlash(self, option):
if option:
if self.flashfile == "rescue":
message = _("Press OK now for flashing\n\n%s") % self.flashfile
else:
message = (
_(
"Press OK now for flashing\n\n%s\n\nBox will reboot automatically when finished!"
)
% self.flashfile
)
self.session.openWithCallback(
self.doFlash, MessageBox, message, MessageBox.TYPE_INFO
)
else:
self.session.open(
MessageBox,
_("Sorry, Flashing of %s was canceled!") % self.flashfile,
MessageBox.TYPE_ERROR,
)
def doFlash(self, option):
if option:
cprint("is flashing now %s" % self.flashfile)
self.doHide()
self.session.summary["slider"].show()
self.session.summary["duration"].setText("0")
self["slider"].show()
self["duration"].setText("0s")
self["size"].setText("0MB")
self.session.summary["titletext"].setText(flashing_string)
self.TimerFlashing = eTimer()
self.TimerFlashing.stop()
if os_path.exists("/var/lib/dpkg/status"):
self.TimerFlashing_conn = self.TimerFlashing.timeout.connect(
self.flashingFinishedCheck
)
else:
self.TimerFlashing.callback.append(self.flashingFinishedCheck)
self.TimerFlashing.start(1000, True)
if self.partition == None:
cprint("Flashing ...")
gm.flash(self.flashfile)
else:
cprint("Flashing to %s ..." % self.partition)
if self.naming == None:
gm.flash(self.flashfile, self.partition,"")
else:
gm.flash(self.flashfile, self.partition, self.naming)
else:
cprint("cancelled flashing %s" % self.flashfile)
def flashingFinishedCheck(self):
global dbackup_progress
global dbackup_duration
if not os_path.exists(dbackup_busy):
rsize = 0
if self.flashfile == "rescue":
dbackup_progress = "512"
else:
tarFile = (
self.flashfile.replace(".tar.gz", ".tar")
.replace(".tar.xz", ".tar")
.replace(".tar.bz2", ".tar")
)
# cprint(tarFile)
dbackup_progress = gm.progress(tarFile)
dbackup_duration = gm.duration(tarFile)
cprint(
"flashing progress %s MB after %d sec"
% (dbackup_progress, dbackup_duration)
)
self["slider"].setValue(int(dbackup_progress))
self["duration"].setText("%ds" % dbackup_duration)
self["size"].setText("%sMB" % dbackup_progress)
# LCD Skin
if "slider" in self.session.summary:
self.session.summary["slider"].setValue(int(dbackup_progress))
if "duration" in self.session.summary:
self.session.summary["duration"].setText("%d" % dbackup_duration)
self["duration"].setText("%s" % dbackup_duration)
if "displayentry" in self.session.summary:
self.session.summary["displayentry"].setText("%sMB" % dbackup_progress)
self.TimerFlashing.start(1000, True)
else:
cprint("FLASHING UNHIDE")
dbackup_progress = "0"
dbackup_duration = 0
self.doUnhide(0, 0)
if self.flashfile == "rescue":
dbackup_progress = "0"
self["slider"].setValue(int(dbackup_progress))
self["duration"].setText(" ")
self["size"].setText(" ")
if "slider" in self.session.summary:
self.session.summary["slider"].setValue(int(dbackup_progress))
self.DimmingTimer.stop()
self.session.open(
MessageBox,
_("Flashing of %s was finished!") % self.flashfile,
MessageBox.TYPE_INFO,
)
else:
self["slider"].setValue(int(dbackup_progress))
self["duration"].setText(" ")
self["size"].setText(" ")
if "slider" in self.session.summary:
self.session.summary["slider"].setValue(int(dbackup_progress))
self.lockFlashing()
def lockFlashing(self):
cprint(">>> lockFlashing")
if self.boxtype != "dreamone":
eDBoxLCD.getInstance().lock()
eRCInput.getInstance().lock()
fbClass.getInstance().lock()
def config(self):
self.session.open(MessageBox, running_string, MessageBox.TYPE_ERROR)
def cancel(self):
self.close(False)
def getBackupPath(self):
backups = []
paths = gm.paths()
for path in paths:
backups.append((path, path))
return backups
def okPressed(self):
if os_path.exists(dbackup_busy):
self.session.open(MessageBox, running_string, MessageBox.TYPE_WARNING)
def backup(self):
global dbackup_progress
if os_path.exists(dbackup_busy):
self.session.open(MessageBox, running_string, MessageBox.TYPE_WARNING)
else:
if config.plugins.dbackup.backupaskdir.value:
self.session.openWithCallback(
self.askForBackupPath,
ChoiceBox,
_("select backup path"),
self.getBackupPath(),
)
else:
backup = []
backup.append((config.plugins.dbackup.backuplocation.value))
self.askForBackupPath(backup)
def askForBackupPath(self, backup_path):
# self.imagetype=""
self.creator = ""
if backup_path == None:
self.session.open(MessageBox, _("nothing entered"), MessageBox.TYPE_ERROR)
return
path = backup_path[0]
cprint("PATH: %s" % path)
if not os_path.exists(path):
self.session.open(MessageBox, mounted_string % path, MessageBox.TYPE_ERROR)
return
path = path.lstrip().rstrip("/").rstrip().replace(" ", "")
# remember for next time
config.plugins.dbackup.backuplocation.value = path
config.plugins.dbackup.backuplocation.save()
if not os_path.exists(config.plugins.dbackup.backuplocation.value):
os_mkdir(config.plugins.dbackup.backuplocation.value, 0o777)
name = gm.trim(
str(config.plugins.dbackup.prefix.value), dbackup_visible, False, False, False
)
if os_path.exists("/etc/image-version"):
f = open("/etc/image-version")
line = f.readline()
while line:
line = f.readline()
if line.startswith("creator="):
name = line
f.close()
name = name.replace("creator=", "")
sp = []
if len(name) > 0:
sp = name.split(" ")
if len(sp) > 0:
name = sp[0]
name = name.replace("\n", "")
# suggested_backupname = gm.trim(name, self.maxlen,False, False, False)
suggested_backupname = gm.trim(name, dbackup_visible,False, False, False)
cprint("suggested: %s" % suggested_backupname)
self.session.openWithCallback(
self.askForBackupName,
InputBox,
title=backupimage_string,
text=suggested_backupname,
maxSize=True,
visible_width=self.maxlen,
type=Input.TEXT,
)
def askForBackupName(self, name):
if name == None:
self.session.open(MessageBox, _("nothing entered"), MessageBox.TYPE_ERROR)
else:
# self.backupname = gm.trim(name, 0, True, False, False)
self.backupname = gm.trim(name,0,True,config.plugins.gutemine.backupdate.value,config.plugins.gutemine.backuptime.value)
cprint("accepted: %s" % self.backupname)
if os_path.exists(
"%s/%s.%s"
% (
config.plugins.dbackup.backuplocation.value,
self.backupname,
config.plugins.dbackup.backuptool.value,
)
):
self.session.openWithCallback(
self.confirmedBackup,
MessageBox,
"%s.%s" % (self.backupname, config.plugins.dbackup.backuptool.value)
+ "\n"
+ _("already exists,")
+ " "
+ _("overwrite ?"),
MessageBox.TYPE_YESNO,
)
else:
self.confirmedBackup(True)
def confirmedBackup(self, answer):
if answer:
if os_path.exists(
"%s/%s.%s"
% (
config.plugins.dbackup.backuplocation.value,
self.backupname,
config.plugins.dbackup.backuptool.value,
)
):
os_remove(
"%s/%s.%s"
% (
config.plugins.dbackup.backuplocation.value,
self.backupname,
config.plugins.dbackup.backuptool.value,
)
)
self.session.openWithCallback(
self.startBackup,
MessageBox,
_("Press OK for starting backup")
+ "\n\n%s.%s"
% (self.backupname, config.plugins.dbackup.backuptool.value)
+ "\n\n"
+ _("Be patient, this takes some time ..."),
MessageBox.TYPE_INFO,
)
else:
self.session.open(MessageBox, _("not confirmed"), MessageBox.TYPE_ERROR)
def startBackup(self, answer):
global dbackup_file
if answer:
self.TimerBackup.stop()
dbackup_file = "%s/%s.%s" % (
config.plugins.dbackup.backuplocation.value,
self.backupname,
config.plugins.dbackup.backuptool.value,
)
cprint("is doing backup now ...")
self["logo"].instance.setPixmapFromFile("%s/ring.png" % dbackup_plugindir)
self.doHide()
self.session.summary["slider"].show()
self.session.summary["duration"].setText("0")
self["slider"].show()
self["duration"].setText("0s")
self["size"].setText("0MB")
self.session.summary["titletext"].setText(backup_string)
gm.backup(dbackup_file)
if config.plugins.dbackup.backupsettings.value:
gm.settings()
config.plugins.dbackup.lastbackup.value = int(time.time())
config.plugins.dbackup.lastbackup.save()
self.TimerBackup.start(1000, True)
else:
cprint("was not confirmed")
def backupFinishedCheck(self):
global dbackup_progress
global dbackup_duration
global dbackup_file
if dbackup_file == None:
self.TimerBackup.start(1000, True)
return
if os_path.exists(dbackup_busy):
dbackup_progress = gm.progress(dbackup_file)
dbackup_duration = gm.duration(dbackup_file)
cprint(
"backup progress %s MB after %d sec"
% (dbackup_progress, dbackup_duration)
)
self["slider"].setValue(int(dbackup_progress))
self["duration"].setText("%ds" % dbackup_duration)
self["size"].setText("%sMB" % dbackup_progress)
# LCD skin
if "slider" in self.session.summary:
self.session.summary["slider"].setValue(int(dbackup_progress))
if "duration" in self.session.summary:
self.session.summary["duration"].setText("%d" % dbackup_duration)
if "displayentry" in self.session.summary:
self.session.summary["displayentry"].setText("%sMB" % dbackup_progress)
self.TimerBackup.start(1000, True)
else:
dbackup_progress = "0"
dbackup_duration = 0
if os_path.exists(dbackup_file):
cprint("found backup %s" % dbackup_file)
dbackup_progress = gm.progress(dbackup_file)
dbackup_duration = gm.duration(dbackup_file)
if "duration" in self.session.summary:
self.session.summary["duration"].setText("%d" % dbackup_duration)
self["duration"].setText("%ds" % dbackup_duration)
if "displayentry" in self.session.summary:
self.session.summary["displayentry"].setText(" ")
self.FinishMsgTxt = (
dbackup_progress
+ " MB "
+ _("Backup finished:\n\n%s") % (dbackup_file)
+ "\n\n"
+ _("Duration:")
+ (" %d %s" % (dbackup_duration, _("seconds")))
)
self.FinishMsgBoxType = MessageBox.TYPE_INFO
else:
self.FinishMsgTxt = _("Backup failed for imagename:\n\n%s") % (
dbackup_file
)
self.FinishMsgBoxType = MessageBox.TYPE_ERROR
if config.plugins.dbackup.transparency.value < config.av.osd_alpha.value:
# reset needed
if os_path.exists("/proc/stb/video/alpha"):
f = open("/proc/stb/video/alpha", "w")
else: # dreamone, dreamtwo, dreamseven
f = open(
"/sys/devices/platform/meson-fb/graphics/fb0/osd_plane_alpha",
"w",
)
f.write("%i" % (config.av.osd_alpha.value))
f.close()
self.DimmingTimer.stop()
dbackup_progress = "0"
dbackup_duration = 0
dbackup_file = None
self["slider"].setValue(int(dbackup_progress))
self["duration"].setText(" ")
self["size"].setText(" ")
# LCD skin
if "slider" in self.session.summary:
self.session.summary["slider"].setValue(0)
self.session.summary["slider"].hide()
if "duration" in self.session.summary:
self.session.summary["duration"].setText(" ")
if "displayentry" in self.session.summary:
self.session.summary["displayentry"].setText(" ")
self.TimerBackup.start(1000, True)
cprint("show finished message ...")
# AddNotification(MessageBox, self.FinishMsgTxt, self.FinishMsgBoxType, windowTitle=_("New Backup"))
clean_dBackup()
self.session.open(MessageBox, self.FinishMsgTxt, self.FinishMsgBoxType)
def config(self):
global dbackup_configuring
dbackup_configuring=True
self.session.openWithCallback(self.closingConfig,dBackupConfiguration)
def closingConfig(self,answer):
global dbackup_configuring
dbackup_configuring=False
def startdBackup(session, **kwargs):
session.open(dBackup)
def startRecover(session, **kwargs):
global dsession
dsession = session
session.openWithCallback(
askForTask,
ChoiceBox,
_("Please choose what you want to do next."),
getTaskList(),
)
def getTaskList():
task = []
task.append((_("Reboot") + " " + _("Recovery Mode"), "boot"))
task.append((_("Software update") + " " + _("Recovery Mode"), "upgrade"))
return task
def askForTask(task):
global dsession
if task == None:
return
else:
do = task[1].rstrip()
# print(">>>>>>>>>>>", do)
if do == "boot":
dsession.openWithCallback(
startRecovery,
MessageBox,
_("Recovery Mode") + " " + _("Really shutdown now?"),
MessageBox.TYPE_YESNO,
)
else:
dsession.openWithCallback(
startLoaderUpdate,
MessageBox,
_("Recovery Mode") + " " + _("Software update") + "?",
MessageBox.TYPE_YESNO,
)
def startRecovery(option):
global dsession
if option:
cprint("starting Recovery")
gm.rescue()
else:
cprint("cancelled Recovery")
def startLoaderUpdate(option):
global dsession
if option:
cprint("starting Rescue Loader update")
update_cmd = "update-rescue -v"
from API import session
dsession.open(
Console,
_("Recovery Mode")
+ " "
+ _("Software update")
+ " "
+ _("waiting")
+ "...",
[update_cmd],
)
else:
cprint("cancelled Rescue Loader update")
def recovery2Webif(enable):
if enable:
cprint("recovery webinterface enabling")
else:
cprint("recovery webinterface disabling")
if os_path.exists(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/WebComponents/Sources/PowerState.py"
):
p = open(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/WebComponents/Sources/PowerState.py"
)
ps = p.read()
p.close()
if enable:
if ps.find("type == 99:") == -1:
cprint("recovery webinterface inserting #1")
ps2 = ps.replace(
"type = int(self.cmd)",
'type = int(self.cmd)\n\n if type == 99:\n b=open("/proc/stb/fp/boot_mode","w")\n b.write("rescue")\n b.close()\n type=2\n',
)
p = open(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/WebComponents/Sources/PowerState.py",
"w",
)
p.write(ps2)
p.close()
else:
if ps.find("type == 99:") != -1:
cprint("recovery webinterface removing #1")
ps2 = ps.replace(
'type = int(self.cmd)\n\n if type == 99:\n b=open("/proc/stb/fp/boot_mode","w")\n b.write("rescue")\n b.close()\n type=2\n',
"type = int(self.cmd)",
)
p = open(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/WebComponents/Sources/PowerState.py",
"w",
)
p.write(ps2)
p.close()
if os_path.exists(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/core.js"
):
p = open(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/core.js"
)
cs = p.read()
p.close()
if enable:
if cs.find("rebootsetup") == -1:
cprint("recovery webinterface inserting #2")
cs2 = cs.replace("'gui' : 3", "'gui' : 3, 'rebootsetup' : 99")
p = open(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/core.js",
"w",
)
p.write(cs2)
p.close()
else:
if cs.find("rebootsetup") != -1:
cprint("recovery webinterface removing #2")
cs2 = cs.replace("'gui' : 3, 'rebootsetup' : 99", "'gui' : 3")
p = open(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/core.js",
"w",
)
p.write(cs2)
p.close()
if os_path.exists(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/tpl/default/index.html"
):
p = open(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/tpl/default/index.html"
)
ix = p.read()
p.close()
if enable:
if ix.find("rebootsetup") == -1:
cprint("recovery webinterface inserting #3")
ix2 = ix.replace(
'data-state="gui">Restart GUI</a></li>',
'data-state="gui">Restart GUI</a></li>\n <li><a href="#" class="powerState" data-state="rebootsetup">Recovery Mode</a></li>',
)
p = open(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/tpl/default/index.html",
"w",
)
p.write(ix2)
p.close()
else:
if ix.find("rebootsetup") != -1:
cprint("recovery webinterface removing #3")
ix2 = ix.replace(
'data-state="gui">Restart GUI</a></li>\n <li><a href="#" class="powerState" data-state="rebootsetup">Recovery Mode</a></li>',
'data-state="gui">Restart GUI</a></li>',
)
ix2 = ix.replace(
'data-state="gui">Restart GUI</a></li>\n <li><a href="#" class="powerState" data-state="rebootsetup">Recovery</a></li>',
'data-state="gui">Restart GUI</a></li>',
)
p = open(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/tpl/default/index.html",
"w",
)
p.write(ix2)
p.close()
if os_path.exists(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/tpl/default/tplPower.htm"
):
p = open(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/tpl/default/tplPower.htm"
)
df = p.read()
p.close()
if enable:
if df.find("rebootsetup") == -1:
cprint("recovery webinterface inserting #4")
df2 = df.replace(
'data-state="gui">${strings.restart_enigma2}</button></td>',
'data-state="gui">${strings.restart_enigma2}</button></td>\n </tr>\n <tr>\n <td><button class="w200h50 powerState" data-state="rebootsetup">Recovery Mode</button></td>',
)
p = open(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/tpl/default/tplPower.htm",
"w",
)
p.write(df2)
p.close()
else:
if df.find("rebootsetup") != -1:
cprint("recovery webinterface removing #4")
df2 = df.replace(
'data-state="gui">${strings.restart_enigma2}</button></td>\n </tr>\n <tr>\n <td><button class="w200h50 powerState" data-state="rebootsetup">Recovery Mode</button></td>',
'data-state="gui">${strings.restart_enigma2}</button></td>',
)
df2 = df.replace(
'data-state="gui">${strings.restart_enigma2}</button></td>\n </tr>\n <tr>\n <td><button class="w200h50 powerState" data-state="rebootsetup">Recovery</button></td>',
'data-state="gui">${strings.restart_enigma2}</button></td>',
)
p = open(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/tpl/default/tplPower.htm",
"w",
)
p.write(df2)
p.close()
return
TimerBackup = None
TimerBackup_conn = None
def autostart(reason, **kwargs):
if "session" in kwargs and reason == 0:
session = kwargs["session"]
cprint("autostart")
if os_path.exists(dbackup_busy):
gm.progress()
config.misc.standbyCounter.addNotifier(dBackupOnStandby, initial_call=False)
dBackupPowerOn()
if os_path.exists(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/WebChilds/Toplevel.py"
):
from Plugins.Extensions.WebInterface.WebChilds.Toplevel import (
addExternalChild,
)
addExternalChild(("dbackup", wBackup(), "dBackup", "1", True))
else:
cprint("Webif not found")
if (
config.plugins.dbackup.recovering.value == "webif"
or config.plugins.dbackup.recovering.value == "both"
):
recovery2Webif(True)
else:
recovery2Webif(False)
if (
config.plugins.dbackup.automatic.value == "boot"
and int(config.plugins.dbackup.latestbackup.value) > 0
):
now = int(time.time())
last = int(config.plugins.dbackup.lastbackup.value)
if (int(config.plugins.dbackup.latestbackup.value) > 30) or (
(now - last)
>= int(config.plugins.dbackup.latestbackup.value) * 3600 * 24
):
cprint("doing new Backup ...")
startBackupFinishedCheckTimer()
backupname = automaticBackupName()
backupfile = "%s/%s.%s" % (
config.plugins.dbackup.backuplocation.value,
backupname,
config.plugins.dbackup.backuptool.value,
)
gm.backup(backupfile)
if config.plugins.dbackup.backupsettings.value:
gm.settings()
config.plugins.dbackup.lastbackup.value = int(time.time())
config.plugins.dbackup.lastbackup.save()
else:
cprint("recent enough Backup ...")
return
def dBackupOnStandby(reason):
cprint("entering Standby/Idle")
from Screens.Standby import inStandby
inStandby.onClose.append(dBackupPowerOn)
if os_path.exists(dbackup_busy):
cprint("busy with Backup ...")
return
if (
config.plugins.dbackup.automatic.value == "idle"
and int(config.plugins.dbackup.latestbackup.value) > 0
):
now = int(time.time())
last = int(config.plugins.dbackup.lastbackup.value)
if (int(config.plugins.dbackup.latestbackup.value) > 30) or (
(now - last) >= int(config.plugins.dbackup.latestbackup.value) * 3600 * 24
):
cprint("doing new Backup ...")
startBackupFinishedCheckTimer()
backupname = automaticBackupName()
backupfile = "%s/%s.%s" % (
config.plugins.dbackup.backuplocation.value,
backupname,
config.plugins.dbackup.backuptool.value,
)
gm.backup(backupfile)
if config.plugins.dbackup.backupsettings.value:
gm.settings()
config.plugins.dbackup.lastbackup.value = int(time.time())
config.plugins.dbackup.lastbackup.save()
else:
cprint("recent enough Backup ...")
def startBackupFinishedCheckTimer():
cprint("start BackupFinishedCheckTimer ...")
global TimerBackup
global TimerBackup_conn
TimerBackup = eTimer()
if os_path.exists("/var/lib/dpkg/status"):
TimerBackup_conn = TimerBackup.timeout.connect(backupFinishedCheck)
else:
TimerBackup.callback.append(backupFinishedCheck)
TimerBackup.start(1000, True)
def freeMount():
f = open("/proc/mounts", "r")
m = f.read()
f.close()
if m.find(dbackup_busy) == -1:
return True
return False
def backupFinishedCheck():
global TimerBackup
if os_path.exists(dbackup_busy):
gm.progress()
# cprint("not finished - continue checking ...")
TimerBackup.start(1000, True)
else:
TimerBackup = eTimer()
TimerBackup.stop()
# start automatic cleanup
clean_dBackup()
def dBackupPowerOn():
cprint("booting or leaving Standby/Idle")
if (
config.plugins.dbackup.automatic.value == "message"
and int(config.plugins.dbackup.latestbackup.value) > 0
and int(config.plugins.dbackup.latestbackup.value) < 31
):
cprint("checking latest backup ...")
now = int(time.time())
last = int(config.plugins.dbackup.lastbackup.value)
if (now - last) >= int(config.plugins.dbackup.latestbackup.value) * 3600 * 24:
cprint("remind too old backup ...")
global BackupReminderTimer
BackupReminderTimer = eTimer()
global BackupReminderTimer_conn
if os_path.exists("/var/lib/dpkg/status"):
BackupReminderTimer_conn = BackupReminderTimer.timeout.connect(
showBackupReminder
)
else:
BackupReminderTimer.callback.append(showBackupReminder)
# remind after 10 seconds ...
BackupReminderTimer.start(10000, True)
def showBackupReminder():
cprint("now reminding too old backup ...")
from API import session
if int(config.plugins.dbackup.lastbackup.value) > 0:
timestr = time.strftime(
"%Y-%m-%d %H:%M",
time.localtime(int(config.plugins.dbackup.lastbackup.value)),
)
text = ("Last Backup") + ": " + timestr
session.open(MessageBox, text, MessageBox.TYPE_INFO, timeout=10)
else:
text = _("Last Backup") + " " + _("not found")
session.open(MessageBox, text, MessageBox.TYPE_WARNING, timeout=10)
def automaticBackupName(mask=False):
maxlen = int(config.plugins.dbackup.maxlen.value)
if mask:
name = gm.trim(
str(config.plugins.dbackup.prefix.value), maxlen, True, False, False
)
else:
name = gm.trim(
str(config.plugins.dbackup.prefix.value),
maxlen,
True,
config.plugins.gutemine.backupdate.value,
config.plugins.gutemine.backuptime.value,
)
if os_path.exists("/etc/image-version"):
f = open("/etc/image-version")
line = f.readline()
while line:
line = f.readline()
if line.startswith("creator="):
name = line
f.close()
name = name.replace("creator=", "")
sp = []
if len(name) > 0:
sp = name.split(" ")
if len(sp) > 0:
name = sp[0]
name = name.replace("\n", "")
cprint("name: %s" % name)
if mask:
suggested_backupname = gm.trim(name, 0, True, False, False) + "*"
else:
suggested_backupname = gm.trim(name, 0)
cprint("suggested name: !%s!" % suggested_backupname)
return suggested_backupname
def main(session, **kwargs):
session.open(dBackup)
def Plugins(**kwargs):
plugin_desc = []
if config.plugins.dbackup.showinsettings.value:
plugin_desc.append(
PluginDescriptor(
name=_("Recovery Mode") + " " + _("Update"),
description="dBackup3",
where=PluginDescriptor.WHERE_MENU,
fnc=mainconf,
)
)
if config.plugins.dbackup.showinplugins.value:
plugin_desc.append(
PluginDescriptor(
name=backup_string + " & " + flashing_string,
description="dBackup3",
where=PluginDescriptor.WHERE_PLUGINMENU,
icon="dbackup.png",
fnc=main,
)
)
if config.plugins.dbackup.showinextensions.value:
plugin_desc.append(
PluginDescriptor(
name=backup_string + " & " + flashing_string,
description="dBackup3",
where=PluginDescriptor.WHERE_EXTENSIONSMENU,
icon="dbackup.png",
fnc=main,
)
)
plugin_desc.append(
PluginDescriptor(
where=[
PluginDescriptor.WHERE_SESSIONSTART,
PluginDescriptor.WHERE_AUTOSTART,
],
fnc=autostart,
)
)
# cprint("PluginDescriptor: %s" % plugin_desc)
return plugin_desc
def mainconf(menuid):
cprint("menu: %s" % menuid)
if menuid == "setup":
return [
(backup_string + " & " + flashing_string, startdBackup, "dbackup3", None)
]
elif menuid == "system":
if (
config.plugins.dbackup.recovering.value == "factory"
or config.plugins.dbackup.recovering.value == "both"
):
return [(_("Recovery Mode"), startRecover, "recover", None)]
else:
return []
elif menuid == "extended":
if (
config.plugins.dbackup.recovering.value == "factory"
or config.plugins.dbackup.recovering.value == "both"
):
return [(_("Recovery Mode"), startRecover, "recover", None)]
else:
return []
else:
return []
###############################################################################
# dBackup Webinterface by gutemine
###############################################################################
class wBackup(resource.Resource):
def render_GET(self, req):
self.boxtype = gm.boxtype()
global dbackup_progress
global dbackup_duration
global dbackup_file
file = req.args.get("file", None)
maxlen = int(config.plugins.dbackup.maxlen.value)
directory = req.args.get("directory", None)
htmlbackup = ""
htmlimages = ""
command = req.args.get("command", None)
cprint("received %s %s %s" % (command, directory, file))
req.setResponseCode(http.OK)
req.setHeader("Content-type", "text/html")
req.setHeader("charset", "UTF-8")
no_reply=header_string + nowebif_string
if not config.plugins.dbackup.webinterface.value:
return no_reply.encode('utf-8')
if not os_path.exists("/usr/lib/enigma2/python/Plugins/SystemPlugins/gutemine"):
return no_reply.encode('utf-8')
if (
not os_path.exists(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/img/dbackup.png"
)
):
os_symlink(
"%s/dbackup.png" % dbackup_plugindir,
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/img/dbackup.png",
)
if (
not os_path.exists(
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/img/ring.png"
)
):
os_symlink(
"%s/ring.png" % dbackup_plugindir,
"/usr/lib/enigma2/python/Plugins/Extensions/WebInterface/web-data/img/ring.png",
)
if os_path.exists(dbackup_busy):
dbackup_backuping_progress = ""
dbackup_backuping_progress += header_string
dbackup_backuping_progress += "<br>%s<br><br>" % running_string
dbackup_backuping_progress += (
'<br><img src="/web-data/img/ring.png" alt="%s ..."/><br><br>'
% (backup_string)
)
if dbackup_file == None:
dbackup_progress = ""
dbackup_duration = 0
else:
dbackup_progress = gm.progress(dbackup_file)
dbackup_duration = gm.duration(dbackup_file)
cprint(
"webif checked backup progress for %s with %s MB for %ds"
% (dbackup_file, dbackup_progress, dbackup_duration)
)
dbackup_backuping_progress += "<br>%s<br><br>" % (dbackup_file)
dbackup_backuping_progress += (
'<div style="background-color:yellow;width:%spx;height:20px;border:1px solid #000"></div> '
% (dbackup_progress)
)
dbackup_backuping_progress += "<br>%s MB" % (dbackup_progress)
dbackup_backuping_progress += " %d %s<br>" % (
dbackup_duration,
_("seconds"),
)
dbackup_backuping_progress += '<br><form method="GET">'
dbackup_backuping_progress += (
'<input name="command" type="submit" size="100px" title="%s" value="%s">'
% (refresh_string, "Refresh")
)
dbackup_backuping_progress += "</form>"
reply_progress=header_string + dbackup_backuping_progress
return reply_progress.encode('utf-8')
if command == None or command[0] == "Refresh":
htmlbackup = ""
paths = gm.paths()
if config.plugins.dbackup.backupaskdir.value:
for path in paths:
htmlbackup += '<option value="%s" class="black">%s</option>\n' % (
path,
path,
)
else:
if os_path.exists("/media/hdd/backup"):
htmlbackup += '<option value="%s" class="black">%s</option>\n' % (
"/media/hdd/backup",
"/media/hdd/backup",
)
else:
htmlbackup += '<option value="%s" class="black">%s</option>\n' % (
"/data/backup",
"/data/backup",
)
cprint("backup: %s" % htmlbackup)
htmlimages = ""
list = gm.backups()
list.sort(reverse=True)
for name in list:
name2 = (
name.replace("/media/sd/backup/", "")
.replace("/media/usb/backup/", "")
.replace("/media/hdd/backup/", "")
.replace("/data/backup/", "")
.replace(".tar.gz", "")
.replace(".tar.xz", "")
.replace(".tar.bz2", "")
)
htmlimages += '<option value="%s" class="black">%s</option>\n' % (
name,
name2,
)
cprint("images: %s" % htmlimages)
name = gm.trim(
str(config.plugins.dbackup.prefix.value), 20, False, False, False
)
# cprint("name: !%s!" % name)
if os_path.exists("/etc/image-version"):
f = open("/etc/image-version")
line = f.readline()
while line:
line = f.readline()
if line.startswith("creator="):
name = line
f.close()
name = name.replace("creator=", "")
sp = []
if len(name) > 0:
sp = name.split(" ")
if len(sp) > 0:
name = sp[0]
name = name.replace("\n", "")
suggested_backupname = gm.trim(name, maxlen, True, False, False)
# cprint("default name: !%s!" % suggested_backupname)
return """
<html>
%s<br>
<u>%s</u><br><br>
%s:<br><br>
%s<hr>
%s @ Dreambox<br><br>
<form method="GET">
<select name="file">%s
<input type="reset" size="100px">
<input name="command" type="submit" size=="100px" title=\"%s\" value="%s">
</select>
</form>
<img src="/web-data/img/dbackup.png" alt="%s ..."/><br><br>
<hr>
%s & %s @ Dreambox<br><br>
<form method="GET">
<select name="directory">%s
<input name="file" type="text" size="64" maxlength="%d" value="%s">
<input type="reset" size="100px">
<input name="command" type="submit" size=="100px" title=\"%s\" value="%s">
</select>
</form>
<img src="/web-data/img/ring.png" alt="%s ..."/><br><br>
<hr>
""" % (
header_string,
plugin_string,
info_header,
disclaimer_wstring,
fileupload_string,
htmlimages,
flashing_string,
"Flashing",
flashing_string,
backupdirectory_string,
backupimage_string,
htmlbackup,
maxlen * 2,
suggested_backupname,
backup_string,
"Backup",
backup_string,
)
else:
if command[0] == "Flashing":
booted = gm.booted()
if booted != "Flash":
cprint("not in Flash")
return header_string + noflashing_string
self.flashfile = file[0]
if (
self.flashname.find(self.boxtype) == -1
and self.flashname.find(self.boxtype.replace("dream", "")) == -1
and self.flashname.find("-dreambox") == -1
):
return header_string + noboxtype_string
if os_path.exists(self.flashfile):
cprint("is flashing now %s" % self.flashfile)
# gm.flash(self.flashfile,config.plugins.dbackup.dataerase.value)
gm.flash(self.flashfile)
return dbackup_flashing
else:
cprint("filename not found")
return header_string + notar_string
elif command[0] == "Backup":
extension = ".%s" % config.plugins.dbackup.backuptool.value
self.backupname = gm.trim(file[0], 0, True) + extension
path = directory[0]
path = path.lstrip().rstrip("/").rstrip().replace(" ", "")
config.plugins.dbackup.backuplocation.value = path
config.plugins.dbackup.backuplocation.save()
if not os_path.exists(config.plugins.dbackup.backuplocation.value):
os_mkdir(config.plugins.dbackup.backuplocation.value, 0o777)
if os_path.exists(
"%s/%s"
% (config.plugins.dbackup.backuplocation.value, self.backupname)
):
cprint("filename already exists")
return (
header_string
+ self.backupname
+ " "
+ _("already exists,")
+ " "
+ dbackup_backbutton
)
else:
# backupfile request
dbackup_file = "%s/%s" % (
config.plugins.dbackup.backuplocation.value,
self.backupname,
)
cprint("starting backup: %s" % dbackup_file)
gm.backup(dbackup_file)
if config.plugins.dbackup.backupsettings.value:
gm.settings()
config.plugins.dbackup.lastbackup.value = int(time.time())
config.plugins.dbackup.lastbackup.save()
return header_string + dbackup_backuping
else:
cprint("unknown command")
return header_string + _("nothing entered")
def backupFinishedCheck(self):
global dbackup_progress
global dbackup_duration
global dbackup_file
if os_path.exists(dbackup_busy):
cprint("checking for finished backup: %s" % dbackup_file)
dbackup_progress = gm.progress(dbackup_file)
dbackup_duration = gm.progress(dbackup_file)
cprint(
"webif backup progress %s MB after %d sec"
% (dbackup_progress, dbackup_duration)
)
self.TimerBackup.start(1000, True)
else:
if os_path.exists(dbackup_file):
dbackup_progress = "0"
dbackup_duration = 0
self.TimerBackup.stop()
cprint("found finished webif backup %s" % dbackup_file)
else:
cprint("found NO finished webif backup ...")
def lockFlashing(self):
cprint(">>> lockFlashing")
if self.boxtype != "dreamone":
eDBoxLCD.getInstance().lock()
eRCInput.getInstance().lock()
fbClass.getInstance().lock()
def clean_dBackup():
if int(config.plugins.dbackup.cleanlastbackup.value) == 0:
cprint("automatic cleanup in setup deactivated - max. number of backups = 0")
return
cprint("automatic cleanup")
# cleanup for settingsbackup
backupname_mask = (
automaticBackupName(mask=True) + "." + config.plugins.dbackup.backuptool.value
)
backuplocation = config.plugins.dbackup.backuplocation.value
# cprint("location %s name %s" % (backuplocation, backupname_mask))
backupList = glob(backuplocation + "/" + backupname_mask)
backupList.sort(reverse=True)
# cprint("backupList Count all: %d" % len(backupList))
keepbackupList = backupList[: int(config.plugins.dbackup.cleanlastbackup.value)]
del backupList[: int(config.plugins.dbackup.cleanlastbackup.value)]
BgFileEraser = eBackgroundFileEraser.getInstance()
cprint("backupList Count to keep: %d" % len(keepbackupList))
# for x in range(len(keepbackupList)):
# print("keep:" + keepbackupList[x] + "\n")
# cprint("backupList Count to delete: %s" % len(backupList))
for x in range(len(backupList)):
if os_path.exists(backupList[x]):
# print("marked do delete:" + backupList[x] + "\n")
BgFileEraser.erase(backupList[x])
class dBackupConfiguration(Screen, ConfigListScreen):
if sz_w == 2560:
skin = """
<screen name="dBackupConfiguration" position="center,240" size="1600,1040" title="dBackup Configuration" >
<widget name="logo" position="20,10" size="200,80" />
<widget backgroundColor="#9f1313" font="Regular;38" halign="center" name="buttonred" position="240,10" foregroundColor="white" shadowColor="black" shadowOffset="-3,-3" size="320,80" valign="center" />
<widget backgroundColor="#1f771f" font="Regular;38" halign="center" name="buttongreen" position="580,10" foregroundColor="white" shadowColor="black" shadowOffset="-3,-3" size="320,80" valign="center" />
<widget backgroundColor="#a08500" font="Regular;38" halign="center" name="buttonyellow" position="920,10" foregroundColor="white" shadowColor="black" shadowOffset="-3,-3" size="320,80" valign="center" />
<widget backgroundColor="#18188b" font="Regular;38" halign="center" name="buttonblue" position="1260,10" foregroundColor="white" shadowColor="black" shadowOffset="-3,-3" size="320,80" valign="center" />
<eLabel backgroundColor="grey" position="20,100" size="1560,2" />
<widget name="config" position="20,120" size="1560,900" enableWrapAround="1" scrollbarMode="showOnDemand" />
</screen>"""
elif sz_w == 1920:
skin = """
<screen name="dBackupConfiguration" position="center,170" size="1200,820" title="dBackup Configuration" >
<widget name="logo" position="20,10" size="150,60" />
<widget backgroundColor="#9f1313" font="Regular;30" halign="center" name="buttonred" position="190,10" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="240,60" valign="center" />
<widget backgroundColor="#1f771f" font="Regular;30" halign="center" name="buttongreen" position="440,10" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="240,60" valign="center" />
<widget backgroundColor="#a08500" font="Regular;30" halign="center" name="buttonyellow" position="690,10" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="240,60" valign="center" />
<widget backgroundColor="#18188b" font="Regular;30" halign="center" name="buttonblue" position="940,10" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="240,60" valign="center" />
<eLabel backgroundColor="grey" position="20,80" size="1160,1" />
<widget enableWrapAround="1" name="config" position="10,90" scrollbarMode="showOnDemand" size="1180,720" />
</screen>"""
else:
skin = """
<screen name="dBackupConfiguration" position="center,120" size="800,520" title="dBackup Configuration" >
<widget name="logo" position="10,5" size="100,40" />
<widget backgroundColor="#9f1313" font="Regular;19" halign="center" name="buttonred" position="120,5" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="160,40" valign="center" />
<widget backgroundColor="#1f771f" font="Regular;19" halign="center" name="buttongreen" position="290,5" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="160,40" valign="center" />
<widget backgroundColor="#a08500" font="Regular;19" halign="center" name="buttonyellow" position="460,5" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="160,40" valign="center" />
<widget backgroundColor="#18188b" font="Regular;19" halign="center" name="buttonblue" position="630,5" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="160,40" valign="center" />
<eLabel backgroundColor="grey" position="10,50" size="780,1" />
<widget name="config" position="10,60" size="780,450" enableWrapAround="1" scrollbarMode="showOnDemand" />
</screen>"""
def __init__(self, session, args=0):
Screen.__init__(self, session)
self.boxtype = gm.boxtype()
self.onShown.append(self.setWindowTitle)
# explizit check on every entry
self.onChangedEntry = []
self.aptInstall = eConsoleAppContainer()
# remember u-Boot
if gm.isgpt() and os_path.exists("/data/bootconfig.txt"):
f = open("/data/bootconfig.txt", "r")
oldmenu = f.read()
f.close()
if oldmenu.find("details=1") != -1:
cprint("found: details on")
config.plugins.uboot.details.value = True
else:
cprint("found: details off")
config.plugins.uboot.details.value = False
if oldmenu.find("default=") == -1:
cprint("found: no default=0")
config.plugins.uboot.image.value = "0"
else:
for x in range(0, 8):
d = "default=%d\n" % x
if oldmenu.find(d) != -1:
cprint("found: %s" % d)
config.plugins.uboot.image.value = str(x)
if oldmenu.find("font_size=") == -1:
cprint("found: font_size=3")
config.plugins.uboot.font.value = "3"
else:
for x in range(0, 4):
d = "font_size=%d\n" % x
if oldmenu.find(d) != -1:
cprint("found: %s" % d)
config.plugins.uboot.font.value = str(x)
for x in range(-1, 31):
t = "timeout=%d\n" % x
if oldmenu.find(t) != -1:
cprint("found: %s" % t)
config.plugins.uboot.timeout.value = str(x)
cprint("found: %s" % config.plugins.uboot.timeout.value)
cprint("----------- values -----------")
print(config.plugins.uboot.details.value)
print(config.plugins.uboot.image.value)
print(config.plugins.uboot.timeout.value)
cprint("----------- values -----------")
self.oldDefault=int(config.plugins.uboot.image.value)
self.oldTimeout=int(config.plugins.uboot.timeout.value)
self.oldDetails=config.plugins.uboot.details.value
self.install = "update"
if os_path.exists("/var/lib/dpkg/status"):
self.aptInstall_conn = self.aptInstall.appClosed.connect(
self.aptInstallFinished
)
cmd = "apt-get update"
else:
self.aptInstall.appClosed.append(self.aptInstallFinished)
cmd = "opkg update"
self.aptInstall.execute(cmd)
self.list = []
ConfigListScreen.__init__(
self, self.list, session=self.session, on_change=self.changedEntry
)
self.createSetup()
self["logo"] = Pixmap()
self["buttonred"] = Label(exit_string)
self["buttongreen"] = Label(_("Save"))
self["buttonyellow"] = Label(_("Reset"))
self["buttonblue"] = Label(info_header)
self["setupActions"] = ActionMap(
["SetupActions", "ColorActions", "VirtualKeyboardActions"],
{
"green": self.save,
"red": self.cancel,
"yellow": self.resetSettings,
"blue": self.disclaimer,
"save": self.save,
"cancel": self.cancel,
"ok": self.okPressed,
"showVirtualKeyboard": self.textPressed,
},
-2,
)
def createSetup(self, status=None):
if not hasattr(config.plugins, "gutemine"):
config.plugins.gutemine = ConfigSubsection()
if not hasattr(config.plugins.gutemine, "backupdate"):
config.plugins.gutemine.backupdate = ConfigBoolean(
default=True, descriptions=yes_no_descriptions
)
if not hasattr(config.plugins.gutemine, "backuptime"):
config.plugins.gutemine.backuptime = ConfigBoolean(
default=False, descriptions=yes_no_descriptions
)
self.list = []
self.list.append(("%s %s" % ("dBackup3 ", setup_string),))
self.list.append(
getConfigListEntry(_("Backuptool"), config.plugins.dbackup.backuptool)
)
self.list.append(
getConfigListEntry(
_("Choose backup location"), config.plugins.dbackup.backupaskdir
)
)
# self.list.append(getConfigListEntry(_("deleting %s ?").replace("?","") % "/data", config.plugins.dbackup.dataerase))
rp = os_path.realpath("/bin/tar")
cprint("realpath: %s\n" % rp)
ok_text = _("Press OK to start upgrade.").rstrip(".")
if rp.startswith("/bin/busybox"):
self.list.append(
getConfigListEntry(
"tar " + _("Installation"), config.plugins.dbackup.tar
)
)
else:
if os_path.exists("/var/lib/dpkg/status"):
self.list.append(
getConfigListEntry(
_("Exclude epg.db"), config.plugins.dbackup.epgdb
)
)
# else:
# self.list.append(getConfigListEntry(_("Exclude epg.dat"), config.plugins.dbackup.epgdb))
self.list.append(
getConfigListEntry(_("Exclude timers"), config.plugins.dbackup.timers)
)
self.list.append(
getConfigListEntry(
_("Exclude settings"), config.plugins.dbackup.settings
)
)
self.list.append(
getConfigListEntry(
_("extra") + " " + _("Settings") + " " + _("Backup"),
config.plugins.dbackup.backupsettings,
)
)
rp = os_path.realpath("/usr/bin/xz")
cprint("realpath: %s\n" % rp)
if not os_path.exists("/usr/bin/xz") or rp.startswith("/bin/busybox"):
self.list.append(
getConfigListEntry("xz " + _("Installation"), config.plugins.dbackup.xz)
)
if not os_path.exists("/usr/bin/pixz"):
self.list.append(
getConfigListEntry(
"pixz " + _("Installation"), config.plugins.dbackup.pixz
)
)
if not os_path.exists("/bin/pigz"):
self.list.append(
getConfigListEntry(
"pigz " + _("Installation"), config.plugins.dbackup.pigz
)
)
if not os_path.exists("/usr/bin/pbzip2"):
self.list.append(
getConfigListEntry(
"bpzip2 " + _("Installation"), config.plugins.dbackup.pbzip2
)
)
self.list.append(
getConfigListEntry(
_("Date in backupname"), config.plugins.gutemine.backupdate
)
)
self.list.append(
getConfigListEntry(
_("Time in backupname"), config.plugins.gutemine.backuptime
)
)
self.list.append(getConfigListEntry(_("Prefix"), config.plugins.dbackup.prefix))
self.list.append(getConfigListEntry(_("Length"), config.plugins.dbackup.maxlen))
self.list.append(
getConfigListEntry(
_("Check")
+ " "
+ _("latest")
+ " "
+ _("Backup")
+ " ["
+ _("days")
+ "]",
config.plugins.dbackup.latestbackup,
)
)
if int(config.plugins.dbackup.latestbackup.value) > 0:
self.list.append(
getConfigListEntry(
_("automatic") + " " + _("Backup"), config.plugins.dbackup.automatic
)
)
self.list.append(
getConfigListEntry(
_("automatic cleanup (max. number of backups)"),
config.plugins.dbackup.cleanlastbackup,
)
)
# self.list.append(getConfigListEntry(_("Clean apt cache before backup"), config.plugins.dbackup.aptclean))
self.list.append(
getConfigListEntry(
_("Fading Time") + " [" + _("seconds") + "]", config.plugins.dbackup.fadetime
)
)
if int(config.plugins.dbackup.fadetime.value) > 0:
self.list.append(
getConfigListEntry(
_("Fading Transparency"),
config.plugins.dbackup.transparency,
)
)
self.list.append(
getConfigListEntry(
_("Show plugin") + " " + _("Settings"),
config.plugins.dbackup.showinsettings,
)
)
self.list.append(
getConfigListEntry(
_("Show plugin") + " " + _("Extension"),
config.plugins.dbackup.showinextensions,
)
)
self.list.append(
getConfigListEntry(
_("Show plugin") + " " + _("Pluginlist"),
config.plugins.dbackup.showinplugins,
)
)
if self.boxtype != "dreamone":
self.list.append(
getConfigListEntry(_("Display"), config.plugins.dbackup.displayentry)
)
if os_path.exists("/var/lib/dpkg/status"):
self.list.append(
getConfigListEntry(_("Recovery Mode"), config.plugins.dbackup.recovering)
)
self.list.append(
getConfigListEntry(_("Webinterface"), config.plugins.dbackup.webinterface)
)
if gm.isgpt():
self.list.append(("%s %s" % ("u-boot ", setup_string),))
self.list.append(
getConfigListEntry(_("Timeout")+ " [" + _("seconds") + "]", config.plugins.uboot.timeout)
)
self.list.append(
getConfigListEntry(_("Default"), config.plugins.uboot.image)
)
self.list.append(
getConfigListEntry(_("Font"), config.plugins.uboot.font)
)
self.list.append(
getConfigListEntry(_("Details"), config.plugins.uboot.details)
)
# self.list.append(
# getConfigListEntry(_("Repeat"), config.plugins.uboot.repeat)
# )
# self.list.append(
# getConfigListEntry(_("SD Card"), config.plugins.uboot.sdcard)
# )
self.list.append(
getConfigListEntry(_("Lock-up"), config.plugins.uboot.lock)
)
self.list.append(
getConfigListEntry(
_("Enter Backup Imagename"), config.plugins.uboot.naming
)
)
self.list.append(
getConfigListEntry(_("Preview"), config.plugins.uboot.preview)
)
# saving is now part of preview
# self.list.append(
# getConfigListEntry(
# _("overwrite ?").replace("?",""), config.plugins.uboot.menu
# )
# )
self["config"].list = self.list
self["config"].l.setList(self.list)
def changedEntry(self):
choice = self["config"].getCurrent()
current = choice[1]
prefix = config.plugins.dbackup.prefix
if not choice == None:
if current != prefix:
self.createSetup()
def setWindowTitle(self):
self["logo"].instance.setPixmapFromFile("%s/dbackup.png" % dbackup_plugindir)
self.setTitle(
setup_string
+ " "
+ backup_string
+ " & "
+ flashing_string
+ " %s @ %s " % (dbackup_version,self.boxtype)
)
def textPressed(self):
cur = self["config"].getCurrentIndex()
current = self["config"].getCurrent()
cprint(">>> textPressed()")
# only call virtual keyboard when needed ...
if current[1] == config.plugins.dbackup.prefix:
self.KeyText()
def KeyText(self):
from Screens.VirtualKeyBoard import VirtualKeyBoard
self.currentConfigIndex = self["config"].getCurrentIndex()
self.session.openWithCallback(
self.VirtualKeyBoardCallback,
VirtualKeyBoard,
title=self["config"].getCurrent()[0],
text=self["config"].getCurrent()[1].getValue(),
)
def VirtualKeyBoardCallback(self, callback=None):
if callback != None and len(callback):
if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(
self["config"].getCurrent()[1], ConfigPassword
):
if "HelpWindow" in self:
if self["config"].getCurrent()[1].help_window.instance != None:
helpwindowpos = self["HelpWindow"].getPosition()
from enigma import ePoint
self["config"].getCurrent()[1].help_window.instance.move(
ePoint(helpwindowpos[0], helpwindowpos[1])
)
self["config"].instance.moveSelectionTo(self.currentConfigIndex)
self["config"].setCurrentIndex(self.currentConfigIndex)
self["config"].getCurrent()[1].setValue(callback)
self["config"].invalidate(self["config"].getCurrent())
def okPressed(self):
cur = self["config"].getCurrentIndex()
current = self["config"].getCurrent()
# print(current[1])
if self.install == "update":
text = _("Trying to download a new packetlist. Please wait...")
self.session.open(MessageBox, text, MessageBox.TYPE_WARNING, timeout=3)
return
if current[1] == config.plugins.dbackup.tar:
self.install = "tar"
cprint("install tar")
if os_path.exists("/var/lib/dpkg/status"):
cmd = "apt-get -f -y install tar"
else:
cmd = "opkg install tar"
self.aptInstall.execute(cmd)
elif current[1] == config.plugins.dbackup.xz:
self.install = "xz"
cprint("install xz")
if os_path.exists("/var/lib/dpkg/status"):
cmd = "apt-get -f -y install xz"
else:
cmd = "opkg install xz"
self.aptInstall.execute(cmd)
elif current[1] == config.plugins.dbackup.pixz:
self.install = "pixz"
cprint("install pixz")
if os_path.exists("/var/lib/dpkg/status"):
cmd = "apt-get -f -y install pixz"
else:
cmd = "opkg install pixz"
self.aptInstall.execute(cmd)
elif current[1] == config.plugins.dbackup.pigz:
self.install = "pigz"
cprint("install pigz")
if os_path.exists("/var/lib/dpkg/status"):
cmd = "apt-get -f -y install pigz"
else:
cmd = "opkg install pigz"
self.aptInstall.execute(cmd)
elif current[1] == config.plugins.dbackup.pbzip2:
self.install = "pbzip2"
cprint("install pbzip2")
if os_path.exists("/var/lib/dpkg/status"):
cmd = "apt-get -f -y install pbzip2"
else:
cmd = "opkg install pbzip2"
self.aptInstall.execute(cmd)
elif current[1] == config.plugins.uboot.menu:
gm.ubootmenu(
int(config.plugins.uboot.timeout.value),
int(config.plugins.uboot.image.value),
int(config.plugins.uboot.font.value),
config.plugins.uboot.details.value,
config.plugins.uboot.naming.value,
config.plugins.uboot.lock.value
)
text="u-boot " + _("Menu")+" "+_("overwrite ?").replace("?","")+_("OK")
self.session.openWithCallback(
self.createSetup, MessageBox, text, MessageBox.TYPE_INFO, timeout=5
)
elif current[1] == config.plugins.uboot.preview:
# write u-boot flash boot menu to temporary bootconfig file
gm.ubootmenu(
int(config.plugins.uboot.timeout.value),
int(config.plugins.uboot.image.value),
int(config.plugins.uboot.font.value),
config.plugins.uboot.details.value,
config.plugins.uboot.naming.value,
config.plugins.uboot.lock.value,
dbackup_boottmp
)
text = (
_("u-Boot")
+ " "
+ _("Menu")
+ " "
+ _("Preview")
+ "\n\n"
+ ("OK")
+ ":\t"
+ _("overwrite ?").replace("?","")
+ "\n"
+ _("EXIT")
+ ":\t"
+ _("Exit")
+ "\n"
+ _("[ ]")
+ ":\t"
+ _("Screenshot")
)
self.session.openWithCallback(
self.showPreview,
MessageBox,
text,
)
def showPreview(self, status):
if status:
self.highPrioAction = None
self.session.open(dBackupPreview)
def aptInstallFinished(self, ret):
if self.install == "update":
cprint("update finished")
self.install = None
else:
text = _("Installation") + " " + self.install + " " + _("finished")
self.session.openWithCallback(
self.createSetup, MessageBox, text, MessageBox.TYPE_INFO, timeout=5
)
def save(self):
config.plugins.dbackup.fadetime.save()
if config.plugins.dbackup.transparency.value > config.av.osd_alpha.value:
# current transparency is maximum for faded transparency = no fading
config.plugins.dbackup.transparency.value = config.av.osd_alpha.value
config.plugins.dbackup.transparency.save()
if (
not config.plugins.dbackup.showinsettings.value
and not config.plugins.dbackup.showinplugins.value
and not config.plugins.dbackup.showinextensions.value
):
config.plugins.dbackup.showinplugins.value = True
config.plugins.dbackup.showinplugins.save()
config.plugins.dbackup.backuplocation.save()
if not os_path.exists("/usr/bin/xz"):
config.plugins.dbackup.backuptool.value = "tar.gz"
config.plugins.dbackup.backuptool.save()
config.plugins.gutemine.backupdate.save()
config.plugins.gutemine.backuptime.save()
name = gm.trim(
str(config.plugins.dbackup.prefix.value), 20, False, False, False
)
config.plugins.dbackup.prefix.value = name
for x in self["config"].list:
if len(x) > 1:
x[1].save()
if gm.isgpt():
gm.ubootmenu(
int(config.plugins.uboot.timeout.value),
int(config.plugins.uboot.image.value),
int(config.plugins.uboot.font.value),
config.plugins.uboot.details.value,
config.plugins.uboot.naming.value,
config.plugins.uboot.lock.value
)
# make sure everything is in settings file
configfile.save()
self.close(True)
def resetSettings(self):
cprint(">>> resetSettings")
for x in self["config"].list:
if len(x) > 1:
x[1].value = x[1].default
x[1].save()
self.createSetup()
def cancel(self):
for x in self["config"].list:
if len(x) > 1:
x[1].cancel()
self.close(False)
def disclaimer(self):
self.session.openWithCallback(
self.about,
MessageBox,
disclaimer_string + "\n" + support_string,
MessageBox.TYPE_WARNING,
)
def about(self, answer):
self.session.open(dBackupAbout)
class dBackupAbout(Screen):
if sz_w == 2560:
skin = """
<screen name="dBackupAbout" position="center,center" size="1440,700" title="About dBackup" >
<eLabel backgroundColor="grey" position="20,20" size="1400,2" />
<widget name="aboutdbackup" position="20,40" size="1400,60" halign="center" foregroundColor="yellow" font="Regular;48"/>
<eLabel backgroundColor="grey" position="20,120" size="1400,2" />
<ePixmap position="520,200" size="400,160" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/dBackup/dbackup.png"/>
<widget name="freefilesystem" position="20,100" size="480,440" valign="center" halign="center" font="Regular;48"/>
<widget name="freememory" position="940,100" size="480,440" valign="center" halign="center" font="Regular;48"/>
<eLabel backgroundColor="grey" position="20,580" size="1400,2" />
<widget backgroundColor="#9f1313" font="Regular;38" halign="center" name="buttonred" position="20,600" foregroundColor="white" shadowColor="black" shadowOffset="-3,-3" size="400,80" valign="center" />
<widget name="lights" position="540,600" size="360,60" alphatest="on" zPosition="1"/>
<widget backgroundColor="#1f771f" font="Regular;38" halign="center" name="buttongreen" position="1020,600" foregroundColor="white" shadowColor="black" shadowOffset="-3,-3" size="400,80" valign="center" />
</screen>"""
elif sz_w == 1920:
skin = """
<screen name="dBackupAbout" position="center,center" size="1200,500" title="About dBackup" >
<eLabel backgroundColor="grey" position="20,10" size="1160,1" />
<widget name="aboutdbackup" foregroundColor="yellow" position="20,30" size="1160,50" halign="center" font="Regular;36"/>
<eLabel backgroundColor="grey" position="20,100" size="1160,1" />
<ePixmap position="400,160" size="400,160" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/dBackup/dbackup.png"/>
<widget name="freefilesystem" position="50,110" size="300,260" valign="center" halign="center" font="Regular;32"/>
<widget name="freememory" position="850,110" size="300,260" valign="center" halign="center" font="Regular;32"/>
<eLabel backgroundColor="grey" position="20,410" size="1160,1" />
<widget backgroundColor="#9f1313" font="Regular;30" halign="center" name="buttonred" position="20,420" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="350,60" valign="center" />
<widget name="lights" position="480,420" size="240,40" alphatest="on" zPosition="1"/>
<widget backgroundColor="#1f771f" font="Regular;30" halign="center" name="buttongreen" position="830,420" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="350,60" valign="center" />
</screen>"""
else:
skin = """
<screen name="dBackupAbout" position="center,center" size="720,350" title="About dBackup" >
<eLabel backgroundColor="grey" position="10,10" size="700,1" />
<widget name="aboutdbackup" position="10,20" size="700,30" halign="center" foregroundColor="yellow" font="Regular;24"/>
<eLabel backgroundColor="grey" position="10,60" size="700,1" />
<ePixmap position="260,100" size="200,80" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/dBackup/dbackup.png"/>
<widget name="freefilesystem" position="10,50" size="240,220" valign="center" halign="center" font="Regular;24"/>
<widget name="freememory" position="470,50" size="240,220" valign="center" halign="center" font="Regular;24"/>
<eLabel backgroundColor="grey" position="10,290" size="700,1" />
<widget backgroundColor="#9f1313" font="Regular;19" halign="center" name="buttonred" position="10,300" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="200,40" valign="center" />
<widget name="lights" position="270,300" size="180,30" alphatest="on" zPosition="1"/>
<widget backgroundColor="#1f771f" font="Regular;19" halign="center" name="buttongreen" position="510,300" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="200,40" valign="center" />
</screen>"""
def __init__(self, session, args=0):
Screen.__init__(self, session)
self.onShown.append(self.setWindowTitle)
st = os_statvfs("/")
free = st.f_bavail * st.f_frsize // 1024 // 1024
total = st.f_blocks * st.f_frsize // 1024 // 1024
used = (st.f_blocks - st.f_bfree) * st.f_frsize // 1024 // 1024
freefilesystem = _(
"Root Filesystem\n\ntotal: %s MB\nused: %s MB\nfree: %s MB"
) % (total, used, free)
memfree = 0
memtotal = 0
memused = 0
fm = open("/proc/meminfo")
line = fm.readline()
sp = line.split()
memtotal = int(sp[1]) // 1024
line = fm.readline()
sp = line.split()
memfree = int(sp[1]) // 1024
fm.close()
memused = memtotal - memfree
freememory = _("Memory\n\ntotal: %i MB\nused: %i MB\nfree: %i MB") % (
memtotal,
memused,
memfree,
)
self["lights"] = Pixmap()
self["buttonred"] = Label(exit_string)
self["buttongreen"] = Label(_("OK"))
self["aboutdbackup"] = Label(plugin_string)
self["freefilesystem"] = Label(freefilesystem)
self["freememory"] = Label(freememory)
self["setupActions"] = ActionMap(
["SetupActions", "ColorActions"],
{
"green": self.cancel,
"red": self.cancel,
"yellow": self.cancel,
"blue": self.cancel,
"save": self.cancel,
"cancel": self.cancel,
"ok": self.cancel,
},
)
def setWindowTitle(self):
self.setTitle(_("About") + " dBackup")
gm.fury()
self["lights"].instance.setPixmapFromFile("/tmp/lights.svg")
def cancel(self):
self.close(False)
class dBackupPreview(Screen):
if sz_w == 2560:
skin = """
<screen position="center,center" size="2560,1440" title="u-Boot Preview" flags="wfNoBorder" backgroundColor="#FFFFFFFF">
<widget name="osdshot" position="0,0" size="2560,1440" alphatest="on" />
</screen>"""
elif sz_w == 1920:
skin = """
<screen position="center,center" size="1920,1080" title="u-Boot Preview" flags="wfNoBorder" backgroundColor="#FFFFFFFF">
<widget name="osdshot" position="0,0" size="1920,1080" alphatest="on" />
</screen>"""
else:
skin = """
<screen position="center,center" size="1280,720" title="u-Boot Preview" flags="wfNoBorder" backgroundColor="#FFFFFFFF">
<widget name="osdshot" position="0,0" size="1280,720" alphatest="on" />
</screen>"""
def __init__(self, session):
self.skin = dBackupPreview.skin
self.setup_title = _("u-Boot") + " " + _("Preview")
Screen.__init__(self, session)
# explizit check on every entry
self.onChangedEntry = []
self.onConfigEntryChanged = []
self.session = session
self.altservice = session.nav.getCurrentlyPlayingServiceReference()
session.nav.stopService()
self["osdshot"] = Pixmap()
self["actions"] = ActionMap(
[
"WizardActions",
"SetupActions",
"MovieSelectionActions",
"InfobarTimeshiftActions",
],
{
"cancel": self.goBack,
"back": self.goBack,
"ok": self.goSaving,
"showEventInfo": self.goBack,
"timeshiftStop": self.osdShot,
},
-1,
)
self.onLayoutFinish.append(self.byLayoutEnd)
def goBack(self):
fbClass.getInstance().unlock()
self.session.nav.playService(self.altservice)
self.close(True)
def goSaving(self):
cprint("saving was confirmed")
gm.ubootmenu(
int(config.plugins.uboot.timeout.value),
int(config.plugins.uboot.image.value),
int(config.plugins.uboot.font.value),
config.plugins.uboot.details.value,
config.plugins.uboot.naming.value,
config.plugins.uboot.lock.value
)
self.goBack()
def byLayoutEnd(self):
fbClass.getInstance().lock()
cprint("showing: u-boot")
gm.showuboot(dbackup_boottmp)
def osdShot(self):
cprint("osdshot")
if os_path.exists("/tmp/osdshot.png"):
os_remove("/tmp/osdshot.png")
cprint("getting osdshot.png")
gm.osdshot()