Skip to content

Commit

Permalink
* s3cmd, s3cmd.1: Added GLOB (shell-style wildcard) exclude, renamed
Browse files Browse the repository at this point in the history
  orig regexp-style --exclude to --rexclude



git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@192 830e0280-6d2a-0410-9c65-932aecc39d9d
  • Loading branch information
mludvig committed Jun 11, 2008
1 parent bb9910b commit 2d7d554
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 20 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2008-06-12 Michal Ludvig <michal@logix.cz>

* s3cmd, s3cmd.1: Added GLOB (shell-style wildcard) exclude, renamed
orig regexp-style --exclude to --rexclude

2008-06-11 Michal Ludvig <michal@logix.cz>

* S3/PkgInfo.py: Version 0.9.8-rc1
Expand Down
42 changes: 33 additions & 9 deletions s3cmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import os
import re
import errno
import pwd, grp
import glob

from copy import copy
from optparse import OptionParser, Option, OptionValueError, IndentedHelpFormatter
Expand Down Expand Up @@ -806,6 +807,15 @@ def run_configure(config_file):
error("Writing config file failed: %s: %s" % (config_file, e.strerror))
sys.exit(1)

def process_exclude_from_file(exf, exclude_array):
exfi = open(exf, "rt")
for ex in exfi:
ex = ex.strip()
if re.match("^#", ex) or re.match("^\s*$", ex):
continue
debug("adding rule: %s" % ex)
exclude_array.append(ex)

