@@ -53,7 +53,7 @@ def process_result(self, result):
5353 self .app .backup_log_event .emit ('' , {})
5454 self .app .backup_progress_event .emit (f"[{ self .params ['profile_name' ]} ] { self .tr ('Backup finished.' )} " )
5555
56- def progress_event (self , fmt ):
56+ def progress_event (self , fmt = None ):
5757 self .app .backup_progress_event .emit (f"[{ self .params ['profile_name' ]} ] { fmt } " )
5858
5959 def started_event (self ):
@@ -63,26 +63,34 @@ def started_event(self):
6363 def finished_event (self , result ):
6464 self .app .backup_finished_event .emit (result )
6565 self .result .emit (result )
66- self .pre_post_backup_cmd (self .params , cmd = 'post_backup_cmd' , returncode = result ['returncode' ])
66+ self .pre_post_backup_cmd (self .params , context = 'post_backup_cmd' , app = self . app , returncode = result ['returncode' ])
6767
6868 @classmethod
69- def pre_post_backup_cmd (cls , params , cmd = 'pre_backup_cmd' , returncode = 0 ):
70- cmd = getattr (params ['profile' ], cmd )
69+ def pre_post_backup_cmd (cls , params , context = 'pre_backup_cmd' , app = None , returncode = 0 ):
70+ cmd = getattr (params ['profile' ], context )
7171 if cmd :
72+ profile_name = getattr (params ['profile' ], 'name' )
7273 env = {
7374 ** os .environ .copy (),
7475 'repo_url' : params ['repo' ].url ,
7576 'profile_name' : params ['profile' ].name ,
7677 'profile_slug' : params ['profile' ].slug (),
7778 'returncode' : str (returncode ),
7879 }
79- proc = subprocess .run (cmd , shell = True , env = env )
80+ proc = subprocess .Popen (cmd , shell = True , env = env )
81+ if context .startswith ('pre' ):
82+ app .backup_progress_event .emit (f"[{ profile_name } ] { trans_late ('messages' , 'Waiting to start backup' )} " )
83+ app .pre_backup_event .emit (proc .pid )
84+ else :
85+ app .post_backup_event .emit (proc .pid , True )
86+ proc .wait ()
87+ app .post_backup_event .emit (None , False )
8088 return proc .returncode
8189 else :
8290 return 0 # 0 if no command was run.
8391
8492 @classmethod
85- def prepare (cls , profile ):
93+ def prepare (cls , profile , app = None ):
8694 """
8795 `borg create` is called from different places and needs some preparation.
8896 Centralize it here and return the required arguments to the caller.
@@ -133,7 +141,7 @@ def prepare(cls, profile):
133141 ret ['repo' ] = profile .repo
134142
135143 # Run user-supplied pre-backup command
136- if cls .pre_post_backup_cmd (ret ) != 0 :
144+ if cls .pre_post_backup_cmd (ret , app = app ) != 0 :
137145 ret ['message' ] = trans_late ('messages' , 'Pre-backup command returned non-zero exit code.' )
138146 return ret
139147
0 commit comments