6 def new_link_path (link
, dir, r
):
10 while i
< len(d
) and i
< len(l
) and l
[i
] == '..':
15 return '/'.join ([x
for x
in l
if not r
.match (x
)])
17 def walk_tree (tree_roots
= [],
22 """Walk directory trees and.returns (dirs, symlinks, files, extra_files) tuple.
25 tree_roots=DIRLIST use DIRLIST as tree roots list
26 process_dir=PATTERN only process files in directories named PATTERN
27 exclude_dir=PATTERN don't recurse into directories named PATTERN
28 find_files=PATTERN filters files which are hardlinked
29 exclude_files=PATTERN exclude files named PATTERN
31 find_files_re
= re
.compile (find_files
)
32 exclude_dirs_re
= re
.compile (exclude_dirs
)
33 exclude_files_re
= re
.compile (exclude_files
)
34 process_dirs_re
= re
.compile (process_dirs
)
41 for current_dir
, dirs
, files
in os
.walk(d
):
44 if exclude_dirs_re
.search (os
.path
.join (current_dir
, dirs
[i
])):
47 p
= os
.path
.join (current_dir
, dirs
[i
])
48 if os
.path
.islink (p
):
49 symlinks_paths
.append (p
)
51 if not process_dirs_re
.search (current_dir
):
53 dirs_paths
.append (current_dir
)
55 if exclude_files_re
.match (f
):
57 p
= os
.path
.join (current_dir
, f
)
58 if os
.path
.islink (p
):
59 symlinks_paths
.append (p
)
60 elif find_files_re
.match (f
):
61 files_paths
.append (p
)
62 return (dirs_paths
, symlinks_paths
, files_paths
)