Browse code

move filter_exclude_include() calls into fetch_remote_list()

To match fetch_local_list(), we can handle all the filtering
inside the calls to fetch_remote_list(). This also lets us
stop exporting filter_exclude_include() from S3/FileLists.py.

Matt Domsch authored on 2014/03/16 09:59:36
Showing 2 changed files
... ...
@@ -21,7 +21,7 @@ import copy
21 21
 import re
22 22
 import errno
23 23
 
24
-__all__ = ["fetch_local_list", "fetch_remote_list", "compare_filelists", "filter_exclude_include"]
24
+__all__ = ["fetch_local_list", "fetch_remote_list", "compare_filelists"]
25 25
 
26 26
 def _fswalk_follow_symlinks(path):
27 27
     '''
... ...
@@ -444,7 +444,9 @@ def fetch_remote_list(args, require_attribs = False, recursive = None, batch_mod
444 444
                 md5 = remote_item.get('md5')
445 445
                 if md5:
446 446
                     remote_list.record_md5(key, md5)
447
-    return remote_list
447
+
448
+    remote_list, exclude_list = filter_exclude_include(remote_list)
449
+    return remote_list, exclude_list
448 450
 
449 451
 
450 452
 def compare_filelists(src_list, dst_list, src_remote, dst_remote, delay_updates = False):
... ...
@@ -400,8 +400,7 @@ def cmd_object_get(args):
400 400
     if len(args) == 0:
401 401
         raise ParameterError("Nothing to download. Expecting S3 URI.")
402 402
 
403
-    remote_list = fetch_remote_list(args, require_attribs = False)
404
-    remote_list, exclude_list = filter_exclude_include(remote_list)
403
+    remote_list, exclude_list = fetch_remote_list(args, require_attribs = False)
405 404
 
406 405
     remote_count = len(remote_list)
407 406
 
... ...
@@ -530,9 +529,7 @@ def subcmd_batch_del(uri_str = None, bucket = None, remote_list = None):
530 530
         uri_str = "s3://%s" % bucket
531 531
     if not remote_list:
532 532
         batch_mode = True
533
-        remote_list = fetch_remote_list(uri_str, require_attribs = False, batch_mode = True)
534
-
535
-    remote_list, exclude_list = filter_exclude_include(remote_list)
533
+        remote_list, exclude_list = fetch_remote_list(uri_str, require_attribs = False, batch_mode = True)
536 534
 
537 535
     if len(remote_list) == 0:
538 536
         warning(u"Remote list is empty.")
... ...
@@ -564,9 +561,8 @@ def subcmd_batch_del(uri_str = None, bucket = None, remote_list = None):
564 564
         if not last_key or not last_key.has_object:
565 565
             break
566 566
         marker = last_key.object()
567
-        remote_list = fetch_remote_list(uri_str, require_attribs = False, batch_mode = True,
568
-                                        uri_params = {"marker": marker})
569
-        remote_list, exclude_list = filter_exclude_include(remote_list)
567
+        remote_list, exclude_list = fetch_remote_list(uri_str, require_attribs = False, batch_mode = True,
568
+                                                      uri_params = {"marker": marker})
570 569
     if cfg.dry_run:
571 570
         warning(u"Exiting now because of --dry-run")
572 571
         return False
... ...
@@ -578,8 +574,7 @@ def subcmd_object_del_uri(uri_str, recursive = None):
578 578
     if recursive is None:
579 579
         recursive = cfg.recursive
580 580
 
581
-    remote_list = fetch_remote_list(uri_str, require_attribs = False, recursive = recursive)
582
-    remote_list, exclude_list = filter_exclude_include(remote_list)
581
+    remote_list, exclude_list = fetch_remote_list(uri_str, require_attribs = False, recursive = recursive)
583 582
 
584 583
     remote_count = len(remote_list)
585 584
 
... ...
@@ -608,8 +603,7 @@ def cmd_object_restore(args):
608 608
     if cfg.restore_days < 1:
609 609
         raise ParameterError("You must restore a file for 1 or more days")
610 610
 
611
-    remote_list = fetch_remote_list(args, require_attribs = False, recursive = cfg.recursive)
612
-    remote_list, exclude_list = filter_exclude_include(remote_list)
611
+    remote_list, exclude_list = fetch_remote_list(args, require_attribs = False, recursive = cfg.recursive)
613 612
 
614 613
     remote_count = len(remote_list)
615 614
 
... ...
@@ -643,8 +637,7 @@ def subcmd_cp_mv(args, process_fce, action_str, message):
643 643
         raise ParameterError("Destination must be S3 URI. To download a file use 'get' or 'sync'.")
644 644
     destination_base = dst_base_uri.uri()
645 645
 
646
-    remote_list = fetch_remote_list(args, require_attribs = False)
647
-    remote_list, exclude_list = filter_exclude_include(remote_list)
646
+    remote_list, exclude_list = fetch_remote_list(args, require_attribs = False)
648 647
 
649 648
     remote_count = len(remote_list)
650 649
 
... ...
@@ -766,8 +759,8 @@ def cmd_sync_remote2remote(args):
766 766
     # Normalise s3://uri (e.g. assert trailing slash)
767 767
     destination_base = unicode(S3Uri(args[-1]))
768 768
 
769
-    src_list = fetch_remote_list(args[:-1], recursive = True, require_attribs = True)
770
-    dst_list = fetch_remote_list(destination_base, recursive = True, require_attribs = True)
769
+    src_list, src_exclude_list = fetch_remote_list(args[:-1], recursive = True, require_attribs = True)
770
+    dst_list, dst_exclude_list = fetch_remote_list(destination_base, recursive = True, require_attribs = True)
771 771
 
772 772
     src_count = len(src_list)
773 773
     orig_src_count = src_count
... ...
@@ -775,9 +768,6 @@ def cmd_sync_remote2remote(args):
775 775
 
776 776
     info(u"Found %d source files, %d destination files" % (src_count, dst_count))
777 777
 
778
-    src_list, src_exclude_list = filter_exclude_include(src_list)
779
-    dst_list, dst_exclude_list = filter_exclude_include(dst_list)
780
-
781 778
     src_list, dst_list, update_list, copy_pairs = compare_filelists(src_list, dst_list, src_remote = True, dst_remote = True, delay_updates = cfg.delay_updates)
782 779
 
783 780
     src_count = len(src_list)
... ...
@@ -874,7 +864,7 @@ def cmd_sync_remote2local(args):
874 874
 
875 875
     destination_base = args[-1]
876 876
     local_list, single_file_local, dst_exclude_list = fetch_local_list(destination_base, is_src = False, recursive = True)
877
-    remote_list = fetch_remote_list(args[:-1], recursive = True, require_attribs = True)
877
+    remote_list, src_exclude_list = fetch_remote_list(args[:-1], recursive = True, require_attribs = True)
878 878
 
879 879
     local_count = len(local_list)
880 880
     remote_count = len(remote_list)
... ...
@@ -882,8 +872,6 @@ def cmd_sync_remote2local(args):
882 882
 
883 883
     info(u"Found %d remote files, %d local files" % (remote_count, local_count))
884 884
 
885
-    remote_list, src_exclude_list = filter_exclude_include(remote_list)
886
-
887 885
     remote_list, local_list, update_list, copy_pairs = compare_filelists(remote_list, local_list, src_remote = True, dst_remote = False, delay_updates = cfg.delay_updates)
888 886
 
889 887
     local_count = len(local_list)
... ...
@@ -1246,7 +1234,7 @@ def cmd_sync_local2remote(args):
1246 1246
                 uploaded_objects_list.append(uri.object())
1247 1247
             return seq, total_size
1248 1248
 
1249
-        remote_list = fetch_remote_list(destination_base, recursive = True, require_attribs = True)
1249
+        remote_list, dst_exclude_list = fetch_remote_list(destination_base, recursive = True, require_attribs = True)
1250 1250
 
1251 1251
         local_count = len(local_list)
1252 1252
         orig_local_count = local_count
... ...
@@ -1254,9 +1242,6 @@ def cmd_sync_local2remote(args):
1254 1254
 
1255 1255
         info(u"Found %d local files, %d remote files" % (local_count, remote_count))
1256 1256
 
1257
-        local_list, src_exclude_list = filter_exclude_include(local_list)
1258
-        remote_list, dst_exclude_list = filter_exclude_include(remote_list)
1259
-
1260 1257
         if single_file_local and len(local_list) == 1 and len(remote_list) == 1:
1261 1258
             ## Make remote_key same as local_key for comparison if we're dealing with only one file
1262 1259
             remote_list_entry = remote_list[remote_list.keys()[0]]
... ...
@@ -1410,8 +1395,7 @@ def cmd_setacl(args):
1410 1410
             else:
1411 1411
                 args.append(arg)
1412 1412
 
1413
-    remote_list = fetch_remote_list(args)
1414
-    remote_list, exclude_list = filter_exclude_include(remote_list)
1413
+    remote_list, exclude_list = fetch_remote_list(args)
1415 1414
 
1416 1415
     remote_count = len(remote_list)
1417 1416