diff --git a/app/properties.py b/app/properties.py index cebda5fb..a6f3a1a9 100644 --- a/app/properties.py +++ b/app/properties.py @@ -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} diff --git a/app/ui/backup.py b/app/ui/backup.py index 849ad0a8..8d27143c 100644 --- a/app/ui/backup.py +++ b/app/ui/backup.py @@ -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 diff --git a/app/ui/download_dialog.py b/app/ui/download_dialog.py index 40e0830b..c8d51050 100644 --- a/app/ui/download_dialog.py +++ b/app/ui/download_dialog.py @@ -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 diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index cb5abeff..11fd23d1 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -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 """ diff --git a/app/ui/settings_dialog.glade b/app/ui/settings_dialog.glade index 5d7ef959..3a10729d 100644 --- a/app/ui/settings_dialog.glade +++ b/app/ui/settings_dialog.glade @@ -944,6 +944,7 @@ Author: Dmitriy Yefremov False 5 5 + 5 5 0.019999999552965164 in @@ -1005,6 +1006,87 @@ Author: Dmitriy Yefremov 0 + + + True + False + 5 + 5 + 5 + 0.019999999552965164 + in + + + True + False + 5 + 5 + 5 + 5 + 5 + + + True + True + end + + + 1 + 0 + + + + + True + True + end + + + 1 + 1 + + + + + True + False + True + Before saving + 0 + + + 0 + 0 + + + + + True + False + Before downloading from the receiver + 0 + + + 0 + 1 + + + + + + + True + False + Backup: + + + + + False + True + 1 + + True @@ -1033,14 +1115,14 @@ Author: Dmitriy Yefremov True False - 10 + 5 5 True False Set background color for the services - 1 + 0 True @@ -1076,13 +1158,13 @@ Author: Dmitriy Yefremov 5 5 5 - 5 + 20 True False Marked as new: - 1 + 0 0 @@ -1106,7 +1188,7 @@ Author: Dmitriy Yefremov True False With an extra name in the bouquet: - 1 + 0 0 @@ -1132,9 +1214,6 @@ Author: Dmitriy Yefremov 1 - - - @@ -1211,14 +1290,11 @@ Author: Dmitriy Yefremov 1 - - - True True - 1 + 2 @@ -1242,9 +1318,6 @@ Author: Dmitriy Yefremov 0 - - - diff --git a/app/ui/settings_dialog.py b/app/ui/settings_dialog.py index 97322e6c..44386504 100644 --- a/app/ui/settings_dialog.py +++ b/app/ui/settings_dialog.py @@ -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()