Skip to content

Instantly share code, notes, and snippets.

@samedhi
Created June 28, 2020 23:49
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 samedhi/7d3071e54f5a6768be4b7fae3cb951f9 to your computer and use it in GitHub Desktop.
Save samedhi/7d3071e54f5a6768be4b7fae3cb951f9 to your computer and use it in GitHub Desktop.
#!/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