hy/scripts/reformat-changelog
Gergely Nagy 9f88e07e1d Drop a set of brackets from let.
This changes let to use a flat list of symbol-value pairs instead of a
vector of vectors. One side effect is that (let [[a 1] z]) is not
expressible now, and one will explicitly need to set a nil value for z,
such as: (let [a 1 z nil]).

Closes #713.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-10-01 10:08:04 +02:00

67 lines
1.9 KiB
Hy
Executable File

#!/usr/bin/env hy
(import re)
(import pdb)
(import codecs)
(setv *maintainer-line*
" -- Alexander Artemenko <svetlyak.40wt@gmail.com> Thu, 30 Sep 2014 13:06:09 +0400")
(defn read-lines-from-file [filename]
(let [f (codecs.open filename "r" "utf-8")]
(fn [] (let [line (.readline f) ]
line))))
(defn get-version-number [line]
(let [match (re.search r"Changes from.*(\d+\.\d+\.\d+)$" line)]
(if match
(let [version (.group match (int 1))
numbered (list (map int (.split version ".")))
explicit-mapping {"0.9.12" "0.10.0"
"0.8.2" "0.9.0"}]
(assoc numbered 2 (+ (get numbered 2) 1))
(.get explicit-mapping
version
(.join "." (map str numbered)))))))
(defn read-version-content [reader]
(setv line (reader))
(setv content [])
(while (and line (not (get-version-number line)))
(.append content (.strip line))
(setv line (reader)))
[content line])
(defn read-versions-from-file [filename]
(let [reader (read-lines-from-file filename)]
(read-versions-rec (reader)
reader)))
(defn read-versions-rec [line reader]
(if line
(let [version (get-version-number line)
[content next-line] (read-version-content reader)]
(+ [{"from" version
"content" content}]
(read-versions-rec next-line reader)))
[]))
(defn format-deb-version [version]
(setv result [(.format "hy ({}) unstable; urgency=low"
(get version "from"))])
(for [line (get version "content")]
(.append result (+ " " line)))
(.append result *maintainer-line*)
(.append result "")
(.join "\n" result))
(defmain [&rest args]
(let [versions (read-versions-from-file "NEWS")]
(for [version versions]
(print (.encode (format-deb-version version) "utf-8")))))