mirror of
https://github.com/c9moser/sgbackup.git
synced 2026-01-20 03:50:13 +00:00
2025.01.25 14:05:44
This commit is contained in:
parent
c256b50ac6
commit
2daf302e54
@ -17,9 +17,22 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
from ._archiver import Archiver,ArchiverManager
|
from ._archiver import Archiver,ArchiverManager
|
||||||
import importlib
|
#import importlib
|
||||||
|
import os
|
||||||
|
|
||||||
archiver = ArchiverManager()
|
_archiver = ArchiverManager.get_global()
|
||||||
|
_archiver_path= os.path.dirname(__file__)
|
||||||
|
for dirent in os.listdir(_archiver_path):
|
||||||
|
if dirent.startswith('.') or dirent.startswith('_'):
|
||||||
|
continue
|
||||||
|
if dirent.endswith('.py'):
|
||||||
|
module = dirent[0:-3]
|
||||||
|
exec("""
|
||||||
|
from . import {module}
|
||||||
|
if hasattr({module},"ARCHIVERS"):
|
||||||
|
for a in {module}.ARCHIVERS:
|
||||||
|
_archiver.archivers[a.key] = a
|
||||||
|
""".format(module=module))
|
||||||
|
|
||||||
__ALL__ = [
|
__ALL__ = [
|
||||||
"Archiver",
|
"Archiver",
|
||||||
|
|||||||
@ -32,8 +32,9 @@ import time
|
|||||||
from ..game import Game
|
from ..game import Game
|
||||||
from ..settings import settings
|
from ..settings import settings
|
||||||
|
|
||||||
class Archiver:
|
class Archiver(GObject):
|
||||||
def __init__(self,key:str,name:str,extensions:list[str],decription:str|None=None):
|
def __init__(self,key:str,name:str,extensions:list[str],decription:str|None=None):
|
||||||
|
GObject.__init__(self)
|
||||||
self.__key = key
|
self.__key = key
|
||||||
self.__name = name
|
self.__name = name
|
||||||
if decription:
|
if decription:
|
||||||
@ -59,23 +60,29 @@ class Archiver:
|
|||||||
def extensions(self)->list[str]:
|
def extensions(self)->list[str]:
|
||||||
return self.__extensions
|
return self.__extensions
|
||||||
|
|
||||||
|
def is_archive(self,filename):
|
||||||
|
for ext in self.extensions:
|
||||||
|
if filename.endswith(ext):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def backup(self,game:Game)->bool:
|
def backup(self,game:Game)->bool:
|
||||||
if not game.get_backup_files():
|
if not game.get_backup_files():
|
||||||
return
|
return
|
||||||
filename = self.generate_new_backup_filename()
|
filename = self.generate_new_backup_filename(game)
|
||||||
dirname = os.path.dirname(filename)
|
dirname = os.path.dirname(filename)
|
||||||
if not os.path.isdir(dirname):
|
if not os.path.isdir(dirname):
|
||||||
os.makedirs(dirname)
|
os.makedirs(dirname)
|
||||||
|
|
||||||
self.emit('backup',game,filename)
|
return self.emit('backup',game,filename)
|
||||||
|
|
||||||
def generate_new_backup_filename(self,game:Game)->str:
|
def generate_new_backup_filename(self,game:Game)->str:
|
||||||
dt = datetime.datetime.now()
|
dt = datetime.datetime.now()
|
||||||
basename = '.'.join(game.savegame_name,
|
basename = '.'.join((game.savegame_name,
|
||||||
game.savegame_subdir,
|
game.savegame_subdir,
|
||||||
dt.strftime("%Y%m%d-%H%M%S"),
|
dt.strftime("%Y%m%d-%H%M%S"),
|
||||||
"sgbackup",
|
"sgbackup",
|
||||||
self.extensions[0])
|
self.extensions[0][1:]))
|
||||||
return os.path.join(settings.backup_dir,game.savegame_name,game.subdir,basename)
|
return os.path.join(settings.backup_dir,game.savegame_name,game.subdir,basename)
|
||||||
|
|
||||||
def _backup_progress(self,game:Game,fraction:float,message:str|None):
|
def _backup_progress(self,game:Game,fraction:float,message:str|None):
|
||||||
@ -84,7 +91,7 @@ class Archiver:
|
|||||||
elif fraction < 0.0:
|
elif fraction < 0.0:
|
||||||
fraction = 0.0
|
fraction = 0.0
|
||||||
|
|
||||||
self.emit("progress",game,fraction,message)
|
self.emit("backup-progress",game,fraction,message)
|
||||||
|
|
||||||
|
|
||||||
@Signal(name="backup",flags=SignalFlags.RUN_FIRST,
|
@Signal(name="backup",flags=SignalFlags.RUN_FIRST,
|
||||||
@ -112,6 +119,7 @@ class ArchiverManager(GObject):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
GObject.__init__(self)
|
GObject.__init__(self)
|
||||||
self.__archivers = {}
|
self.__archivers = {}
|
||||||
|
self.__backup_in_progress = False
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -128,17 +136,29 @@ class ArchiverManager(GObject):
|
|||||||
except:
|
except:
|
||||||
return self.__archivers["zipfile"]
|
return self.__archivers["zipfile"]
|
||||||
|
|
||||||
|
@Property(type=bool,nick='backup-in-progress',default=False)
|
||||||
|
def backup_in_progress(self)->bool:
|
||||||
|
return self.__backup_in_progress
|
||||||
|
@backup_in_progress.setter
|
||||||
|
def backup_in_progress(self,b:bool):
|
||||||
|
self.__backup_in_progress = b
|
||||||
|
|
||||||
|
@property
|
||||||
|
def archivers(self):
|
||||||
|
return self.__archivers
|
||||||
|
|
||||||
def _on_archiver_backup_progress_single(self,archiver,game,fraction,message):
|
def _on_archiver_backup_progress_single(self,archiver,game,fraction,message):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _on_archiver_backup_progress_multi(self,archiver,game,fraction,message):
|
def _on_archiver_backup_progress_multi(self,archiver,game,fraction,message):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@Signal(name="backup-game-progress",return_type=None,arg_types=(Game,float,str),flags=SignalFlags.RUN_FIRST)
|
@Signal(name="backup-game-progress",return_type=None,arg_types=(Game,float,str),flags=SignalFlags.RUN_FIRST)
|
||||||
def do_backup_game_progress(self,game,fraction,message):
|
def do_backup_game_progress(self,game,fraction,message):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@Signal(name="backup-game-finished",return_type=None,arg_types=(Game,float,str),flags=SignalFlags.RUN_FIRST)
|
@Signal(name="backup-game-finished",return_type=None,arg_types=(Game,),flags=SignalFlags.RUN_FIRST)
|
||||||
def do_backup_game_finished(self,game:Game):
|
def do_backup_game_finished(self,game:Game):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -155,21 +175,27 @@ class ArchiverManager(GObject):
|
|||||||
self.emit("backup-game-progress",game,fraction,message)
|
self.emit("backup-game-progress",game,fraction,message)
|
||||||
self.emit("backup-progress",fraction)
|
self.emit("backup-progress",fraction)
|
||||||
|
|
||||||
|
if self.backup_in_progress:
|
||||||
|
raise RuntimeError("A backup is already in progress!!!")
|
||||||
|
|
||||||
|
self.backup_in_progress = True
|
||||||
|
|
||||||
archiver = self.standard_archiver
|
archiver = self.standard_archiver
|
||||||
backup_sc = archiver.connect('backup-progress',on_progress)
|
backup_sc = archiver.connect('backup-progress',on_progress)
|
||||||
archiver.backup(game)
|
archiver.backup(game)
|
||||||
archiver.disconnect(backup_sc)
|
archiver.disconnect(backup_sc)
|
||||||
self.emit("backup-game-finished",game)
|
self.emit("backup-game-finished",game)
|
||||||
self.emit("backup-finsihed")
|
self.emit("backup-finished")
|
||||||
|
self.backup_in_progress = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def backup_many(self,games:list[Game]):
|
def backup_many(self,games:list[Game]):
|
||||||
def thread_function(game):
|
def thread_function(game):
|
||||||
archiver = self.standard_archiver
|
archiver = self.standard_archiver
|
||||||
self._on_archiver_backup_progress_multi(archiver,game,1.0,"Finished ...")
|
self._on_archiver_backup_progress_multi(archiver,game,1.0,"Finished ...")
|
||||||
|
|
||||||
|
if self.backup_in_progress:
|
||||||
|
raise RuntimeError("A backup is already in progress!!!")
|
||||||
|
self.backup_in_progress = True
|
||||||
game_list = list(games)
|
game_list = list(games)
|
||||||
threadpool = {}
|
threadpool = {}
|
||||||
|
|
||||||
@ -200,5 +226,25 @@ class ArchiverManager(GObject):
|
|||||||
thread = threading.Thread(thread_function,args=game,daemon=True)
|
thread = threading.Thread(thread_function,args=game,daemon=True)
|
||||||
threadpool.append(thread)
|
threadpool.append(thread)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
self.backup_in_progress = False
|
||||||
|
|
||||||
|
def is_archive(self,filename)->bool:
|
||||||
|
if self.standard_archiver.is_archive(filename):
|
||||||
|
return True
|
||||||
|
for i in self.archivers.values():
|
||||||
|
if i.is_archive(filename):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_backups(self,game:Game):
|
||||||
|
ret = []
|
||||||
|
for backupdir in [os.path.join(settings.backup_dir,game.savegame_name,i) for i in ('live','finished')]:
|
||||||
|
if os.path.isdir(backupdir):
|
||||||
|
for basename in os.listdir(backupdir):
|
||||||
|
filename = os.path.join(backupdir,basename)
|
||||||
|
if (self.is_archive(filename)):
|
||||||
|
ret.append(filename)
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ import zipfile
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from ..game import Game,GameManager
|
from ..game import Game,GameManager
|
||||||
from settings import settings
|
from ..settings import settings
|
||||||
|
|
||||||
class ZipfileArchiver(Archiver):
|
class ZipfileArchiver(Archiver):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -32,7 +32,7 @@ class ZipfileArchiver(Archiver):
|
|||||||
|
|
||||||
self._backup_progress(game,0.0,"Starting {game} ...".format(game=game.name))
|
self._backup_progress(game,0.0,"Starting {game} ...".format(game=game.name))
|
||||||
files = game.get_backup_files()
|
files = game.get_backup_files()
|
||||||
div = len(files + 2)
|
div = len(files) + 2
|
||||||
cnt=1
|
cnt=1
|
||||||
game_data = json.dumps(game.serialize(),ensure_ascii=False,indent=4)
|
game_data = json.dumps(game.serialize(),ensure_ascii=False,indent=4)
|
||||||
with zipfile.ZipFile(filename,mode="w",
|
with zipfile.ZipFile(filename,mode="w",
|
||||||
@ -45,20 +45,19 @@ class ZipfileArchiver(Archiver):
|
|||||||
self._backup_progress(game,_calc_fraction(div,cnt),"{} -> {}".format(game.name,arcname))
|
self._backup_progress(game,_calc_fraction(div,cnt),"{} -> {}".format(game.name,arcname))
|
||||||
zf.write(path,arcname)
|
zf.write(path,arcname)
|
||||||
|
|
||||||
self._backup_progress("{game} ... FINISHED".format(game=game.name))
|
self._backup_progress(game,1.0,"{game} ... FINISHED".format(game=game.name))
|
||||||
|
|
||||||
|
|
||||||
def is_archive(self,filename:str)->bool:
|
def is_archive(self,filename:str)->bool:
|
||||||
if zipfile.is_zipfile(filename):
|
if zipfile.is_zipfile(filename):
|
||||||
with zipfile.ZipFile(filename,"r") as zf:
|
with zipfile.ZipFile(filename,"r") as zf:
|
||||||
if 'game.conf' in zf.filelist():
|
if 'gameconf.json' in [i.filename for i in zf.filelist]:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def do_restore(self,filename:str):
|
def do_restore(self,filename:str):
|
||||||
# TODO: convert savegame dir if not the same SvaegameType!!!
|
# TODO: convert savegame dir if not the same SvaegameType!!!
|
||||||
|
|
||||||
|
|
||||||
if not zipfile.is_zipfile(filename):
|
if not zipfile.is_zipfile(filename):
|
||||||
raise RuntimeError("\"{filename}\" is not a valid sgbackup zipfile archive!")
|
raise RuntimeError("\"{filename}\" is not a valid sgbackup zipfile archive!")
|
||||||
|
|
||||||
|
|||||||
@ -1151,6 +1151,13 @@ class Game(GObject):
|
|||||||
else:
|
else:
|
||||||
self.__variables = dict(vars)
|
self.__variables = dict(vars)
|
||||||
|
|
||||||
|
@Property(type=str)
|
||||||
|
def subdir(self):
|
||||||
|
if self.is_live:
|
||||||
|
return "live"
|
||||||
|
else:
|
||||||
|
return "finished"
|
||||||
|
|
||||||
@Property
|
@Property
|
||||||
def game_data(self):
|
def game_data(self):
|
||||||
sgtype = self.savegame_type
|
sgtype = self.savegame_type
|
||||||
@ -1367,7 +1374,10 @@ class Game(GObject):
|
|||||||
if self.game_data.match(fname):
|
if self.game_data.match(fname):
|
||||||
ret[str(path)] = os.path.join(sgdir,fname)
|
ret[str(path)] = os.path.join(sgdir,fname)
|
||||||
elif file_path.is_dir():
|
elif file_path.is_dir():
|
||||||
ret.update(get_backup_files_recursive(sgroot,sgdir,os.path.join(subdir,dirent)))
|
if subdir:
|
||||||
|
ret.update(get_backup_files_recursive(sgroot,sgdir,os.path.join(subdir,dirent)))
|
||||||
|
else:
|
||||||
|
ret.update(get_backup_files_recursive(sgroot,sgdir,dirent))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,9 @@ from ._settingsdialog import SettingsDialog
|
|||||||
from ._gamedialog import GameDialog
|
from ._gamedialog import GameDialog
|
||||||
from ..game import Game,GameManager,SAVEGAME_TYPE_ICONS
|
from ..game import Game,GameManager,SAVEGAME_TYPE_ICONS
|
||||||
from ._steam import SteamLibrariesDialog,NewSteamAppsDialog
|
from ._steam import SteamLibrariesDialog,NewSteamAppsDialog
|
||||||
|
from ._backupdialog import BackupSingleDialog
|
||||||
|
from ..archiver import ArchiverManager
|
||||||
|
|
||||||
|
|
||||||
__gtype_name__ = __name__
|
__gtype_name__ = __name__
|
||||||
|
|
||||||
@ -236,18 +239,21 @@ class GameView(Gtk.ScrolledWindow):
|
|||||||
def _on_actions_column_bind(self,action,item):
|
def _on_actions_column_bind(self,action,item):
|
||||||
child = item.get_child()
|
child = item.get_child()
|
||||||
game = item.get_item()
|
game = item.get_item()
|
||||||
|
archiver_manager = ArchiverManager.get_global()
|
||||||
child.backup_button.connect('clicked',self._on_columnview_backup_button_clicked,item)
|
child.backup_button.connect('clicked',self._on_columnview_backup_button_clicked,item)
|
||||||
child.edit_button.connect('clicked',self._on_columnview_edit_button_clicked,item)
|
child.edit_button.connect('clicked',self._on_columnview_edit_button_clicked,item)
|
||||||
child.remove_button.connect('clicked',self._on_columnview_remove_button_clicked,item)
|
child.remove_button.connect('clicked',self._on_columnview_remove_button_clicked,item)
|
||||||
|
archiver_manager.bind_property('backup-in-progress',child.backup_button,'sensitive',
|
||||||
|
BindingFlags.SYNC_CREATE,lambda binding,x: False if x else True)
|
||||||
|
archiver_manager.bind_property('backup-in-progress',child.edit_button,'sensitive',
|
||||||
|
BindingFlags.SYNC_CREATE,lambda binding,x: False if x else True)
|
||||||
|
archiver_manager.bind_property('backup-in-progress',child.remove_button,'sensitive',
|
||||||
|
BindingFlags.SYNC_CREATE,lambda binding,x: False if x else True)
|
||||||
|
|
||||||
def _on_columnview_backup_button_clicked(self,button,item):
|
def _on_columnview_backup_button_clicked(self,button,item):
|
||||||
def on_dialog_response(dialog,response):
|
|
||||||
dialog.hide()
|
|
||||||
dialog.destroy()
|
|
||||||
|
|
||||||
game = item.get_item()
|
game = item.get_item()
|
||||||
print('{}.{}._on_columnview_backup_button_clicked() -> {}'.format(__name__,__class__,game.name))
|
dialog = BackupSingleDialog(self.get_root(),game)
|
||||||
|
dialog.run()
|
||||||
|
|
||||||
def _on_columnview_edit_button_clicked(self,button,item):
|
def _on_columnview_edit_button_clicked(self,button,item):
|
||||||
def on_dialog_response(dialog,response):
|
def on_dialog_response(dialog,response):
|
||||||
@ -303,17 +309,17 @@ class BackupViewData(GObject):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,_game:Game,filename:str):
|
def __init__(self,_game:Game,filename:str):
|
||||||
GObject.GObject.__init__(self)
|
GObject.__init__(self)
|
||||||
self.__game = _game
|
self.__game = _game
|
||||||
self.__filename = filename
|
self.__filename = filename
|
||||||
|
|
||||||
basename = os.path.basename(filename)
|
basename = os.path.basename(filename)
|
||||||
self.__is_live = (os.path.basename(os.path.dirname(filename)) == 'live')
|
self.__is_live = (os.path.basename(os.path.dirname(filename)) == 'live')
|
||||||
parts = filename.split('.')
|
parts = basename.split('.')
|
||||||
self.__savegame_name = parts[0]
|
self.__savegame_name = parts[0]
|
||||||
self.__timestamp = DateTime.strptime(parts[1],"%Y%m%d-%H%M%S")
|
self.__timestamp = DateTime.strptime(parts[2],"%Y%m%d-%H%M%S")
|
||||||
|
|
||||||
self.__extension = '.' + parts[3:]
|
self.__extension = '.' + '.'.join(parts[3:])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def game(self)->Game:
|
def game(self)->Game:
|
||||||
@ -410,10 +416,16 @@ class BackupView(Gtk.Box):
|
|||||||
timestamp_factory.connect('bind',self._on_timestamp_column_bind)
|
timestamp_factory.connect('bind',self._on_timestamp_column_bind)
|
||||||
timestamp_column = Gtk.ColumnViewColumn.new("Timestamp",timestamp_factory)
|
timestamp_column = Gtk.ColumnViewColumn.new("Timestamp",timestamp_factory)
|
||||||
|
|
||||||
|
size_factory = Gtk.SignalListItemFactory()
|
||||||
|
size_factory.connect('setup',self._on_size_column_setup)
|
||||||
|
size_factory.connect('bind',self._on_size_column_bind)
|
||||||
|
size_column = Gtk.ColumnViewColumn.new("Size",size_factory)
|
||||||
|
|
||||||
self.__columnview = Gtk.ColumnView.new(selection)
|
self.__columnview = Gtk.ColumnView.new(selection)
|
||||||
self.__columnview.append_column(live_column)
|
self.__columnview.append_column(live_column)
|
||||||
self.__columnview.append_column(sgname_column)
|
self.__columnview.append_column(sgname_column)
|
||||||
self.__columnview.append_column(timestamp_column)
|
self.__columnview.append_column(timestamp_column)
|
||||||
|
self.__columnview.append_column(size_column)
|
||||||
self.__columnview.set_vexpand(True)
|
self.__columnview.set_vexpand(True)
|
||||||
|
|
||||||
self.gameview.columnview.connect('activate',self._on_gameview_columnview_activate)
|
self.gameview.columnview.connect('activate',self._on_gameview_columnview_activate)
|
||||||
@ -435,6 +447,7 @@ class BackupView(Gtk.Box):
|
|||||||
def _on_live_column_setup(self,factory,item):
|
def _on_live_column_setup(self,factory,item):
|
||||||
checkbutton = Gtk.CheckButton()
|
checkbutton = Gtk.CheckButton()
|
||||||
checkbutton.set_sensitive(False)
|
checkbutton.set_sensitive(False)
|
||||||
|
item.set_child(checkbutton)
|
||||||
|
|
||||||
def _on_live_column_bind(self,factory,item):
|
def _on_live_column_bind(self,factory,item):
|
||||||
checkbutton = item.get_child()
|
checkbutton = item.get_child()
|
||||||
@ -444,7 +457,7 @@ class BackupView(Gtk.Box):
|
|||||||
|
|
||||||
def _on_savegamename_column_setup(self,factory,item):
|
def _on_savegamename_column_setup(self,factory,item):
|
||||||
label = Gtk.Label()
|
label = Gtk.Label()
|
||||||
self.set_child(label)
|
item.set_child(label)
|
||||||
|
|
||||||
def _on_savegamename_column_bind(self,factory,item):
|
def _on_savegamename_column_bind(self,factory,item):
|
||||||
label = item.get_child()
|
label = item.get_child()
|
||||||
@ -490,6 +503,13 @@ class BackupView(Gtk.Box):
|
|||||||
|
|
||||||
self._title_label.set_markup("<span size='large' weight='bold'>{}</span>".format(GLib.markup_escape_text(game.name)))
|
self._title_label.set_markup("<span size='large' weight='bold'>{}</span>".format(GLib.markup_escape_text(game.name)))
|
||||||
|
|
||||||
|
self.__liststore.remove_all()
|
||||||
|
for bf in ArchiverManager.get_global().get_backups(game):
|
||||||
|
try:
|
||||||
|
self.__liststore.append(BackupViewData(game,bf))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AppWindow(Gtk.ApplicationWindow):
|
class AppWindow(Gtk.ApplicationWindow):
|
||||||
|
|||||||
@ -16,7 +16,68 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
from gi.repository import Gtk,GLib
|
||||||
from ..game import GameManager,Game
|
from ..game import GameManager,Game
|
||||||
from ..archiver import ArchiverManager
|
from ..archiver import ArchiverManager
|
||||||
|
from threading import Thread,ThreadError
|
||||||
|
|
||||||
|
class BackupSingleDialog(Gtk.Dialog):
|
||||||
|
def __init__(self,parent:Gtk.Window,game:Game):
|
||||||
|
Gtk.Dialog.__init__(self)
|
||||||
|
self.set_title("sgbackup: Backup -> {game}".format(game=game.name))
|
||||||
|
self.set_decorated(False)
|
||||||
|
self.__game = game
|
||||||
|
|
||||||
|
self.set_transient_for(parent)
|
||||||
|
|
||||||
|
self.__progressbar = Gtk.ProgressBar()
|
||||||
|
self.__progressbar.set_text("Starting savegame backup ...")
|
||||||
|
self.__progressbar.set_fraction(0.0)
|
||||||
|
|
||||||
|
self.get_content_area().append(self.__progressbar)
|
||||||
|
self.set_modal(False)
|
||||||
|
|
||||||
|
self.__am_signal_progress = None
|
||||||
|
self.__am_signal_finished = None
|
||||||
|
|
||||||
|
|
||||||
|
def _on_propgress(self,fraction,message):
|
||||||
|
self.__progressbar.set_text(message if message else "Working ...")
|
||||||
|
self.__progressbar.set_fraction(fraction)
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _on_finished(self):
|
||||||
|
self.__progressbar.set_text("Finished ...")
|
||||||
|
self.__progressbar.set_fraction(1.0)
|
||||||
|
am = ArchiverManager.get_global()
|
||||||
|
if self.__am_signal_finished is not None:
|
||||||
|
am.disconnect(self.__am_signal_finished)
|
||||||
|
self.__am_signal_finished = None
|
||||||
|
|
||||||
|
if self.__am_signal_progress is not None:
|
||||||
|
am.disconnect(self.__am_signal_progress)
|
||||||
|
self.__am_signal_progress = None
|
||||||
|
|
||||||
|
self.hide()
|
||||||
|
self.destroy()
|
||||||
|
|
||||||
|
def _on_am_backup_game_progress(self,am,game,fraction,message):
|
||||||
|
if self.__game.key == game.key:
|
||||||
|
GLib.idle_add(self._on_propgress,fraction,message)
|
||||||
|
|
||||||
|
def _on_am_backup_game_finished(self,am,game):
|
||||||
|
if self.__game.key == game.key:
|
||||||
|
GLib.idle_add(self._on_finished)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
def _thread_func(archiver_manager,game):
|
||||||
|
am.backup(game)
|
||||||
|
|
||||||
|
self.present()
|
||||||
|
|
||||||
|
am = ArchiverManager.get_global()
|
||||||
|
self.__am_signal_progress = am.connect('backup-game-progress',self._on_am_backup_game_progress)
|
||||||
|
self.__am_signal_finished = am.connect('backup-game-finished',self._on_am_backup_game_finished)
|
||||||
|
thread = Thread(target=_thread_func,args=(am,self.__game),daemon=True)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
|||||||
@ -87,6 +87,7 @@ class Settings(GObject.GObject):
|
|||||||
return self.__logger_conf
|
return self.__logger_conf
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@GObject.Property(type=str,nick="backup-dir")
|
@GObject.Property(type=str,nick="backup-dir")
|
||||||
def backup_dir(self)->str:
|
def backup_dir(self)->str:
|
||||||
if self.parser.has_option('sgbackup','backupDirectory'):
|
if self.parser.has_option('sgbackup','backupDirectory'):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user