Skip to content

Instantly share code, notes, and snippets.

@AeroNotix
Last active January 4, 2016 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AeroNotix/9927cc922e8c40c521fa to your computer and use it in GitHub Desktop.
Save AeroNotix/9927cc922e8c40c521fa to your computer and use it in GitHub Desktop.
(ns pismo.core
(:require [clj-yaml.core :as yaml]
[awizo.core :as awizo]
[clojure.core.async :as async])
(:use [clojure.java.shell :only [sh]])
(:gen-class))
(def config (yaml/parse-string (slurp "/etc/pismo.yaml")))
(defn mailmessage [p]
(let [path (awizo/string->path p)]
(fn [e]
(let [filepath (.context e)]
(println (.resolve path filepath))))))
(defn dir-seq [path]
(let [dir-contents (file-seq (clojure.java.io/file path))
dirs (rest (filter (fn [p] (.isDirectory p)) dir-contents))]
(map (fn [d] (.getPath d)) dirs)))
(defn create-watcher [path]
(prn path)
(fn []
(awizo/attach-handler path (mailmessage path) [awizo/CREATE awizo/MODIFY])))
(defn create-watchers [config]
(flatten
(doall
(for [path (config :paths)]
(if (config :recursive)
(let [paths (dir-seq path)]
(map create-watcher paths))
(create-watcher path))))))
(defn -main [& args]
(let [watchers (create-watchers config)
resp (doall
(for [watcher watchers]
(async/go (watcher))))]
(doseq [r resp]
(println (async/<!! r)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment