[ADD]Hy base : add xml-write macro

This commit is contained in:
Fabien BOURGEOIS 2019-09-16 16:47:29 +02:00
parent 8eb4c0e294
commit b8462951e0

View File

@ -48,3 +48,12 @@
(defmacro field-model [model] `(field {"name" "model"} [~model]))
(defmacro field-inherit [xmlid] `(field {"name" "inherit_id" "ref" ~xmlid} []))
(defmacro field-arch [&rest args] `(field {"name" "arch" "type" "xml"} ~@args))
(defmacro xml-write [filename tree]
"Write XML file according to filename and given tree"
`(do
(import [os [path]])
(setv elementtree ~tree)
(setv output (.tostring ET elementtree))
(setv fpath (+ (.dirname path (.abspath path __file__)) "/" ~filename))
(with [f (open fpath "w")] (.write f output))))