~ubuntu-branches/ubuntu/saucy/dput-ng/saucy-proposed

« back to all changes in this revision

Viewing changes to examples/hooks/bd-blacklist/code/bd-blacklist.clj

  • Committer: Package Import Robot
  • Author(s): Paul Tagliamonte, Paul Tagliamonte, Arno Töll
  • Date: 2012-12-26 09:30:06 UTC
  • Revision ID: package-import@ubuntu.com-20121226093006-8oebt2qovy5stc8a
Tags: 1.3
* The "we're so proud of our work, we need to let everyone know" release

[ Paul Tagliamonte ]
* Avoid failing on upload if a pre/post upload hook is missing from the
  Filesystem. Thanks to Moritz Mühlenhoff for the report. (Closes: #696659)
* Adjust Homepage: to point to our spiffy debian.net alias, rather then
  my people.debian.
* Add in experiemental clojure support via clojurepy hackery. It's
  amazingly cool, really. Thanks to Paul Tagliamonte for the extremely
  nice patch. Well done.

[ Arno Töll ]
* Fix "dcut raises FtpUploadException" by correctly initializing the uploader
  classes from dcut (Closes: #696467)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
; Copyright (c) Gergely Nagy <algernon@debian.org>, 2012, under the
 
2
; terms of dput-ng itself.
 
3
 
 
4
(ns bd-blacklist
 
5
  (:require dput.core
 
6
            dput.exceptions
 
7
            dput.dsc))
 
8
 
 
9
(defn prune-build-deps
 
10
  "Prune a string representation of the build-depends so that only a
 
11
  list of packages remain."
 
12
  [bd-string]
 
13
 
 
14
  (map #(first (-> % (.strip) (.split " "))) (.. bd-string (split ","))))
 
15
 
 
16
(defn has-blacklisted?
 
17
  "Given a dsc file and a blacklist, check if any of the
 
18
  build-depencencies are in that list. Throws an error if there are
 
19
  matches."
 
20
 
 
21
  [dsc-file blacklist]
 
22
 
 
23
  (let [dsc (dput.dsc/parse_dsc_file dsc-file)
 
24
        build-deps (prune-build-deps (.. dsc (get "build-depends")))]
 
25
    (if-let [bad-bd (some blacklist build-deps)]
 
26
      (throw (dput.exceptions/HookException. (str "Blacklisted build-dependency found: " bad-bd)))
 
27
      (-> dput.core/logger (.trace "Build-Dependencies do not have anything on the blacklist")))))
 
28
 
 
29
(defn blacklist-checker
 
30
  "Checks whether the dsc has blacklisted build-dependencies, ignores
 
31
  the check when no dsc is to be found."
 
32
 
 
33
  [changes profile interface]
 
34
 
 
35
  (if-let [dsc-file (.. changes (get_dsc))]
 
36
    (has-blacklisted? dsc-file (set (get profile "bd-blacklist")))
 
37
    (-> dput.core/logger (.trace "No .dsc found, build-dependencies cannot be checked"))))