File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 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+
320import os , sys
421from contextlib import closing
522import re
623import zipfile
724
825def 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
1533def 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 :
You can’t perform that action at this time.
0 commit comments