Merge pull request #437 from anarcat/no-progress

fix --no-progress
This commit is contained in:
TW 2015-11-23 18:48:45 +01:00
commit f834e335f9
2 changed files with 49 additions and 13 deletions

View File

@ -35,6 +35,20 @@ from .remote import RepositoryServer, RemoteRepository
has_lchflags = hasattr(os, 'lchflags')
class ToggleAction(argparse.Action):
"""argparse action to handle "toggle" flags easily
toggle flags are in the form of ``--foo``, ``--no-foo``.
the ``--no-foo`` argument still needs to be passed to the
``add_argument()`` call, but it simplifies the ``--no``
detection.
"""
def __call__(self, parser, ns, values, option):
"""set the given flag to true unless ``--no`` is passed"""
setattr(ns, self.dest, not option.startswith('--no-'))
class Archiver:
def __init__(self, verbose=False, lock_wait=None):
@ -777,19 +791,6 @@ class Archiver:
See the output of the "borg help patterns" command for more help on exclude patterns.
""")
class ToggleAction(argparse.Action):
"""argparse action to handle "toggle" flags easily
toggle flags are in the form of ``--foo``, ``--no-foo``.
the ``--no-foo`` argument still needs to be passed to the
``add_argument()`` call, but it simplifies the ``--no``
detection.
"""
def __call__(self, parser, ns, values, option):
"""set the given flag to true unless ``--no`` is passed"""
setattr(ns, self.dest, option.startswith('--no-'))
subparser = subparsers.add_parser('create', parents=[common_parser],
description=self.do_create.__doc__,
epilog=create_epilog,

View File

@ -669,6 +669,41 @@ class ArchiverTestCase(ArchiverTestCaseBase):
manifest, key = Manifest.load(repository)
self.assert_equal(len(manifest.archives), 0)
def test_progress(self):
self.create_regular_file('file1', size=1024 * 80)
self.cmd('init', self.repository_location)
# progress forced on
output = self.cmd('create', '--progress', self.repository_location + '::test4', 'input')
self.assert_in("\r", output)
# progress forced off
output = self.cmd('create', '--no-progress', self.repository_location + '::test5', 'input')
self.assert_not_in("\r", output)
@unittest.skipUnless(sys.stdout.isatty(), 'need a tty to test auto-detection')
def test_progress_tty(self):
"""test that the --progress and --no-progress flags work,
overriding defaults from the terminal auto-detection"""
self.create_regular_file('file1', size=1024 * 80)
self.cmd('init', self.repository_location)
# without a terminal, no progress expected
output = self.cmd('create', self.repository_location + '::test1', 'input', fork=False)
self.assert_not_in("\r", output)
# with a terminal, progress expected
output = self.cmd('create', self.repository_location + '::test2', 'input', fork=True)
self.assert_in("\r", output)
# without a terminal, progress forced on
output = self.cmd('create', '--progress', self.repository_location + '::test3', 'input', fork=False)
self.assert_in("\r", output)
# with a terminal, progress forced on
output = self.cmd('create', '--progress', self.repository_location + '::test4', 'input', fork=True)
self.assert_in("\r", output)
# without a terminal, progress forced off
output = self.cmd('create', '--no-progress', self.repository_location + '::test5', 'input', fork=False)
self.assert_not_in("\r", output)
# with a terminal, progress forced off
output = self.cmd('create', '--no-progress', self.repository_location + '::test6', 'input', fork=True)
self.assert_not_in("\r", output)
def test_cmdline_compatibility(self):
self.create_regular_file('file1', size=1024 * 80)
self.cmd('init', self.repository_location)