]>
Commit | Line | Data |
---|---|---|
1 | ; Common utility functions used by scripts | |
2 | ||
3 | (import '[java.nio.file Files FileSystems CopyOption StandardCopyOption]) | |
4 | ||
5 | (require '[org.httpkit.client :as http]) | |
6 | ||
7 | (defn extract-file-from-zip | |
8 | [zip-file-name source destination] | |
9 | (let [zip-file (io/file zip-file-name) | |
10 | src (io/file source) | |
11 | dest (io/file destination) | |
12 | fs (FileSystems/newFileSystem (.toPath zip-file) nil) | |
13 | file-in-zip (.getPath fs source (into-array String []))] | |
14 | (Files/copy file-in-zip | |
15 | (.toPath dest) | |
16 | (into-array CopyOption [StandardCopyOption/REPLACE_EXISTING])))) | |
17 | ||
18 | (defn expand-home | |
19 | [s] | |
20 | (if (.startsWith s "~") | |
21 | (clojure.string/replace-first s "~" (System/getProperty "user.home")) | |
22 | s)) | |
23 | ||
24 | (defn download-binary | |
25 | [url destination] | |
26 | (io/copy (:body @(http/get url)) (io/file destination))) |