added backup options

This commit is contained in:
DYefremov
2019-01-03 23:32:28 +03:00
parent 0a06b36f60
commit 3d34539c16
6 changed files with 130 additions and 33 deletions

View File

@@ -43,8 +43,9 @@ def get_default_settings():
"http_user": "root", "http_password": "", "http_port": "80", "http_timeout": 5,
"telnet_user": "root", "telnet_password": "", "telnet_port": "23", "telnet_timeout": 5,
"services_path": "/etc/enigma2/", "user_bouquet_path": "/etc/enigma2/",
"satellites_xml_path": "/etc/tuxbox/", "data_dir_path": DATA_PATH + "enigma2/",
"satellites_xml_path": "/etc/tuxbox/", "data_dir_path": DATA_PATH + "enigma2/",
"picons_path": "/usr/share/enigma2/picon", "picons_dir_path": DATA_PATH + "enigma2/picons/",
"backup_before_save": True, "backup_before_downloading": True,
"v5_support": False, "http_api_support": False,
"use_colors": True, "new_color": "rgb(255,230,204)", "extra_color": "rgb(179,230,204)"},
Profile.NEUTRINO_MP.value: {
@@ -53,7 +54,8 @@ def get_default_settings():
"telnet_user": "root", "telnet_password": "", "telnet_port": "23", "telnet_timeout": 1,
"services_path": "/var/tuxbox/config/zapit/", "user_bouquet_path": "/var/tuxbox/config/zapit/",
"satellites_xml_path": "/var/tuxbox/config/", "data_dir_path": DATA_PATH + "neutrino/",
"picons_path": "/usr/share/tuxbox/neutrino/icons/logo/", "picons_dir_path": DATA_PATH + "neutrino/picons/"},
"picons_path": "/usr/share/tuxbox/neutrino/icons/logo/", "picons_dir_path": DATA_PATH + "neutrino/picons/",
"backup_before_save": True, "backup_before_downloading": True},
"profile": Profile.ENIGMA_2.value}

View File

