def list_archives(repository, storage_config, list_arguments, local_path='borg', remote_path=None): ''' Given a local or remote repository path, a storage config dict, and the arguments to the list action, display the output of listing Borg archives in the repository or return JSON output. Or, if an archive name is given, listing the files in that archive. ''' lock_wait = storage_config.get('lock_wait', None) if list_arguments.successful: list_arguments.glob_archives = BORG_EXCLUDE_CHECKPOINTS_GLOB full_command = ( (local_path, 'list') + (('--info', ) if logger.getEffectiveLevel() == logging.INFO and not list_arguments.json else ()) + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) and not list_arguments.json else ()) + make_flags('remote-path', remote_path) + make_flags('lock-wait', lock_wait) + make_flags_from_arguments( list_arguments, excludes=('repository', 'archive', 'paths', 'successful')) + ('::'.join((repository, list_arguments.archive)) if list_arguments.archive else repository, ) + (tuple(list_arguments.paths) if list_arguments.paths else ())) return execute_command( full_command, output_log_level=None if list_arguments.json else logging.WARNING, error_on_warnings=False, )
def display_archives_info(repository, storage_config, info_arguments, local_path='borg', remote_path=None): ''' Given a local or remote repository path, a storage config dict, and the arguments to the info action, display summary information for Borg archives in the repository or return JSON summary information. ''' lock_wait = storage_config.get('lock_wait', None) full_command = ((local_path, 'info') + (('--info', ) if logger.getEffectiveLevel() == logging.INFO and not info_arguments.json else ()) + (('--debug', '--show-rc') if logger.isEnabledFor( logging.DEBUG) and not info_arguments.json else ()) + make_flags('remote-path', remote_path) + make_flags('lock-wait', lock_wait) + make_flags_from_arguments( info_arguments, excludes=('repository', 'archive')) + ('::'.join((repository, info_arguments.archive)) if info_arguments.archive else repository, )) return execute_command( full_command, output_log_level=None if info_arguments.json else logging.WARNING)
def test_make_flags_from_arguments_flattens_and_sorts_multiple_arguments(): flexmock(module).should_receive('make_flags').with_args('foo', 'bar').and_return(('foo', 'bar')) flexmock(module).should_receive('make_flags').with_args('baz', 'quux').and_return( ('baz', 'quux') ) arguments = flexmock(foo='bar', baz='quux') assert module.make_flags_from_arguments(arguments) == ('baz', 'quux', 'foo', 'bar')
def test_make_flags_from_arguments_omits_excludes(): flexmock(module).should_receive('make_flags').with_args('foo', 'bar').and_return(('foo', 'bar')) arguments = flexmock(foo='bar', baz='quux') assert module.make_flags_from_arguments(arguments, excludes=('baz', 'other')) == ('foo', 'bar')
def test_make_flags_from_arguments_excludes_underscored_argument_names(): flexmock(module).should_receive('make_flags').with_args('foo', 'bar').and_return(('foo', 'bar')) arguments = flexmock(foo='bar', _baz='quux') assert module.make_flags_from_arguments(arguments) == ('foo', 'bar')