Show More
@@ -53,7 +53,7 b' globsyntax = """\\' | |||
|
53 | 53 | - readme*, exclude files ending with .bak |
|
54 | 54 | !.svn/ !.hg/ !*_Data/ rec:. |
|
55 | 55 | - Skip .svn, .hg, foo_Data dirs (and their subdirs) in recurse. |
|
56 | Trailing / is the key, \ does not work! | |
|
56 | Trailing / is the key, \ does not work! Use !.*/ for all hidden. | |
|
57 | 57 | dir:foo |
|
58 | 58 | - the directory foo if it exists (not files in foo) |
|
59 | 59 | dir:* |
@@ -63,13 +63,16 b' globsyntax = """\\' | |||
|
63 | 63 | foo.py is *not* included twice. |
|
64 | 64 | @filelist.txt |
|
65 | 65 | - All files listed in 'filelist.txt' file, on separate lines. |
|
66 | "cont:class \wak:" rec:*.py | |
|
67 | - Match files containing regexp. Applies to subsequent files. | |
|
68 | note quotes because of whitespace. | |
|
66 | 69 | """ |
|
67 | 70 | |
|
68 | 71 | |
|
69 | 72 | __version__ = "0.2" |
|
70 | 73 | |
|
71 | 74 | |
|
72 | import os,glob,fnmatch,sys | |
|
75 | import os,glob,fnmatch,sys,re | |
|
73 | 76 | from sets import Set as set |
|
74 | 77 | |
|
75 | 78 | |
@@ -84,21 +87,34 b' def expand(flist,exp_dirs = False):' | |||
|
84 | 87 | |
|
85 | 88 | """ |
|
86 | 89 | if isinstance(flist, basestring): |
|
87 | flist = flist.split() | |
|
90 | import shlex | |
|
91 | flist = shlex.split(flist) | |
|
88 | 92 | done_set = set() |
|
89 | 93 | denied_set = set() |
|
90 | ||
|
94 | cont_set = set() | |
|
95 | cur_rejected_dirs = set() | |
|
96 | ||
|
91 | 97 | def recfind(p, pats = ["*"]): |
|
92 |
denied_dirs = [ |
|
|
93 | #print "de", denied_dirs | |
|
98 | denied_dirs = [os.path.dirname(d) for d in denied_set if d.endswith("/")] | |
|
94 | 99 | for (dp,dnames,fnames) in os.walk(p): |
|
95 | 100 | # see if we should ignore the whole directory |
|
96 | 101 | dp_norm = dp.replace("\\","/") + "/" |
|
97 | 102 | deny = False |
|
103 | # do not traverse under already rejected dirs | |
|
104 | for d in cur_rejected_dirs: | |
|
105 | if dp.startswith(d): | |
|
106 | deny = True | |
|
107 | break | |
|
108 | if deny: | |
|
109 | continue | |
|
110 | ||
|
111 | ||
|
98 | 112 | #print "dp",dp |
|
113 | bname = os.path.basename(dp) | |
|
99 | 114 | for deny_pat in denied_dirs: |
|
100 |
if fnmatch.fnmatch( |
|
|
115 | if fnmatch.fnmatch( bname, deny_pat): | |
|
101 | 116 | deny = True |
|
117 | cur_rejected_dirs.add(dp) | |
|
102 | 118 | break |
|
103 | 119 | if deny: |
|
104 | 120 | continue |
@@ -124,6 +140,17 b' def expand(flist,exp_dirs = False):' | |||
|
124 | 140 | if fnmatch.fnmatch(os.path.basename(p), deny_pat): |
|
125 | 141 | deny = True |
|
126 | 142 | break |
|
143 | if cont_set: | |
|
144 | try: | |
|
145 | cont = open(p).read() | |
|
146 | except IOError: | |
|
147 | # deny | |
|
148 | continue | |
|
149 | for pat in cont_set: | |
|
150 | if not re.search(pat,cont, re.IGNORECASE): | |
|
151 | deny = True | |
|
152 | break | |
|
153 | ||
|
127 | 154 | if not deny: |
|
128 | 155 | yield it |
|
129 | 156 | return |
@@ -158,7 +185,8 b' def expand(flist,exp_dirs = False):' | |||
|
158 | 185 | # glob only dirs |
|
159 | 186 | elif ent.lower().startswith('dir:'): |
|
160 | 187 | res.extend(once_filter(filter(os.path.isdir,glob.glob(ent[4:])))) |
|
161 | ||
|
188 | elif ent.lower().startswith('cont:'): | |
|
189 | cont_set.add(ent[5:]) | |
|
162 | 190 | # get all files in the specified dir |
|
163 | 191 | elif os.path.isdir(ent) and exp_dirs: |
|
164 | 192 | res.extend(once_filter(filter(os.path.isfile,glob.glob(ent + os.sep+"*")))) |
General Comments 0
You need to be logged in to leave comments.
Login now