@@ -1,6 +1,7 @@
import os
import shutil
import tempfile
from datetime import datetime
from enum import Enum
from app.commons import run_idle
@@ -108,9 +109,7 @@ class BackupDialog:
try:
if restore_type is RestoreType.ALL:
for file in filter(lambda f: f != "satellites.xml" and os.path.isfile(os.path.join(self._data_path, f)),
os.listdir(self._data_path)):
os.remove(os.path.join(self._data_path, file))
clear_data_path(self._data_path)
shutil.unpack_archive(full_file_name, self._data_path)
elif restore_type is RestoreType.BOUQUETS:
tmp_dir = tempfile.gettempdir() + "/" + file_name
@@ -128,5 +127,23 @@ class BackupDialog:
self._open_data_callback(self._data_path)
def backup_data(path):
""" Creating data backup from a folder at the specified path """
backup_path = "{}backup/{}/".format(path, datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
os.makedirs(os.path.dirname(backup_path), exist_ok=True)
# backup files in data dir(skipping dirs and satellites.xml)
for file in filter(lambda f: f != "satellites.xml" and os.path.isfile(os.path.join(path, f)), os.listdir(path)):
shutil.move(os.path.join(path, file), backup_path + file)
# compressing to zip and delete remaining files
shutil.make_archive(backup_path, "zip", backup_path)
shutil.rmtree(backup_path)
def clear_data_path(path):
""" Clearing data at the specified path excluding satellites.xml file """
for file in filter(lambda f: f != "satellites.xml" and os.path.isfile(os.path.join(path, f)), os.listdir(path)):
os.remove(os.path.join(path, file))
if __name__ == "__main__":
pass

View File

@@ -3,6 +3,7 @@ from gi.repository import GLib
from app.commons import run_idle, run_task
from app.connections import download_data, DownloadType, upload_data
from app.properties import Profile, get_config
from app.ui.backup import backup_data
from app.ui.main_helper import append_text_to_tview
from app.ui.settings_dialog import show_settings_dialog
from .uicommons import Gtk, UI_RESOURCES_PATH, TEXT_DOMAIN
@@ -66,6 +67,9 @@ class DownloadDialog:
@run_idle
def on_receive(self, item):
if self._profile_properties.get("backup_before_downloading", True):
backup_data(self._profile_properties.get("data_dir_path", self._data_path_entry.get_text()))
self.download(True, self.get_download_type())
@run_idle

View File

@@ -1,9 +1,7 @@
import os
import shutil
import sys
from contextlib import suppress
from datetime import datetime
from functools import lru_cache
from gi.repository import GLib
@@ -17,7 +15,7 @@ from app.eparser.enigma.bouquets import BqServiceType
from app.eparser.neutrino.bouquets import BqType
from app.properties import get_config, write_config, Profile
from app.tools.media import Player
from app.ui.backup import BackupDialog
from app.ui.backup import BackupDialog, backup_data, clear_data_path
from .download_dialog import DownloadDialog
from .iptv import IptvDialog, SearchUnavailableDialog, IptvListConfigurationDialog
from .search import SearchProvider
@@ -877,15 +875,10 @@ class Application(Gtk.Application):
return
profile = Profile(self._profile)
path = self._options.get(self._profile).get("data_dir_path")
backup_path = "{}backup/{}/".format(path, datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
os.makedirs(os.path.dirname(backup_path), exist_ok=True)
# backup files in data dir(skipping dirs and satellites.xml)
for file in filter(lambda f: f != "satellites.xml" and os.path.isfile(os.path.join(path, f)), os.listdir(path)):
shutil.move(os.path.join(path, file), backup_path + file)
# compressing to zip and delete remaining files
shutil.make_archive(backup_path, "zip", backup_path)
shutil.rmtree(backup_path)
options = self._options.get(self._profile)
path = options.get("data_dir_path")
# Backup data or clearing data path
backup_data(path) if options.get("backup_before_save", True) else clear_data_path(path)
bouquets = []
@@ -1293,7 +1286,7 @@ class Application(Gtk.Application):
bq_services.append(ch.fav_id)
next(self.update_bouquet_services(self._fav_model, None, self._bq_selected), False)
# ***************** Backup tool ****************#
# ***************** Backup ********************#
def on_backup_tool_show(self, item):
""" Shows backup tool dialog """

View File

@@ -944,6 +944,7 @@ Author: Dmitriy Yefremov
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label_xalign">0.019999999552965164</property>
<property name="shadow_type">in</property>
@@ -1005,6 +1006,87 @@ Author: Dmitriy Yefremov
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="backup_frame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_bottom">5</property>
<property name="label_xalign">0.019999999552965164</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkGrid" id="backup_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_bottom">5</property>
<property name="row_spacing">5</property>
<property name="column_spacing">5</property>
<child>
<object class="GtkSwitch" id="before_save_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="before_downloading_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Before saving</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Before downloading from the receiver</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Backup:</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="program_box">
<property name="visible">True</property>
@@ -1033,14 +1115,14 @@ Author: Dmitriy Yefremov
<object class="GtkBox" id="set_color_switch_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">10</property>
<property name="margin_top">5</property>
<property name="spacing">5</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Set background color for the services</property>
<property name="xalign">1</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="expand">True</property>
@@ -1076,13 +1158,13 @@ Author: Dmitriy Yefremov
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="row_spacing">5</property>
<property name="column_spacing">5</property>
<property name="column_spacing">20</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Marked as new:</property>
<property name="xalign">1</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
@@ -1106,7 +1188,7 @@ Author: Dmitriy Yefremov
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">With an extra name in the bouquet:</property>
<property name="xalign">1</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
@@ -1132,9 +1214,6 @@ Author: Dmitriy Yefremov
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<child type="label_item">
@@ -1211,14 +1290,11 @@ Author: Dmitriy Yefremov
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>
@@ -1242,9 +1318,6 @@ Author: Dmitriy Yefremov
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<action-widgets>

View File

@@ -70,6 +70,8 @@ class SettingsDialog:
self._support_ver5_check_button = builder.get_object("support_ver5_check_button")
self._support_http_api_check_button = builder.get_object("support_http_api_check_button")
# Program
self._before_save_switch = builder.get_object("before_save_switch")
self._before_downloading_switch = builder.get_object("before_downloading_switch")
self._program_box = builder.get_object("program_box")
self._colors_grid = builder.get_object("colors_grid")
self._set_color_switch = builder.get_object("set_color_switch")
@@ -146,6 +148,9 @@ class SettingsDialog:
self._picons_field.set_text(options.get("picons_path", ""))
self._data_dir_field.set_text(options.get("data_dir_path", ""))
self._picons_dir_field.set_text(options.get("picons_dir_path", ""))
self._before_save_switch.set_active(options.get("backup_before_save", True))
self._before_downloading_switch.set_active(options.get("backup_before_downloading", True))
if Profile(self._active_profile) is Profile.ENIGMA_2:
self._support_ver5_check_button.set_active(options.get("v5_support", False))
self._support_http_api_check_button.set_active(options.get("http_api_support", False))
@@ -179,6 +184,9 @@ class SettingsDialog:
options["picons_path"] = self._picons_field.get_text()
options["data_dir_path"] = self._data_dir_field.get_text()
options["picons_dir_path"] = self._picons_dir_field.get_text()
options["backup_before_save"] = self._before_save_switch.get_active()
options["backup_before_downloading"] = self._before_downloading_switch.get_active()
if profile is Profile.ENIGMA_2:
options["v5_support"] = self._support_ver5_check_button.get_active()
options["http_api_support"] = self._support_http_api_check_button.get_active()