2013-03-26 02:37:55 +01:00
|
|
|
#!/usr/bin/env hy
|
2013-04-28 16:31:31 +02:00
|
|
|
;; Copyright (c) Paul R. Tagliamonte <paultag@debian.org>, 2013 under the terms
|
|
|
|
;; of the Expat license, a copy of which you have should have received with
|
|
|
|
;; the source.
|
2013-03-26 02:37:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
(import sys)
|
|
|
|
|
|
|
|
|
|
|
|
(defn parse-rfc822-file [path]
|
|
|
|
"Parse an RFC822 file"
|
|
|
|
(with-as (open path "r") fd
|
2013-04-28 16:31:31 +02:00
|
|
|
(parse-rfc822-stream fd)))
|
2013-03-26 02:37:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
(defn parse-rfc822-stream [fd]
|
|
|
|
"Parse an RFC822 stream"
|
2013-04-01 23:51:28 +02:00
|
|
|
(setv bits {})
|
2015-08-12 00:22:13 +02:00
|
|
|
(setv key None)
|
2013-03-26 02:37:55 +01:00
|
|
|
(for [line fd]
|
|
|
|
(if (in ":" line)
|
2013-04-28 16:31:31 +02:00
|
|
|
(do (setv line (.split line ":" 1))
|
|
|
|
(setv key (.strip (get line 0)))
|
|
|
|
(setv val (.strip (get line 1)))
|
|
|
|
(assoc bits key val))
|
|
|
|
(do
|
|
|
|
(if (= (.strip line) ".")
|
|
|
|
(assoc bits key (+ (get bits key) "\n"))
|
|
|
|
(assoc bits key (+ (get bits key) "\n" (.strip line)))))))
|
2013-03-26 02:37:55 +01:00
|
|
|
bits)
|
|
|
|
|
|
|
|
|
2013-04-01 23:51:28 +02:00
|
|
|
(setv block (parse-rfc822-file (get sys.argv 1)))
|
|
|
|
(setv source (get block "Source"))
|
2013-03-26 02:37:55 +01:00
|
|
|
(print source "is a(n)" (get block "Description"))
|
|
|
|
|
|
|
|
|
2013-04-20 16:06:32 +02:00
|
|
|
(import [sh [apt-cache]])
|
2013-04-01 23:51:28 +02:00
|
|
|
(setv archive-block (parse-rfc822-stream (.show apt-cache source)))
|
2013-03-26 02:37:55 +01:00
|
|
|
(print "The archive has version" (get archive-block "Version") "of" source)
|