... | ... |
@@ -14,6 +14,7 @@ from logging import debug, info, warning, error |
14 | 14 |
|
15 | 15 |
import os |
16 | 16 |
import glob |
17 |
+import copy |
|
17 | 18 |
|
18 | 19 |
__all__ = ["fetch_local_list", "fetch_remote_list", "compare_filelists", "filter_exclude_include"] |
19 | 20 |
|
... | ... |
@@ -75,6 +76,62 @@ def filter_exclude_include(src_list): |
75 | 75 |
debug(u"PASS: %s" % (file)) |
76 | 76 |
return src_list, exclude_list |
77 | 77 |
|
78 |
+def handle_exclude_include_walk(root, dirs, files): |
|
79 |
+ cfg = Config() |
|
80 |
+ copydirs = copy.copy(dirs) |
|
81 |
+ copyfiles = copy.copy(files) |
|
82 |
+ |
|
83 |
+ # exclude dir matches in the current directory |
|
84 |
+ # this prevents us from recursing down trees we know we want to ignore |
|
85 |
+ for x in copydirs: |
|
86 |
+ d = os.path.join(root, x, '') |
|
87 |
+ debug(u"CHECK: %s" % d) |
|
88 |
+ excluded = False |
|
89 |
+ for r in cfg.exclude: |
|
90 |
+ if r.search(d): |
|
91 |
+ excluded = True |
|
92 |
+ debug(u"EXCL-MATCH: '%s'" % (cfg.debug_exclude[r])) |
|
93 |
+ break |
|
94 |
+ if excluded: |
|
95 |
+ ## No need to check for --include if not excluded |
|
96 |
+ for r in cfg.include: |
|
97 |
+ if r.search(d): |
|
98 |
+ excluded = False |
|
99 |
+ debug(u"INCL-MATCH: '%s'" % (cfg.debug_include[r])) |
|
100 |
+ break |
|
101 |
+ if excluded: |
|
102 |
+ ## Still excluded - ok, action it |
|
103 |
+ debug(u"EXCLUDE: %s" % d) |
|
104 |
+ dirs.remove(x) |
|
105 |
+ continue |
|
106 |
+ else: |
|
107 |
+ debug(u"PASS: %s" % (d)) |
|
108 |
+ |
|
109 |
+ # exclude file matches in the current directory |
|
110 |
+ for x in copyfiles: |
|
111 |
+ file = os.path.join(root, x) |
|
112 |
+ debug(u"CHECK: %s" % file) |
|
113 |
+ excluded = False |
|
114 |
+ for r in cfg.exclude: |
|
115 |
+ if r.search(file): |
|
116 |
+ excluded = True |
|
117 |
+ debug(u"EXCL-MATCH: '%s'" % (cfg.debug_exclude[r])) |
|
118 |
+ break |
|
119 |
+ if excluded: |
|
120 |
+ ## No need to check for --include if not excluded |
|
121 |
+ for r in cfg.include: |
|
122 |
+ if r.search(file): |
|
123 |
+ excluded = False |
|
124 |
+ debug(u"INCL-MATCH: '%s'" % (cfg.debug_include[r])) |
|
125 |
+ break |
|
126 |
+ if excluded: |
|
127 |
+ ## Still excluded - ok, action it |
|
128 |
+ debug(u"EXCLUDE: %s" % file) |
|
129 |
+ files.remove(x) |
|
130 |
+ continue |
|
131 |
+ else: |
|
132 |
+ debug(u"PASS: %s" % (file)) |
|
133 |
+ |
|
78 | 134 |
def fetch_local_list(args, recursive = None): |
79 | 135 |
def _get_filelist_local(local_uri): |
80 | 136 |
info(u"Compiling list of local files...") |
... | ... |
@@ -90,6 +147,7 @@ def fetch_local_list(args, recursive = None): |
90 | 90 |
single_file = True |
91 | 91 |
loc_list = SortedDict(ignore_case = False) |
92 | 92 |
for root, dirs, files in filelist: |
93 |
+ handle_exclude_include_walk(root, dirs, files) |
|
93 | 94 |
rel_root = root.replace(local_path, local_base, 1) |
94 | 95 |
for f in files: |
95 | 96 |
full_name = os.path.join(root, f) |