commands = {}
commands_list = [
{"cmd":"mb", "label":"Make bucket", "param":"s3://BUCKET", "func":cmd_bucket_create, "argc":1},
Expand Down Expand Up @@ -877,8 +887,10 @@ if __name__ == '__main__':
optparser.add_option( "--no-delete-removed", dest="delete_removed", action="store_false", help="Don't delete remote objects.")
optparser.add_option("-p", "--preserve", dest="preserve_attrs", action="store_true", help="Preserve filesystem attributes (mode, ownership, timestamps). Default for [sync] command.")
optparser.add_option( "--no-preserve", dest="preserve_attrs", action="store_false", help="Don't store FS attributes")
optparser.add_option( "--exclude", dest="exclude", action="append", metavar="REGEXP", help="Filenames and paths matching REGEXP will be excluded from sync")
optparser.add_option( "--exclude-from", dest="exclude_from", action="append", metavar="FILE", help="Read --exclude REGEXPs from FILE")
optparser.add_option( "--exclude", dest="exclude", action="append", metavar="GLOB", help="Filenames and paths matching GLOB will be excluded from sync")
optparser.add_option( "--exclude-from", dest="exclude_from", action="append", metavar="FILE", help="Read --exclude GLOBs from FILE")
optparser.add_option( "--rexclude", dest="rexclude", action="append", metavar="REGEXP", help="Filenames and paths matching REGEXP (regular expression) will be excluded from sync")
optparser.add_option( "--rexclude-from", dest="rexclude_from", action="append", metavar="FILE", help="Read --rexclude REGEXPs from FILE")
optparser.add_option( "--debug-syncmatch", dest="debug_syncmatch", action="store_true", help="Output detailed information about remote vs. local filelist matching and then exit")

optparser.add_option( "--bucket-location", dest="bucket_location", help="Datacentre to create bucket in. Either EU or US (default)")
Expand Down Expand Up @@ -938,22 +950,34 @@ if __name__ == '__main__':
## Some Config() options are not settable from command line
pass

## Process GLOB (shell wildcard style) excludes
if options.exclude is None:
options.exclude = []

if options.exclude_from:
for exf in options.exclude_from:
debug("processing --exclude-from %s" % exf)
exfi = open(exf, "rt")
for ex in exfi:
ex = ex.strip()
if re.match("^#", ex) or re.match("^\s*$", ex):
continue
debug("adding rule: %s" % ex)
options.exclude.append(ex)
process_exclude_from_file(exf, options.exclude)

if options.exclude:
for ex in options.exclude:
debug("processing rule: %s" % ex)
exc = re.compile(glob.fnmatch.translate(ex))
cfg.exclude.append(exc)
if options.debug_syncmatch:
cfg.debug_exclude[exc] = ex

## Process REGEXP style excludes
if options.rexclude is None:
options.rexclude = []

if options.rexclude_from:
for exf in options.rexclude_from:
debug("processing --rexclude-from %s" % exf)
process_exclude_from_file(exf, options.rexclude)

if options.rexclude:
for ex in options.rexclude:
debug("processing rule: %s" % ex)
exc = re.compile(ex)
cfg.exclude.append(exc)
Expand Down
33 changes: 22 additions & 11 deletions s3cmd.1
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ Preserve filesystem attributes (mode, ownership, timestamps). Default for 'sync'
\fB\-\-no\-preserve\fR
Don't store filesystem attributes with uploaded files.
.TP
\fB\-\-exclude REGEXP\fR
Exclude files matching REGEXP from \fIsync\fI. See SYNC COMMAND section for more information.
\fB\-\-exclude GLOB\fR
Exclude files matching GLOB (a.k.a. shell-style wildcard) from \fIsync\fI. See SYNC COMMAND section for more information.
.TP
\fB\-\-exclude\-from FILE\fR
Same as \-\-exclude but reads REGEXPs from the given FILE instead of expecting them on the command line.
Same as \-\-exclude but reads GLOBs from the given FILE instead of expecting them on the command line.
.TP
\fB\-\-rexclude REGEXP\fR
Same as \-\-exclude but works with REGEXPs (Regular expressions).
.TP
\fB\-\-rexclude\-from FILE\fR
Same as \-\-exclude\-from but works with REGEXPs.
.TP
\fB\-\-debug\-syncmatch\fR
Display detailed information about matching file names against exclude\-rules as well as information about remote vs local filelists matching. S3cmd exits after performing the match and no actual transfer takes place.
Expand Down Expand Up @@ -177,21 +183,26 @@ will be \fB/\fRfile1.ext and \fB/\fRdir123/file2.bin, that is both with the lead
slash regardless whether you specified s3://test-bucket/backup or
s3://test-bucket/backup/ (note the trailing slash) on the command line.

Both \fB\-\-exclude\fR and \fB\-\-exclude\-from\fR options expect regular expressions, not
shell-style wildcards! Run s3cmd with \fB\-\-debug\-syncmatch\fR to get detailed information
Both \fB\-\-exclude\fR and \fB\-\-exclude\-from\fR work with shell-style wildcards (a.k.a. GLOB).
For a greater flexibility s3cmd provides Regular-expression versions of the two exclude options
named \fB\-\-rexclude\fR and \fB\-\-rexclude\-from\fR.

Run s3cmd with \fB\-\-debug\-syncmatch\fR to get detailed information
about matching file names against exclude rules.

For example to exclude all files with ".bin" extension use:
For example to exclude all files with ".bin" extension with a REGEXP use:
.PP
\-\-rexclude '\.bin$'
.PP
\-\-exclude '\.bin$'
to exclude all hidden files and subdirectories (i.e. those whose name begins with dot ".") use GLOB:
.PP
to exclude all hidden files and subdirectories (i.e. those whose name begins with dot ".") use:
\-\-exclude '/.*'
.PP
\-\-exclude '/\.'
on the other hand to exclude only hidden files but not hidden subdirectories use REGEXP:
.PP
on the other hand to exclude only hidden files but not hidden subdirectories use:
\-\-rexclude '/\.[^/]*$'
.PP
\-\-exclude '/\.[^/]*$'
etc...

.SH AUTHOR
Written by Michal Ludvig <michal@logix.cz>
Expand Down

0 comments on commit 2d7d554

Please sign in to comment.