Compare commits
No commits in common. "81d430b56b0ec8ff2ce6b03c6023adbde0c6697c" and "a540f4336f6778115cd52b5e9df20bb052dbfd16" have entirely different histories.
81d430b56b
...
a540f4336f
24
backup.py
24
backup.py
|
@ -15,7 +15,6 @@ import select
|
||||||
import pathlib
|
import pathlib
|
||||||
import threading
|
import threading
|
||||||
import subprocess
|
import subprocess
|
||||||
import _thread # for interrupt_main
|
|
||||||
|
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
@ -318,7 +317,10 @@ def main(argv: typing.List[str]):
|
||||||
for line in fh:
|
for line in fh:
|
||||||
try:
|
try:
|
||||||
data = json.loads(line)
|
data = json.loads(line)
|
||||||
if data['type'] == 'log_message':
|
if ((data['type'] == 'log_message' or
|
||||||
|
data['type'] == 'progress_message')
|
||||||
|
and 'message' in data):
|
||||||
|
|
||||||
# Count warnings and errors, but ignore some.
|
# Count warnings and errors, but ignore some.
|
||||||
changed_msg = "file changed while we backed it up"
|
changed_msg = "file changed while we backed it up"
|
||||||
if data['levelname'] == 'WARNING':
|
if data['levelname'] == 'WARNING':
|
||||||
|
@ -332,11 +334,6 @@ def main(argv: typing.List[str]):
|
||||||
prefix = ""
|
prefix = ""
|
||||||
|
|
||||||
line = (prefix + data['message'] + '\n').encode()
|
line = (prefix + data['message'] + '\n').encode()
|
||||||
|
|
||||||
elif (data['type'] == 'progress_message'
|
|
||||||
and 'message' in data):
|
|
||||||
line = (data['message'] + '\n').encode()
|
|
||||||
|
|
||||||
elif data['type'] == 'archive_progress':
|
elif data['type'] == 'archive_progress':
|
||||||
now = time.time()
|
now = time.time()
|
||||||
if now - last_progress > 10:
|
if now - last_progress > 10:
|
||||||
|
@ -356,20 +353,13 @@ def main(argv: typing.List[str]):
|
||||||
# ignore unknown progress line
|
# ignore unknown progress line
|
||||||
continue
|
continue
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# on error, print raw line with exception
|
# on error, print raw line
|
||||||
line = f"[exception: {str(e)} ]".encode() + line
|
pass
|
||||||
sys.stdout.buffer.write(line)
|
sys.stdout.buffer.write(line)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
captured_output.append(line)
|
captured_output.append(line)
|
||||||
fh.close()
|
fh.close()
|
||||||
def _reader_thread(fh):
|
reader = threading.Thread(target=reader_thread, args=(borg.stdout,))
|
||||||
try:
|
|
||||||
return reader_thread(fh)
|
|
||||||
except BrokenPipeError:
|
|
||||||
pass
|
|
||||||
except Exception:
|
|
||||||
_thread.interrupt_main()
|
|
||||||
reader = threading.Thread(target=_reader_thread, args=(borg.stdout,))
|
|
||||||
reader.daemon = True
|
reader.daemon = True
|
||||||
reader.start()
|
reader.start()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user