[FIX]Hy Base : handle python2 case

This commit is contained in:
Fabien BOURGEOIS 2019-09-18 09:26:07 +02:00
parent d2e8abff37
commit 68f6c68696
1 changed files with 11 additions and 2 deletions

13
odoo.hy
View File

@ -19,6 +19,13 @@
(require [odoo.addons.hy_base.xml [*]]) (require [odoo.addons.hy_base.xml [*]])
(defmacro if-python2 [python2-form python3-form]
"If running on python2, execute python2-form, else, execute python3-form"
(import sys)
(if (< (get sys.version_info 0) 3)
python2-form
python3-form))
(defmacro ox-odoo [&rest args] `(xmlr "odoo" ~@args)) (defmacro ox-odoo [&rest args] `(xmlr "odoo" ~@args))
(defmacro ox-data [&rest args] `(xmlnc "data" ~@args)) (defmacro ox-data [&rest args] `(xmlnc "data" ~@args))
(defmacro ox-record [&rest args] `(xmlnc "record" ~@args)) (defmacro ox-record [&rest args] `(xmlnc "record" ~@args))
@ -63,7 +70,9 @@
"Write XML file according to filename and given tree" "Write XML file according to filename and given tree"
`(do `(do
(import [os [path]]) (import [os [path]])
(setv ~g!output-xml (.tostring ET ~tree) (if-python2
~g!output-path (.dirname path (.abspath path __file__)) (setv ~g!output-xml (.tostring ET ~tree))
(setv ~g!output-xml (.decode (.tostring ET ~tree) "utf-8")))
(setv ~g!output-path (.dirname path (.abspath path __file__))
~g!fpath (+ ~g!output-path "/" ~filename)) ~g!fpath (+ ~g!output-path "/" ~filename))
(with [f (open ~g!fpath "w")] (.write f ~g!output-xml)))) (with [f (open ~g!fpath "w")] (.write f ~g!output-xml))))