data backup before save

This commit is contained in:
Dmitriy Yefremov
2018-02-01 14:02:59 +03:00
parent dbe18b345f
commit 2f8dcaf47b
3 changed files with 18 additions and 5 deletions

View File

@@ -2,6 +2,8 @@ import os
from contextlib import suppress
from functools import lru_cache
import shutil
from app.commons import run_idle, log
from app.eparser import get_blacklist, write_blacklist, parse_m3u
from app.eparser import get_services, get_bouquets, write_bouquets, write_services, Bouquets, Bouquet, Service
@@ -554,9 +556,11 @@ class MainAppWindow:
return
path = self.__options.get(self.__profile).get("data_dir_path")
# deleting files in data dir(skipping dirs) :)
list(map(os.unlink, (os.path.join(path, f) for f in filter(
lambda f: f != "satellites.xml" and os.path.isfile(os.path.join(path, f)), os.listdir(path)))))
backup_path = path + "backup/"
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)
bouquets = []
services_model = self.__services_view.get_model()

View File

@@ -3,6 +3,7 @@ from enum import Enum
import os
import shutil
from gi.repository import GdkPixbuf
from app.eparser import Service
@@ -304,8 +305,6 @@ def assign_picon(view, transient, options):
show_dialog(DialogType.ERROR, transient, text="No png file is selected!")
return
print(response)
def remove_picon(target, srv_view, fav_view, picons, options):
view = srv_view if target is ViewTarget.SERVICES else fav_view
@@ -315,6 +314,7 @@ def remove_picon(target, srv_view, fav_view, picons, options):
fav_ids = []
picon_ids = []
picon_pos = 8 # picon position is equal for services and fav
for path in paths:
itr = model.get_iter(path)
model.set_value(itr, picon_pos, None)
@@ -333,8 +333,15 @@ def remove_picon(target, srv_view, fav_view, picons, options):
fav_view.get_model().foreach(remove) if target is ViewTarget.SERVICES else get_base_model(
srv_view.get_model()).foreach(remove)
pions_path = options.get("picons_dir_path")
backup_path = options.get("data_dir_path") + "backup/picons/"
os.makedirs(os.path.dirname(backup_path), exist_ok=True)
for p_id in picon_ids:
picons[p_id] = None
src = pions_path + p_id
if os.path.isfile(src):
shutil.move(src, backup_path + p_id)
def copy_picon_reference(target, view, services, clipboard, transient):

View File

@@ -1199,9 +1199,11 @@
</child>
<child>
<object class="GtkSearchEntry" id="search_entry">
<property name="width_request">200</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="text" translatable="yes">Not implemented yet!</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>