Skip to content

Instantly share code, notes, and snippets.

@samedhi

samedhi/run.clj

Created Jun 28, 2020
Embed
What would you like to do?
#!/usr/bin/env bb
;; --- CONSTANTS --
(def projects-directory "/home/samedhi/")
(def commit-to-video-config-filename ".commit-to-video.edn")
;; -- FILESYSTEM --
(defn list-dir
"Get a sequence of files under 'directory as Java File objects"
[directory]
(-> directory
io/file
.listFiles
seq))
(defn absolute? [file]
(.isAbsolute file))
(defn directory? [file]
(.isDirectory file))
(defn exist? [file]
(.exists file))
(defn git-directory? [file]
(exist? (io/file file ".git")))
(defn contains-config? [file]
(exist? (io/file file commit-to-video-config-filename)))
(defn path->file [path file]
(if (absolute? (io/file path))
(io/file path)
(io/file file path)))
(defn read-config [file]
(-> (io/file file commit-to-video-config-filename)
slurp
edn/read-string
(update :videos-path path->file file)
(assoc :git-path file)))
(defn videos-exist? [config]
(let [{:keys [videos-path]} config]
(and (exist? videos-path)
(directory? videos-path))))
(->> (list-dir projects-directory)
(filter directory?)
(filter git-directory?)
(filter contains-config?)
(map read-config)
(filter videos-exist?))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment