mirror of https://github.com/borgbackup/borg.git
Add return code functions (#2199)
This commit is contained in:
parent
89114d4885
commit
4b33c3fe14
|
@ -36,7 +36,7 @@ from .cache import Cache
|
|||
from .constants import * # NOQA
|
||||
from .crc32 import crc32
|
||||
from .helpers import EXIT_SUCCESS, EXIT_WARNING, EXIT_ERROR
|
||||
from .helpers import Error, NoManifestError
|
||||
from .helpers import Error, NoManifestError, set_ec
|
||||
from .helpers import location_validator, archivename_validator, ChunkerParams, CompressionSpec
|
||||
from .helpers import PrefixSpec, SortBySpec, HUMAN_SORT_KEYS
|
||||
from .helpers import BaseFormatter, ItemFormatter, ArchiveFormatter
|
||||
|
@ -3372,7 +3372,7 @@ class Archiver:
|
|||
self.prerun_checks(logger)
|
||||
if is_slow_msgpack():
|
||||
logger.warning("Using a pure-python msgpack! This will result in lower performance.")
|
||||
return func(args)
|
||||
return set_ec(func(args))
|
||||
|
||||
|
||||
def sig_info_handler(sig_no, stack): # pragma: no cover
|
||||
|
|
|
@ -52,6 +52,26 @@ def Chunk(data, **meta):
|
|||
return _Chunk(meta, data)
|
||||
|
||||
|
||||
'''
|
||||
The global exit_code variable is used so that modules other than archiver can increase the program exit code if a
|
||||
warning or error occured during their operation. This is different from archiver.exit_code, which is only accessible
|
||||
from the archiver object.
|
||||
'''
|
||||
exit_code = EXIT_SUCCESS
|
||||
|
||||
|
||||
def set_ec(ec):
|
||||
'''
|
||||
Sets the exit code of the program, if an exit code higher or equal than this is set, this does nothing. This
|
||||
makes EXIT_ERROR override EXIT_WARNING, etc..
|
||||
|
||||
ec: exit code to set
|
||||
'''
|
||||
global exit_code
|
||||
exit_code = max(exit_code, ec)
|
||||
return exit_code
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
"""Error base class"""
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ def exec_cmd(*args, archiver=None, fork=False, exe=None, **kw):
|
|||
archiver = Archiver()
|
||||
archiver.prerun_checks = lambda *args: None
|
||||
archiver.exit_code = EXIT_SUCCESS
|
||||
helpers.exit_code = EXIT_SUCCESS
|
||||
try:
|
||||
args = archiver.parse_args(list(args))
|
||||
# argparse parsing may raise SystemExit when the command line is bad or
|
||||
|
|
Loading…
Reference in New Issue