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