Yeah, wait, what?
No, really!
I took a look through clojure-py, and found out something pretty rad. In order to get clojurepy scripts to load other clojurepy, it had to shim out and add a new importer for clojure scripts.
What this really means, is that you can import Clojure from Python, which is pretty sweet. I abused the internals here, and added it to dput-ng as a quick hack.
Basically, I just had to import clojure.main, and let the main function set up the sys shim. I would set it up in dput, but I’d have to import that module anyway.
Remember, when doing this, the namespace ((ns …)) needs to match the filename.
So, I present the first Clojure hook for dput-ng:
; Copyright (c) Paul R. Tagliamonte , 2012, under the
; terms of dput-ng itsself.
(ns clojtest
(:require dput.core
dput.exceptions))
(defn log [x] ; for debug output
(.debug dput.core/logger x))
(defn dput-checker [changes profile interface]
(cond (>= (-> changes (.get “maintainer”) (.find “arno@debian.org”)) 0)
(throw (dput.exceptions/HookException. “Maintainer’s Arno. Aborting upload”))
:else
(log “Nah, it’s not arno, we’re good”)))
This, of course, checks if the maintainer is Arno, and throws a fit if it is. Gist is over on gist.github.
After, Algernon added his own checker, which throws a fit if you have a package in the B-Ds that you aught to not use (such as depatch)
; Copyright (c) Gergely Nagy , 2012, under the
; terms of dput-ng itself.
(ns bd-blacklist
(:require dput.core
dput.exceptions
dput.dsc))
(defn prune-build-deps
“Prune a string representation of the build-depends so that only a
list of packages remain.”
[bd-string]
(map #(first (-> % (.strip) (.split ” “))) (.. bd-string (split “,”))))
(defn has-blacklisted?
“Given a dsc file and a blacklist, check if any of the
build-depencencies are in that list. Throws an error if there are
matches.”
[dsc-file blacklist]
(let [dsc (dput.dsc/parse_dsc_file dsc-file)
build-deps (prune-build-deps (.. dsc (get “build-depends”)))]
(if-let [bad-bd (some blacklist build-deps)]
(throw (dput.exceptions/HookException. (str “Blacklisted build-dependency found: ” bad-bd)))
(-> dput.core/logger (.trace “Build-Dependencies do not have anything on the blacklist”)))))
(defn blacklist-checker
“Checks whether the dsc has blacklisted build-dependencies, ignores
the check when no dsc is to be found.”
[changes profile interface]
(if-let [dsc-file (.. changes (get_dsc))]
(has-blacklisted? dsc-file (set (get profile “bd-blacklist”)))
(-> dput.core/logger (.trace “No .dsc found, build-dependencies cannot be checked”))))
You can check that out in the git tree
Hacks welcome!
Source: Planet Ubuntu