-
-
Save AeroNotix/9927cc922e8c40c521fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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