diff -r 4cad934aa9ce -r d72c4844e791 backup.py --- a/backup.py Fri Jan 19 14:42:27 2018 +0000 +++ b/backup.py Fri Jan 19 15:41:45 2018 +0000 @@ -3,9 +3,10 @@ # import config +import logging from instance import BorgInstance from queue import Queue -from threading import Thread +from threading import Thread, Lock class Backup: @@ -53,18 +54,42 @@ self.lastrun=None self.borg_instance=None self.thread=None + self.lock=Lock() def __block_when_running(self): - assert(self.borg_instance is None and self.thread is None) + self.lock.acquire() + not_running=self.borg_instance is None and self.thread is None + self.lock.release() + assert(not_running) def __listener(self): for status in iter(self.borg_instance.read, None): + t=status['type'] + if t=='progress_percent': + pass + elif t=='archive_progress': + pass + elif t=='progress_message': + pass + elif t=='progress_percent': + pass + elif t=='file_status': + pass + elif t=='log_message': + pass + elif t=='exception': + pass + elif t=='unparsed_error': + pass # What to do? print(status) - # What to do on error - # queue.put({'identifier': instance.identifier, - # 'operation': instance.operation, - # 'status': status}) + + logging.info('Borg subprocess finished; terminating listener thread') + + self.lock.acquire() + self.borg_instance=None + self.thread=None + self.lock.release() def __launch(self, queue, operation, archive_or_repository, *args): @@ -95,6 +120,15 @@ self.__launch(queue, 'prune', self.repository, [{'prefix': self.archive_prefix}] + self.prune_parameters) + # TODO: Decide exact (manual) abort mechanism. Perhaps two stages + def abort(self): + self.lock.acquire() + if self.borg_instance: + self.borg_instance.terminate() + if self.thread: + self.thread.terminate() + self.lock.release() + def join(self): if self.thread: self.thread.join()