make tests and build work again in usage using environment

this is such a crude hack it is totally embarrassing....

the proper solution would probably be to move the `build_parser()`
function out of `Archiver` completely, but this is such an undertaking
that i doubt it is worth doing since we're looking at switching to
click anyways.

the main problem in moving build_parser() out is that it references
`self` all the time, so it *needs* an archiver context that it can
reuse. we could make the function static and pass self in there by
hand, but it seems like almost a worse hack... and besides, we would
need to load the archiver in order to do that, which would break usage
all over again...
This commit is contained in:
Antoine Beaupré 2015-10-07 22:24:30 -04:00
parent 8fe56f001c
commit 9cbc868764
6 changed files with 21 additions and 14 deletions

View File

@ -12,9 +12,10 @@ import sys
import time
from io import BytesIO
from . import xattr
from .platform import acl_get, acl_set
from .chunker import Chunker
from .hashindex import ChunkIndex
if not os.environ.get('BORG_GEN_USAGE', False):
from .platform import acl_get, acl_set
from .chunker import Chunker
from .hashindex import ChunkIndex
from .helpers import parse_timestamp, Error, uid2user, user2uid, gid2group, group2gid, \
Manifest, Statistics, decode_dict, st_mtime_ns, make_path_safe, StableDict, int_to_bigint, bigint_to_int

View File

@ -15,12 +15,13 @@ import textwrap
import traceback
from . import __version__
if not os.environ.get('BORG_GEN_USAGE', False):
from .compress import Compressor, COMPR_BUFFER
from .upgrader import AtticRepositoryUpgrader
from .repository import Repository
from .cache import Cache
from .key import key_creator
from .archive import Archive, ArchiveChecker, CHUNKER_PARAMS
from .compress import Compressor, COMPR_BUFFER
from .upgrader import AtticRepositoryUpgrader
from .repository import Repository
from .cache import Cache
from .key import key_creator
from .helpers import Error, location_validator, format_time, format_file_size, \
format_file_mode, ExcludePattern, IncludePattern, exclude_path, adjust_patterns, to_localtime, timestamp, \
get_cache_dir, get_keys_dir, format_timedelta, prune_within, prune_split, \

View File

@ -18,9 +18,10 @@ from operator import attrgetter
import msgpack
from . import hashindex
from . import chunker
from . import crypto
if not os.environ.get('BORG_GEN_USAGE', False):
from . import hashindex
from . import chunker
from . import crypto
class Error(Exception):

View File

@ -7,8 +7,9 @@ import textwrap
import hmac
from hashlib import sha256
from .crypto import pbkdf2_sha256, get_random_bytes, AES, bytes_to_long, long_to_bytes, bytes_to_int, num_aes_blocks
from .compress import Compressor, COMPR_BUFFER
if not os.environ.get('BORG_GEN_USAGE', False):
from .crypto import pbkdf2_sha256, get_random_bytes, AES, bytes_to_long, long_to_bytes, bytes_to_int, num_aes_blocks
from .compress import Compressor, COMPR_BUFFER
from .helpers import IntegrityError, get_keys_dir, Error
PREFIX = b'\0' * 8

View File

@ -8,7 +8,8 @@ import struct
import sys
from zlib import crc32
from .hashindex import NSIndex
if not os.environ.get('BORG_GEN_USAGE', False):
from .hashindex import NSIndex
from .helpers import Error, IntegrityError, read_msgpack, write_msgpack, unhexlify
from .locking import UpgradableLock
from .lrucache import LRUCache

View File

@ -136,6 +136,8 @@ class build_usage(Command):
def run(self):
import pdb
print('generating usage docs')
# XXX: gross hack: allows us to skip loading C modules during help generation
os.environ['BORG_GEN_USAGE'] = "True"
from borg.archiver import Archiver
parser = Archiver().build_parser(prog='borg')
choices = {}