Skip to content

Commit

Permalink
bloomreach#88 (multiple) --exclude for local src files in dsync.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eichhorst committed Jul 1, 2019
1 parent bb51075 commit 896a1df
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ Synchronize the contents of two directories. The directory can either be local o
* -f/--force: override existing file instead of showing error message.
* -n/--dry-run: emulate the operation without real sync.
* --delete-removed: delete files not in source directory.
* --exclude: exclude files with the given pattern(s). Only works for local files to be uploaded to s3 directory. This option can be provided several times.

#### `s4cmd sync [source] [target]`

Expand Down Expand Up @@ -263,6 +264,9 @@ before given parameter.
Condition on files where their last modified dates are
after given parameter.

##### `--exclude`
(local) Filenames, matching the given pattern (https://docs.python.org/3.4/library/fnmatch.html) will not be synced to s3 directory. You may provide this param several times.


## S3 API Pass-through Options

Expand Down
23 changes: 22 additions & 1 deletion s4cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,14 @@ def dsync_files(self, source, target):
for src, dest in sync_list:
pool.download(src, dest)
elif not src_s3_url and dst_s3_url:
expats = []
if self.opt.exclude:
expats = self.opt.exclude
info("excluded patterns: %s", expats)

for src, dest in sync_list:
pool.upload(src, dest)
if not any(fnmatch.fnmatch(src, expat) for expat in expats):
pool.upload(src, dest)
elif src_s3_url and dst_s3_url:
for src, dest in sync_list:
pool.copy(src, dest)
Expand Down Expand Up @@ -1815,6 +1821,18 @@ def check_dict(self, opt, value):
TYPE_CHECKER['datetime'] = check_datetime
TYPE_CHECKER['dict'] = check_dict

# enable multiple option values (e.g. --exclude '*.thumbnail.jpg' --exclude '*.layout.jpg')
ACTIONS = optparse.Option.ACTIONS + ("extend",)
STORE_ACTIONS = optparse.Option.STORE_ACTIONS + ("extend",)
TYPED_ACTIONS = optparse.Option.TYPED_ACTIONS + ("extend",)
ALWAYS_TYPED_ACTIONS = optparse.Option.ALWAYS_TYPED_ACTIONS + ("extend",)

def take_action(self, action, dest, opt, value, values, parser):
if action == "extend":
values.ensure_value(dest, []).append(value)
else:
optparse.Option.take_action(self, action, dest, opt, value, values, parser)

def main():
try:
if not sys.argv[0]: sys.argv[0] = '' # Workaround for running with optparse from egg
Expand Down Expand Up @@ -1910,6 +1928,9 @@ def main():
'--last-modified-after',
help='Condition on files where their last modified dates are after given parameter.',
type='datetime', default=None)
parser.add_option(
'--exclude', help='Exclude all files from src dsync (file-)list matching the specified pattern',
dest='exclude', action="extend", type='string', default=None)

# Extra S3 API arguments
BotoClient.add_options(parser)
Expand Down

0 comments on commit 896a1df

Please sign in to comment.