Skip to content

Commit

Permalink
Use keywords for tags store, update deps, more unit tests, Fix #22
Browse files Browse the repository at this point in the history
  • Loading branch information
verma committed Apr 4, 2014
1 parent f34807d commit 719517d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 11 deletions.
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[ring/ring-devel "1.2.2"]
[ring/ring-core "1.2.2"]
[http-kit "2.1.18"]
[org.clojure/clojurescript "0.0-2197"]
[org.clojure/clojurescript "0.0-2202"]
[org.clojure/data.json "0.2.4"]
[de.ubercode.clostache/clostache "1.3.1"]
[org.clojure/tools.logging "0.2.6"]
Expand All @@ -20,7 +20,7 @@
[reagent "0.4.2"]
[crate "0.2.5"]
[jayq "2.5.0"]]
:plugins [[lein-cljsbuild "1.0.2"]
:plugins [[lein-cljsbuild "1.0.3"]
[lein-ancient "0.5.5"]]

:main dakait.main
Expand Down
2 changes: 1 addition & 1 deletion src/dakait/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
(def defaults { :server-name "Server"
:sftp-port 22
:concurrency 4
:local-base-path "."
:username (System/getProperty "user.name")
:base-path "." })

Expand All @@ -18,7 +19,6 @@
(defn- make-sure-required-exist []
"Makes sure that required properties exist"
(let [required '(:config-data-dir
:local-base-path
:sftp-host :private-key)]
(doseq [k required]
(when (nil? (config k))
Expand Down
4 changes: 2 additions & 2 deletions src/dakait/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@
(do-with-cond
(or (nil? tag) (nil? target)) 400 "Tag and taget file needs to be specified"
(let [tag-obj (find-tag tag)
dest (get tag-obj "target")]
dest (:target tag-obj)]
(do-with-cond
(or (nil? tag-obj) (nil? dest)) 400 "The specified tag is invalid"
(let [target-path (join-path (config :base-path) target)
dest-path (join-path (config :local-base-path) (get tag-obj "target"))]
dest-path (join-path (config :local-base-path) (:target tag-obj))]
;; start the download
;;
(start-download target-path dest-path)
Expand Down
9 changes: 6 additions & 3 deletions src/dakait/tags.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
;; disk files

(ns dakait.tags
(:use dakait.util)
(:require
[clojure.java.io :as io]
[clojure.data.json :as json]))
[clojure.data.json :as json]
[clojure.walk :refer [keywordize-keys]]))

(def source-file (atom nil))
(def all-tags (atom {}))
Expand All @@ -23,7 +25,8 @@
(when (.exists (io/as-file file))
(reset! all-tags (->> file
slurp
json/read-str))))
json/read-str
(map-vals keywordize-keys)))))

(defn get-all-tags
"Return all tags that we know of"
Expand All @@ -33,7 +36,7 @@
(defn add-tag
"Add the given tag to the list of tags"
[name target color]
(reset! all-tags (assoc @all-tags name {"target" target "color" color}))
(reset! all-tags (assoc @all-tags name {:target target :color color}))
(flush-to-disk))

(defn find-tag
Expand Down
15 changes: 12 additions & 3 deletions src/dakait/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
[clojure.java.io :as io]))

(defn join-path
"Join path elements together"
[& parts]
(.getPath (reduce #(io/file %1 %2) parts)))
"Join path elements together, if any of the path components start with a /
the function assumes that the path is being reset to root and will ignore all parts
before that"
[p & parts]
(let [p (if (= p "") "." p)]
(.getPath (reduce #(if (.startsWith %2 "/")
(io/file %2)
(io/file %1 %2)) (io/file p) parts))))

(defn filename
"Get the last component from the given path"
Expand All @@ -15,4 +20,8 @@
last))


(defn map-vals
"Maps the values of the given given map using the given function"
[f col]
(into {} (for [[k v] col] [k (f v)])))

21 changes: 21 additions & 0 deletions test/dakait/test/util.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(ns dakait.test.util
(:use clojure.test
dakait.util))

(defmacro join-path-as-string [& args]
`(.toString (join-path ~@args)))

(deftest util
(testing "combines paths correctly"
(is (= (join-path-as-string "/home" "test") "/home/test"))
(is (= (join-path-as-string "/home" "/tmp") "/tmp"))
(is (= (join-path-as-string "tmp") "tmp"))
(is (= (join-path-as-string "." "/stuff") "/stuff"))
(is (= (join-path-as-string "" "stuff") "./stuff"))
(is (= (join-path-as-string "." "tmp") "./tmp")))

(testing "map-vals works correctly"
(is (= (map-vals inc {:a 1 :b 1}) {:a 2 :b 2}))
(is (= (map-vals keyword {:hello "world" :bye "world"}) {:hello :world :bye :world}))))


0 comments on commit 719517d

Please sign in to comment.