Last active
September 5, 2018 14:58
-
-
Save pesterhazy/74f6bc235dfe5f64690250d2ee84969d to your computer and use it in GitHub Desktop.
Grep in classpath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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