Skip to content

Instantly share code, notes, and snippets.

@olymk2
Last active November 7, 2023 16:32
Show Gist options
  • Save olymk2/e125e7bc15d1c9a292dd427a6c8202a0 to your computer and use it in GitHub Desktop.
Save olymk2/e125e7bc15d1c9a292dd427a6c8202a0 to your computer and use it in GitHub Desktop.
Scan solus packages for occurances of a packing in the dependencies

Example of running

bb scan.clj --search nodejs

or use the below command with vscode calva emacs or similar bb nrepl-server

(require '[clojure.string :as str])
(require '[babashka.cli :as cli])
(require '[babashka.fs :as fs])
(require '[clj-yaml.core :as yaml])
(def file-list (fs/glob "." "**{package.yml}"))
(defn parse-yaml-file [file]
(try
(yaml/parse-string (str (slurp file)))
(catch Exception _
(prn (str "Failed to parse or open " file)))))
(defn fetch-packages-with-deps
([key package]
(->> file-list
(map str)
(map parse-yaml-file)
(filter (fn filter-deps [deps]
(some #(= % package )
(get deps key) )))
(map :name))))
(def cli-options {:search {:coerce :string}})
(let [params (cli/parse-opts *command-line-args* {:spec cli-options})
results {:builddeps (fetch-packages-with-deps :builddeps (:search params))
:rundeps (fetch-packages-with-deps :rundeps (:search params))}]
(prn "Run dependencies")
(mapv prn (:rundeps results))
(prn "Build dependencies")
(mapv prn (:builddeps results))
(prn "sudo eopkg install " (str/join " " (into #{}
(concat
(:rundeps results)
(:builddeps results))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment