mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-07 10:56:49 +00:00
Make --exclude-from behavior consistent, at the cost of a minor incompatibility.
This commit is contained in:
parent
69c8305ae8
commit
64f6ccd17f
@ -514,10 +514,10 @@ Command Examples
|
||||
the pattern will be matched against any level of the directory tree;
|
||||
it's still impossible to specify absolute path exclusions.
|
||||
|
||||
``tahoe backup --exclude-from=/path/to/filename ~ work:backups``
|
||||
``tahoe backup --exclude-from-utf-8=/path/to/filename ~ work:backups``
|
||||
|
||||
``--exclude-from`` is similar to ``--exclude``, but reads exclusion
|
||||
patterns from ``/path/to/filename``, one per line.
|
||||
``--exclude-from-utf-8`` is similar to ``--exclude``, but reads exclusion
|
||||
patterns from a UTF-8-encoded ``/path/to/filename``, one per line.
|
||||
|
||||
``tahoe backup --exclude-vcs ~ work:backups``
|
||||
|
||||
|
1
newsfragments/3716.incompat
Normal file
1
newsfragments/3716.incompat
Normal file
@ -0,0 +1 @@
|
||||
tahoe backup's --exclude-from has been renamed to --exclude-from-utf-8, and correspondingly requires the file to be UTF-8 encoded.
|
@ -357,17 +357,16 @@ class BackupOptions(FileStoreOptions):
|
||||
exclude = self['exclude']
|
||||
exclude.add(g)
|
||||
|
||||
def opt_exclude_from(self, filepath):
|
||||
def opt_exclude_from_utf_8(self, filepath):
|
||||
"""Ignore file matching glob patterns listed in file, one per
|
||||
line. The file is assumed to be in the argv encoding."""
|
||||
abs_filepath = argv_to_abspath(filepath)
|
||||
try:
|
||||
exclude_file = open(abs_filepath, "rb")
|
||||
exclude_file = open(abs_filepath, "r", encoding="utf-8")
|
||||
except Exception as e:
|
||||
raise BackupConfigurationError('Error opening exclude file %s. (Error: %s)' % (
|
||||
quote_local_unicode_path(abs_filepath), e))
|
||||
try:
|
||||
|
||||
for line in exclude_file:
|
||||
self.opt_exclude(line)
|
||||
finally:
|
||||
|
@ -355,14 +355,14 @@ class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):
|
||||
exclusion_string = "_darcs\n*py\n.svn"
|
||||
excl_filepath = os.path.join(basedir, 'exclusion')
|
||||
fileutil.write(excl_filepath, exclusion_string)
|
||||
backup_options = parse(['--exclude-from', excl_filepath, 'from', 'to'])
|
||||
backup_options = parse(['--exclude-from-utf-8', excl_filepath, 'from', 'to'])
|
||||
filtered = list(backup_options.filter_listdir(subdir_listdir))
|
||||
self._check_filtering(filtered, subdir_listdir, (u'another_doc.lyx', u'CVS'),
|
||||
(u'.svn', u'_darcs', u'run_snake_run.py'))
|
||||
# test BackupConfigurationError
|
||||
self.failUnlessRaises(cli.BackupConfigurationError,
|
||||
parse,
|
||||
['--exclude-from', excl_filepath + '.no', 'from', 'to'])
|
||||
['--exclude-from-utf-8', excl_filepath + '.no', 'from', 'to'])
|
||||
|
||||
# test that an iterator works too
|
||||
backup_options = parse(['--exclude', '*lyx', 'from', 'to'])
|
||||
@ -373,7 +373,7 @@ class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):
|
||||
def test_exclude_options_unicode(self):
|
||||
nice_doc = u"nice_d\u00F8c.lyx"
|
||||
try:
|
||||
doc_pattern_arg = u"*d\u00F8c*"
|
||||
doc_pattern_arg_unicode = doc_pattern_arg = u"*d\u00F8c*"
|
||||
if PY2:
|
||||
doc_pattern_arg = doc_pattern_arg.encode(get_io_encoding())
|
||||
except UnicodeEncodeError:
|
||||
@ -397,14 +397,10 @@ class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):
|
||||
self._check_filtering(filtered, root_listdir, (u'_darcs', u'subdir'),
|
||||
(nice_doc, u'lib.a'))
|
||||
# read exclude patterns from file
|
||||
exclusion_string = doc_pattern_arg + ensure_str("\nlib.?")
|
||||
if PY3:
|
||||
# On Python 2 this gives some garbage encoding. Also on Python 2 we
|
||||
# expect exclusion string to be bytes.
|
||||
exclusion_string = exclusion_string.encode(locale.getpreferredencoding(False))
|
||||
exclusion_string = (doc_pattern_arg_unicode + "\nlib.?").encode("utf-8")
|
||||
excl_filepath = os.path.join(basedir, 'exclusion')
|
||||
fileutil.write(excl_filepath, exclusion_string)
|
||||
backup_options = parse(['--exclude-from', excl_filepath, 'from', 'to'])
|
||||
backup_options = parse(['--exclude-from-utf-8', excl_filepath, 'from', 'to'])
|
||||
filtered = list(backup_options.filter_listdir(root_listdir))
|
||||
self._check_filtering(filtered, root_listdir, (u'_darcs', u'subdir'),
|
||||
(nice_doc, u'lib.a'))
|
||||
@ -427,20 +423,20 @@ class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):
|
||||
ns = Namespace()
|
||||
ns.called = False
|
||||
original_open = open
|
||||
def call_file(name, *args):
|
||||
def call_file(name, *args, **kwargs):
|
||||
if name.endswith("excludes.dummy"):
|
||||
ns.called = True
|
||||
self.failUnlessEqual(name, abspath_expanduser_unicode(exclude_file))
|
||||
return StringIO()
|
||||
else:
|
||||
return original_open(name, *args)
|
||||
return original_open(name, *args, **kwargs)
|
||||
|
||||
if PY2:
|
||||
from allmydata.scripts import cli as module_to_patch
|
||||
else:
|
||||
import builtins as module_to_patch
|
||||
patcher = MonkeyPatcher((module_to_patch, 'open', call_file))
|
||||
patcher.runWithPatches(parse_options, basedir, "backup", ['--exclude-from', unicode_to_argv(exclude_file), 'from', 'to'])
|
||||
patcher.runWithPatches(parse_options, basedir, "backup", ['--exclude-from-utf-8', unicode_to_argv(exclude_file), 'from', 'to'])
|
||||
self.failUnless(ns.called)
|
||||
|
||||
def test_ignore_symlinks(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user