Add classpath_builder to help with java CLASSPATH
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 29 Jul 2011 16:37:46 +0000 (09:37 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 29 Jul 2011 16:39:13 +0000 (09:39 -0700)
Signed-off-by: Colin McCabe <cmccabe@alumni.cmu.edu>

classpath_builder.py [new file with mode: 0755]

diff --git a/classpath_builder.py b/classpath_builder.py
new file mode 100755 (executable)
index 0000000..174a35b
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+
+import os
+import subprocess
+import sys
+
+def usage():
+    print >>sys.stderr, "classpath_builder takes a directory, and returns \
+the CLASSPATH environment variable that would give you access to all the \
+jars in or under that directory.\n"
+    print >>sys.stderr, "Usage: classpath_builder.py [directory-name]"
+
+if (len(sys.argv) == 1):
+    usage()
+    sys.exit(1)
+if (sys.argv[1] == "-h") or (sys.argv[1] == "--help"):
+    usage()
+    sys.exit(0)
+if (not os.path.exists(sys.argv[1])):
+    usage()
+    sys.exit(1)
+proc = subprocess.Popen(["find", sys.argv[1], "-name", "*.jar"], \
+    shell=False, stdout=subprocess.PIPE)
+data = proc.communicate()[0]
+lines = data.splitlines()
+sep=""
+outs=":".join(lines)
+print "CLASSPATH=\"$CLASSPATH:" + outs + "\""