From: <lu...@us...> - 2008-06-11 15:06:19
|
Revision: 192 http://s3tools.svn.sourceforge.net/s3tools/?rev=192&view=rev Author: ludvigm Date: 2008-06-11 08:06:15 -0700 (Wed, 11 Jun 2008) Log Message: ----------- * s3cmd, s3cmd.1: Added GLOB (shell-style wildcard) exclude, renamed orig regexp-style --exclude to --rexclude Modified Paths: -------------- s3cmd/trunk/ChangeLog s3cmd/trunk/s3cmd s3cmd/trunk/s3cmd.1 Modified: s3cmd/trunk/ChangeLog =================================================================== --- s3cmd/trunk/ChangeLog 2008-06-11 02:21:59 UTC (rev 191) +++ s3cmd/trunk/ChangeLog 2008-06-11 15:06:15 UTC (rev 192) @@ -1,3 +1,8 @@ +2008-06-12 Michal Ludvig <mi...@lo...> + + * s3cmd, s3cmd.1: Added GLOB (shell-style wildcard) exclude, renamed + orig regexp-style --exclude to --rexclude + 2008-06-11 Michal Ludvig <mi...@lo...> * S3/PkgInfo.py: Version 0.9.8-rc1 Modified: s3cmd/trunk/s3cmd =================================================================== --- s3cmd/trunk/s3cmd 2008-06-11 02:21:59 UTC (rev 191) +++ s3cmd/trunk/s3cmd 2008-06-11 15:06:15 UTC (rev 192) @@ -12,6 +12,7 @@ import re import errno import pwd, grp +import glob from copy import copy from optparse import OptionParser, Option, OptionValueError, IndentedHelpFormatter @@ -806,6 +807,15 @@ 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}, @@ -877,8 +887,10 @@ 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)") @@ -938,23 +950,35 @@ ## 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) if options.debug_syncmatch: Modified: s3cmd/trunk/s3cmd.1 =================================================================== --- s3cmd/trunk/s3cmd.1 2008-06-11 02:21:59 UTC (rev 191) +++ s3cmd/trunk/s3cmd.1 2008-06-11 15:06:15 UTC (rev 192) @@ -86,12 +86,18 @@ \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. .\".TP @@ -177,21 +183,26 @@ 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 - \-\-exclude '\.bin$' + \-\-rexclude '\.bin$' .PP -to exclude all hidden files and subdirectories (i.e. those whose name begins with dot ".") use: +to exclude all hidden files and subdirectories (i.e. those whose name begins with dot ".") use GLOB: .PP - \-\-exclude '/\.' + \-\-exclude '/.*' .PP -on the other hand to exclude only hidden files but not hidden subdirectories use: +on the other hand to exclude only hidden files but not hidden subdirectories use REGEXP: .PP - \-\-exclude '/\.[^/]*$' + \-\-rexclude '/\.[^/]*$' +.PP +etc... .SH AUTHOR Written by Michal Ludvig <mi...@lo...> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |