annotate src/rlm/clj.clj @ 0:78a630e650d2

initial import
author Robert McIntyre <rlm@mit.edu>
date Tue, 18 Oct 2011 00:57:08 -0700
parents
children
rev   line source
rlm@0 1 #!/home/r/roBin/env-cool java -cp /home/r/roBin/libs/*:/home/r/roBin/src:/home/r/roBin/rlm-lib/* -Xms1g -Xmx1g clojure.main
rlm@0 2
rlm@0 3 (ns rlm.clj
rlm@0 4 (:use [clojure.contrib
rlm@0 5 [duck-streams :only [file-str] ]
rlm@0 6 command-line str-utils shell-out
rlm@0 7 [seq :only [indexed]]]
rlm@0 8 [rlm shell-write]))
rlm@0 9
rlm@0 10 (defn clj [& args]
rlm@0 11 (with-command-line args
rlm@0 12 "Simple Clojure shebang (#!) lines"
rlm@0 13 [[classpath c "java classpath in which this script will run. rlm is always on the classpath."
rlm@0 14 "/home/r/roBin/libs/*:/home/r/roBin/rlm-lib/*:/home/r/roBin/src"]
rlm@0 15 [memory m "how much memory should this stupid jvm be provided? (megabytes)" 1000]
rlm@0 16 [garbage g "level of congestion after which the jvm starts garbage collecting (megabytes)"
rlm@0 17 "30% of whatever memory is"]
rlm@0 18 [libraries l "link in libraries under -Djava.library.path" ""]
rlm@0 19 [configure conf "use a file with configureations to defeat shebang line limit don't double define things:) " "/dev/null"]
rlm@0 20 target-files]
rlm@0 21
rlm@0 22 (if (not (= configure "/dev/null"))
rlm@0 23 (apply clj (into (re-split #" " (chomp (slurp configure))) target-files))
rlm@0 24
rlm@0 25 (let [
rlm@0 26 adjusted-garbage
rlm@0 27 (if (string? garbage)
rlm@0 28 (int (* 0.3 (Integer. memory)))
rlm@0 29 garbage)]
rlm@0 30
rlm@0 31 ;assemble arguments to be passed to java
rlm@0 32 (let [java-args
rlm@0 33 (into
rlm@0 34 ["-cp" classpath
rlm@0 35 (str "-Xmn" adjusted-garbage "M")
rlm@0 36 (str "-Xmx" memory "M")
rlm@0 37 (str "-Xms" memory "M")
rlm@0 38 (str "-Djava.library.path=\"" libraries "\"")
rlm@0 39 "clojure.main"]
rlm@0 40 target-files)]
rlm@0 41 (let [command (str "java " (str-join " " java-args))]
rlm@0 42 (println command)
rlm@0 43 (sw command)
rlm@0 44 ))))))
rlm@0 45
rlm@0 46
rlm@0 47
rlm@0 48
rlm@0 49
rlm@0 50 (if *command-line-args*
rlm@0 51 (let [options #{"-c" "-g" "-m" "-l" "-conf"}
rlm@0 52 fuck (split-with (fn [[index element]] (or (odd? index) (options element)))
rlm@0 53 (indexed *command-line-args*))
rlm@0 54 fuck2 (conj (apply vector (map last (first fuck))) (str-join " " (map last (last fuck))))
rlm@0 55 ]
rlm@0 56 (apply clj fuck2)))
rlm@0 57
rlm@0 58