Skip to content

Instantly share code, notes, and snippets.

@pesterhazy
Last active September 5, 2018 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pesterhazy/74f6bc235dfe5f64690250d2ee84969d to your computer and use it in GitHub Desktop.
Save pesterhazy/74f6bc235dfe5f64690250d2ee84969d to your computer and use it in GitHub Desktop.
Grep in classpath
#!/usr/bin/env python
# unpack-cp.py
# Takes cp as argument, or reads from stdin. cp should be a colon separated
# list of jars. Extracts all jars to temp directory and prints out the name of
# the temp directory. The user is expected to delete the directory when it
# is not needed anymore.
#
# Useful for grepping for code and checking which files are visible to the JVM.
#
# Example:
#
# clojure -Spath | ./unpack-cp.py
from __future__ import print_function
import sys, tempfile, zipfile, os
if len(sys.argv) > 1:
inf = open(sys.argv[1])
else:
inf = sys.stdin
data = inf.read().rstrip()
dirpath = tempfile.mkdtemp()
for f in data.split(":"):
if not os.path.isfile(f):
print("Not a file, skipping", f)
continue
if os.path.isdir(f):
print("Dir, skipping", f)
continue
zip_ref = zipfile.ZipFile(f, 'r')
zip_ref.extractall(dirpath)
zip_ref.close()
print(dirpath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment