Browse code

* s3cmd: Added --exclude switch for sync.

git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@186 830e0280-6d2a-0410-9c65-932aecc39d9d

Michal Ludvig authored on 2008/06/09 21:53:48
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+2008-06-10  Michal Ludvig  <michal@logix.cz>
2
+
3
+	* s3cmd: Added --exclude switch for sync.
4
+
1 5
 2008-06-05  Michal Ludvig  <michal@logix.cz>
2 6
 
3 7
 	* Released version 0.9.7
... ...
@@ -360,8 +360,23 @@ def _get_filelist_remote(remote_uri):
360 360
 def _compare_filelists(src_list, dst_list, src_is_local_and_dst_is_remote):
361 361
 	output("Verifying checksums...")
362 362
 	exists_list = {}
363
+	exclude_list = {}
363 364
 	for file in src_list.keys():
364 365
 		debug("Checking %s ..." % file)
366
+		excluded = False
367
+		for r in Config().exclude:
368
+			## all paths start with '/' from the base dir
369
+			if r.search(os.sep + file):
370
+				## Can't directly 'continue' to the outer loop
371
+				## therefore this awkward excluded switch :-(
372
+				excluded = True
373
+				break
374
+		if excluded:
375
+			info("%s: excluded" % file)
376
+			exclude_list = src_list[file]
377
+			del(src_list[file])
378
+			continue
379
+
365 380
 		if dst_list.has_key(file):
366 381
 			debug("%s exists in remote list" % file)
367 382
 			## Check size first
... ...
@@ -389,7 +404,7 @@ def _compare_filelists(src_list, dst_list, src_is_local_and_dst_is_remote):
389 389
 			## Remove from destination-list, all that is left there will be deleted
390 390
 			debug("%s removed from destination list" % file)
391 391
 			del(dst_list[file])
392
-	return src_list, dst_list, exists_list
392
+	return src_list, dst_list, exists_list, exclude_list
393 393
 
394 394
 def cmd_sync_remote2local(src, dst):
395 395
 	def _parse_attrs_header(attrs_header):
... ...
@@ -842,6 +857,9 @@ if __name__ == '__main__':
842 842
 	optparser.add_option(      "--no-delete-removed", dest="delete_removed", action="store_false", help="Don't delete remote objects.")
843 843
 	optparser.add_option("-p", "--preserve", dest="preserve_attrs", action="store_true", help="Preserve filesystem attributes (mode, ownership, timestamps). Default for [sync] command.")
844 844
 	optparser.add_option(      "--no-preserve", dest="preserve_attrs", action="store_false", help="Don't store FS attributes")
845
+	optparser.add_option(      "--exclude", dest="exclude", action="append", metavar="REGEXP", help="Filenames and paths matching REGEXP will be excluded from sync")
846
+	#optparser.add_option(      "--exclude-from", dest="exclude_from", action="append", metavar="FILE", help="Read --exclude REGEXPs from FILE")
847
+
845 848
 	optparser.add_option(      "--bucket-location", dest="bucket_location", help="Datacentre to create bucket in. Either EU or US (default)")
846 849
 
847 850
 	optparser.add_option("-m", "--mime-type", dest="default_mime_type", type="mimetype", metavar="MIME/TYPE", help="Default MIME-type to be set for objects stored.")
... ...
@@ -899,6 +917,9 @@ if __name__ == '__main__':
899 899
 			## Some Config() options are not settable from command line
900 900
 			pass
901 901
 
902
+	for ex in options.exclude:
903
+		cfg.exclude.append(re.compile(ex))
904
+
902 905
 	if cfg.encrypt and cfg.gpg_passphrase == "":
903 906
 		error("Encryption requested but no passphrase set in config file.")
904 907
 		error("Please re-run 's3cmd --configure' and supply it.")