Skip to content

Commit 55f5f4a

Browse files
author
Dan North
committed
[dn] added some docs
1 parent aa9af48 commit 55f5f4a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

zfind

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
#!/usr/bin/env python
22

3+
''' Recursively search for files contained in jar/zip files.
4+
5+
This isn't for searching _inside_ the files, like zgrep, but
6+
for matching the file names themselves. For instance:
7+
8+
$ zfind org.apache.http.client.params.HttpClientParams ~/.m2
9+
10+
will search Maven's local cache for any jars containing the
11+
HttpClientParams class. It turns out the dots in the package name
12+
conveniently match slashes in the java class's name:
13+
14+
/home/dnorth/.m2/repository/org/apache/httpcomponents/httpclient/4.0.1/httpclient-4.0.1.jar: org/apache/http/client/params/HttpClientParams.class
15+
16+
Ah, there it is! '''
17+
18+
__AUTHOR__ = 'Dan North <dan@dannorth.net>'
19+
320
import os, sys
421
from contextlib import closing
522
import re
623
import zipfile
724

825
def scan_file(pattern, path):
26+
''' Search a zip file's contents for matching file names '''
927
if zipfile.is_zipfile(path):
1028
with closing(zipfile.ZipFile(path)) as zf:
1129
for name in zf.namelist():
1230
if re.search(pattern, name):
1331
print "%s: %s" % (path, name)
1432

1533
def scan_zip_files(pattern, path):
34+
''' Use os.walk to recurse down a directory hierarchy looking for zip files '''
1635
if os.path.isfile(path):
1736
scan_file(pattern, path)
1837
else:

0 commit comments

Comments
 (0)