|
@@ -13,6 +13,7 @@ from ..helpers import bin_to_hex, prepare_dump_dict
|
|
from ..helpers import dash_open
|
|
from ..helpers import dash_open
|
|
from ..helpers import StableDict
|
|
from ..helpers import StableDict
|
|
from ..helpers import positive_int_validator, archivename_validator
|
|
from ..helpers import positive_int_validator, archivename_validator
|
|
|
|
+from ..helpers import CommandError, RTError
|
|
from ..manifest import Manifest
|
|
from ..manifest import Manifest
|
|
from ..platform import get_process_id
|
|
from ..platform import get_process_id
|
|
from ..repository import Repository, LIST_SCAN_LIMIT, TAG_PUT, TAG_DELETE, TAG_COMMIT
|
|
from ..repository import Repository, LIST_SCAN_LIMIT, TAG_PUT, TAG_DELETE, TAG_COMMIT
|
|
@@ -27,7 +28,6 @@ class DebugMixIn:
|
|
"""display system information for debugging / bug reports"""
|
|
"""display system information for debugging / bug reports"""
|
|
print(sysinfo())
|
|
print(sysinfo())
|
|
print("Process ID:", get_process_id())
|
|
print("Process ID:", get_process_id())
|
|
- return EXIT_SUCCESS
|
|
|
|
|
|
|
|
@with_repository(compatibility=Manifest.NO_OPERATION_CHECK)
|
|
@with_repository(compatibility=Manifest.NO_OPERATION_CHECK)
|
|
def do_debug_dump_archive_items(self, args, repository, manifest):
|
|
def do_debug_dump_archive_items(self, args, repository, manifest):
|
|
@@ -41,7 +41,6 @@ class DebugMixIn:
|
|
with open(filename, "wb") as fd:
|
|
with open(filename, "wb") as fd:
|
|
fd.write(data)
|
|
fd.write(data)
|
|
print("Done.")
|
|
print("Done.")
|
|
- return EXIT_SUCCESS
|
|
|
|
|
|
|
|
@with_repository(compatibility=Manifest.NO_OPERATION_CHECK)
|
|
@with_repository(compatibility=Manifest.NO_OPERATION_CHECK)
|
|
def do_debug_dump_archive(self, args, repository, manifest):
|
|
def do_debug_dump_archive(self, args, repository, manifest):
|
|
@@ -96,7 +95,6 @@ class DebugMixIn:
|
|
|
|
|
|
with dash_open(args.path, "w") as fd:
|
|
with dash_open(args.path, "w") as fd:
|
|
output(fd)
|
|
output(fd)
|
|
- return EXIT_SUCCESS
|
|
|
|
|
|
|
|
@with_repository(compatibility=Manifest.NO_OPERATION_CHECK)
|
|
@with_repository(compatibility=Manifest.NO_OPERATION_CHECK)
|
|
def do_debug_dump_manifest(self, args, repository, manifest):
|
|
def do_debug_dump_manifest(self, args, repository, manifest):
|
|
@@ -108,7 +106,6 @@ class DebugMixIn:
|
|
|
|
|
|
with dash_open(args.path, "w") as fd:
|
|
with dash_open(args.path, "w") as fd:
|
|
json.dump(meta, fd, indent=4)
|
|
json.dump(meta, fd, indent=4)
|
|
- return EXIT_SUCCESS
|
|
|
|
|
|
|
|
@with_repository(manifest=False)
|
|
@with_repository(manifest=False)
|
|
def do_debug_dump_repo_objs(self, args, repository):
|
|
def do_debug_dump_repo_objs(self, args, repository):
|
|
@@ -164,7 +161,6 @@ class DebugMixIn:
|
|
decrypt_dump(i, id, cdata)
|
|
decrypt_dump(i, id, cdata)
|
|
i += 1
|
|
i += 1
|
|
print("Done.")
|
|
print("Done.")
|
|
- return EXIT_SUCCESS
|
|
|
|
|
|
|
|
@with_repository(manifest=False)
|
|
@with_repository(manifest=False)
|
|
def do_debug_search_repo_objs(self, args, repository):
|
|
def do_debug_search_repo_objs(self, args, repository):
|
|
@@ -191,8 +187,7 @@ class DebugMixIn:
|
|
except (ValueError, UnicodeEncodeError):
|
|
except (ValueError, UnicodeEncodeError):
|
|
wanted = None
|
|
wanted = None
|
|
if not wanted:
|
|
if not wanted:
|
|
- self.print_error("search term needs to be hex:123abc or str:foobar style")
|
|
|
|
- return EXIT_ERROR
|
|
|
|
|
|
+ raise CommandError("search term needs to be hex:123abc or str:foobar style")
|
|
|
|
|
|
from ..crypto.key import key_factory
|
|
from ..crypto.key import key_factory
|
|
|
|
|
|
@@ -234,7 +229,6 @@ class DebugMixIn:
|
|
if i % 10000 == 0:
|
|
if i % 10000 == 0:
|
|
print("%d objects processed." % i)
|
|
print("%d objects processed." % i)
|
|
print("Done.")
|
|
print("Done.")
|
|
- return EXIT_SUCCESS
|
|
|
|
|
|
|
|
@with_repository(manifest=False)
|
|
@with_repository(manifest=False)
|
|
def do_debug_get_obj(self, args, repository):
|
|
def do_debug_get_obj(self, args, repository):
|
|
@@ -245,17 +239,14 @@ class DebugMixIn:
|
|
if len(id) != 32: # 256bit
|
|
if len(id) != 32: # 256bit
|
|
raise ValueError("id must be 256bits or 64 hex digits")
|
|
raise ValueError("id must be 256bits or 64 hex digits")
|
|
except ValueError as err:
|
|
except ValueError as err:
|
|
- print(f"object id {hex_id} is invalid [{str(err)}].")
|
|
|
|
- return EXIT_ERROR
|
|
|
|
|
|
+ raise CommandError(f"object id {hex_id} is invalid [{str(err)}].")
|
|
try:
|
|
try:
|
|
data = repository.get(id)
|
|
data = repository.get(id)
|
|
except Repository.ObjectNotFound:
|
|
except Repository.ObjectNotFound:
|
|
- print("object %s not found." % hex_id)
|
|
|
|
- return EXIT_ERROR
|
|
|
|
|
|
+ raise RTError("object %s not found." % hex_id)
|
|
with open(args.path, "wb") as f:
|
|
with open(args.path, "wb") as f:
|
|
f.write(data)
|
|
f.write(data)
|
|
print("object %s fetched." % hex_id)
|
|
print("object %s fetched." % hex_id)
|
|
- return EXIT_SUCCESS
|
|
|
|
|
|
|
|
@with_repository(compatibility=Manifest.NO_OPERATION_CHECK)
|
|
@with_repository(compatibility=Manifest.NO_OPERATION_CHECK)
|
|
def do_debug_id_hash(self, args, repository, manifest):
|
|
def do_debug_id_hash(self, args, repository, manifest):
|
|
@@ -265,7 +256,6 @@ class DebugMixIn:
|
|
key = manifest.key
|
|
key = manifest.key
|
|
id = key.id_hash(data)
|
|
id = key.id_hash(data)
|
|
print(id.hex())
|
|
print(id.hex())
|
|
- return EXIT_SUCCESS
|
|
|
|
|
|
|
|
@with_repository(compatibility=Manifest.NO_OPERATION_CHECK)
|
|
@with_repository(compatibility=Manifest.NO_OPERATION_CHECK)
|
|
def do_debug_parse_obj(self, args, repository, manifest):
|
|
def do_debug_parse_obj(self, args, repository, manifest):
|
|
@@ -278,8 +268,7 @@ class DebugMixIn:
|
|
if len(id) != 32: # 256bit
|
|
if len(id) != 32: # 256bit
|
|
raise ValueError("id must be 256bits or 64 hex digits")
|
|
raise ValueError("id must be 256bits or 64 hex digits")
|
|
except ValueError as err:
|
|
except ValueError as err:
|
|
- print(f"object id {hex_id} is invalid [{str(err)}].")
|
|
|
|
- return EXIT_ERROR
|
|
|
|
|
|
+ raise CommandError(f"object id {hex_id} is invalid [{str(err)}].")
|
|
|
|
|
|
with open(args.object_path, "rb") as f:
|
|
with open(args.object_path, "rb") as f:
|
|
cdata = f.read()
|
|
cdata = f.read()
|
|
@@ -293,8 +282,6 @@ class DebugMixIn:
|
|
with open(args.binary_path, "wb") as f:
|
|
with open(args.binary_path, "wb") as f:
|
|
f.write(data)
|
|
f.write(data)
|
|
|
|
|
|
- return EXIT_SUCCESS
|
|
|
|
-
|
|
|
|
@with_repository(compatibility=Manifest.NO_OPERATION_CHECK)
|
|
@with_repository(compatibility=Manifest.NO_OPERATION_CHECK)
|
|
def do_debug_format_obj(self, args, repository, manifest):
|
|
def do_debug_format_obj(self, args, repository, manifest):
|
|
"""format file and metadata into borg object file"""
|
|
"""format file and metadata into borg object file"""
|
|
@@ -306,8 +293,7 @@ class DebugMixIn:
|
|
if len(id) != 32: # 256bit
|
|
if len(id) != 32: # 256bit
|
|
raise ValueError("id must be 256bits or 64 hex digits")
|
|
raise ValueError("id must be 256bits or 64 hex digits")
|
|
except ValueError as err:
|
|
except ValueError as err:
|
|
- print(f"object id {hex_id} is invalid [{str(err)}].")
|
|
|
|
- return EXIT_ERROR
|
|
|
|
|
|
+ raise CommandError(f"object id {hex_id} is invalid [{str(err)}].")
|
|
|
|
|
|
with open(args.binary_path, "rb") as f:
|
|
with open(args.binary_path, "rb") as f:
|
|
data = f.read()
|
|
data = f.read()
|
|
@@ -321,7 +307,6 @@ class DebugMixIn:
|
|
|
|
|
|
with open(args.object_path, "wb") as f:
|
|
with open(args.object_path, "wb") as f:
|
|
f.write(data_encrypted)
|
|
f.write(data_encrypted)
|
|
- return EXIT_SUCCESS
|
|
|
|
|
|
|
|
@with_repository(manifest=False, exclusive=True)
|
|
@with_repository(manifest=False, exclusive=True)
|
|
def do_debug_put_obj(self, args, repository):
|
|
def do_debug_put_obj(self, args, repository):
|
|
@@ -334,12 +319,11 @@ class DebugMixIn:
|
|
if len(id) != 32: # 256bit
|
|
if len(id) != 32: # 256bit
|
|
raise ValueError("id must be 256bits or 64 hex digits")
|
|
raise ValueError("id must be 256bits or 64 hex digits")
|
|
except ValueError as err:
|
|
except ValueError as err:
|
|
- print(f"object id {hex_id} is invalid [{str(err)}].")
|
|
|
|
- return EXIT_ERROR
|
|
|
|
|
|
+ raise CommandError(f"object id {hex_id} is invalid [{str(err)}].")
|
|
|
|
+
|
|
repository.put(id, data)
|
|
repository.put(id, data)
|
|
print("object %s put." % hex_id)
|
|
print("object %s put." % hex_id)
|
|
repository.commit(compact=False)
|
|
repository.commit(compact=False)
|
|
- return EXIT_SUCCESS
|
|
|
|
|
|
|
|
@with_repository(manifest=False, exclusive=True)
|
|
@with_repository(manifest=False, exclusive=True)
|
|
def do_debug_delete_obj(self, args, repository):
|
|
def do_debug_delete_obj(self, args, repository):
|
|
@@ -360,7 +344,6 @@ class DebugMixIn:
|
|
if modified:
|
|
if modified:
|
|
repository.commit(compact=False)
|
|
repository.commit(compact=False)
|
|
print("Done.")
|
|
print("Done.")
|
|
- return EXIT_SUCCESS
|
|
|
|
|
|
|
|
@with_repository(manifest=False, exclusive=True, cache=True, compatibility=Manifest.NO_OPERATION_CHECK)
|
|
@with_repository(manifest=False, exclusive=True, cache=True, compatibility=Manifest.NO_OPERATION_CHECK)
|
|
def do_debug_refcount_obj(self, args, repository, manifest, cache):
|
|
def do_debug_refcount_obj(self, args, repository, manifest, cache):
|
|
@@ -376,7 +359,6 @@ class DebugMixIn:
|
|
print("object %s has %d referrers [info from chunks cache]." % (hex_id, refcount))
|
|
print("object %s has %d referrers [info from chunks cache]." % (hex_id, refcount))
|
|
except KeyError:
|
|
except KeyError:
|
|
print("object %s not found [info from chunks cache]." % hex_id)
|
|
print("object %s not found [info from chunks cache]." % hex_id)
|
|
- return EXIT_SUCCESS
|
|
|
|
|
|
|
|
@with_repository(manifest=False, exclusive=True)
|
|
@with_repository(manifest=False, exclusive=True)
|
|
def do_debug_dump_hints(self, args, repository):
|
|
def do_debug_dump_hints(self, args, repository):
|
|
@@ -394,7 +376,6 @@ class DebugMixIn:
|
|
json.dump(hints, fd, indent=4)
|
|
json.dump(hints, fd, indent=4)
|
|
finally:
|
|
finally:
|
|
repository.rollback()
|
|
repository.rollback()
|
|
- return EXIT_SUCCESS
|
|
|
|
|
|
|
|
def do_debug_convert_profile(self, args):
|
|
def do_debug_convert_profile(self, args):
|
|
"""convert Borg profile to Python profile"""
|
|
"""convert Borg profile to Python profile"""
|
|
@@ -402,7 +383,6 @@ class DebugMixIn:
|
|
|
|
|
|
with args.output, args.input:
|
|
with args.output, args.input:
|
|
marshal.dump(msgpack.unpack(args.input, use_list=False, raw=False), args.output)
|
|
marshal.dump(msgpack.unpack(args.input, use_list=False, raw=False), args.output)
|
|
- return EXIT_SUCCESS
|
|
|
|
|
|
|
|
def build_parser_debug(self, subparsers, common_parser, mid_common_parser):
|
|
def build_parser_debug(self, subparsers, common_parser, mid_common_parser):
|
|
debug_epilog = process_epilog(
|
|
debug_epilog = process_epilog(
|