|
|
|
@ -4,11 +4,14 @@ import os
|
|
|
|
|
import select
|
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
from borgmatic.commands import warning
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ERROR_OUTPUT_MAX_LINE_COUNT = 25
|
|
|
|
|
BORG_ERROR_EXIT_CODE = 2
|
|
|
|
|
BORG_WARNING_EXIT_CODE = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def exit_code_indicates_error(command, exit_code, borg_local_path=None):
|
|
|
|
@ -26,6 +29,21 @@ def exit_code_indicates_error(command, exit_code, borg_local_path=None):
|
|
|
|
|
return bool(exit_code != 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def exit_code_indicates_borg_warning(process, exit_code, borg_local_path=None):
|
|
|
|
|
'''
|
|
|
|
|
Return True if the given exit code from running a borg command corresponds to an borg warning.
|
|
|
|
|
'''
|
|
|
|
|
if exit_code is None:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
command = process.args.split(' ') if isinstance(process.args, str) else process.args
|
|
|
|
|
|
|
|
|
|
if borg_local_path and command[0] == borg_local_path:
|
|
|
|
|
return bool(exit_code == BORG_WARNING_EXIT_CODE)
|
|
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def command_for_process(process):
|
|
|
|
|
'''
|
|
|
|
|
Given a process as an instance of subprocess.Popen, return the command string that was used to
|
|
|
|
@ -134,6 +152,10 @@ def log_outputs(processes, exclude_stdouts, output_log_level, borg_local_path):
|
|
|
|
|
still_running = True
|
|
|
|
|
|
|
|
|
|
command = process.args.split(' ') if isinstance(process.args, str) else process.args
|
|
|
|
|
|
|
|
|
|
if exit_code_indicates_borg_warning(process, exit_code, borg_local_path):
|
|
|
|
|
raise warning.BorgmaticWarning()
|
|
|
|
|
|
|
|
|
|
# If any process errors, then raise accordingly.
|
|
|
|
|
if exit_code_indicates_error(command, exit_code, borg_local_path):
|
|
|
|
|
# If an error occurs, include its output in the raised exception so that we don't
|
|
|
|
@ -227,6 +249,7 @@ def execute_command(
|
|
|
|
|
env=environment,
|
|
|
|
|
cwd=working_directory,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if not run_to_completion:
|
|
|
|
|
return process
|
|
|
|
|
|
|
|
|
|