]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/mirrortree.py
Merge branch 'lilypond/translation' of ssh://jomand@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / buildscripts / mirrortree.py
1 #!@PYTHON@
2
3 import re
4 import os
5
6 def new_link_path (link, dir, r):
7     l = link.split ('/')
8     d = dir.split ('/')
9     i = 0
10     while i < len(d) and i < len(l) and l[i] == '..':
11         if r.match (d[i]):
12             del l[i]
13         else:
14             i += 1
15     return '/'.join ([x for x in l if not r.match (x)])
16
17 def walk_tree (tree_roots = [],
18                process_dirs = '.*',
19                exclude_dirs = '',
20                find_files = '.*',
21                exclude_files = ''):
22     """Walk directory trees and.returns (dirs, symlinks, files, extra_files) tuple.
23
24     Arguments:
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
30     """
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)
35
36     dirs_paths = []
37     symlinks_paths = []
38     files_paths = []
39
40     for d in tree_roots:
41         for current_dir, dirs, files in os.walk(d):
42             i = 0
43             while i < len(dirs):
44                 if exclude_dirs_re.search (os.path.join (current_dir, dirs[i])):
45                     del dirs[i]
46                 else:
47                     p = os.path.join (current_dir, dirs[i])
48                     if os.path.islink (p):
49                         symlinks_paths.append (p)
50                     i += 1
51             if not process_dirs_re.search (current_dir):
52                 continue
53             dirs_paths.append (current_dir)
54             for f in files:
55                 if exclude_files_re.match (f):
56                     continue
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)