source: scenarios/GerminationX/oak/src/oak/island.clj @ 902

Revision 902, 1.6 KB checked in by dave, 10 years ago (diff)

path tweak

Line 
1;; Copyright (C) 2010 FoAM vzw
2;; This program is free software: you can redistribute it and/or modify
3;; it under the terms of the GNU Affero General Public License as
4;; published by the Free Software Foundation, either version 3 of the
5;; License, or (at your option) any later version.
6;;
7;; This program is distributed in the hope that it will be useful,
8;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10;; GNU Affero General Public License for more details.
11;;
12;; You should have received a copy of the GNU Affero General Public License
13;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
15(ns oak.island
16  (:use clojure.contrib.duck-streams)
17  (:require [org.danlarkin.json :as json]
18            clojure.contrib.java-utils))
19
20(defn execute [command]
21  (println (str "executing: " command))
22  (let [process (.exec (Runtime/getRuntime) command)]
23    (if (= 0 (.waitFor  process))
24        (read-lines (.getInputStream process))
25        (read-lines (.getErrorStream process)))))
26
27(defn update-islands [srcpath dstpath]
28  (when (.exists (clojure.contrib.java-utils/file srcpath))
29    (execute (str "rm -r " dstpath "islands"))
30    (execute (str "cp -r " srcpath " " dstpath))
31    (execute (str "rm -r " srcpath))
32    ))
33
34(defn read-islands [path]
35  (json/encode-to-str
36   (map
37    (fn [file]
38      (let [toks (.split (str file) "-")]
39        {:name (.substring (str file) 8)
40         :position
41         {:x (nth toks 2)
42          :y (first (.split (nth toks 3) "\\."))}}))
43    (filter #(re-find #"\.png$" (str %)) (file-seq (java.io.File. path))))))
44
Note: See TracBrowser for help on using the repository browser.