[REF]Hy Odoo repackging
This commit is contained in:
parent
48a14d8dd9
commit
b260bf1f8d
@ -16,4 +16,4 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import hy
|
||||
from . import odoo
|
||||
from . import odoo, xml
|
||||
|
@ -18,16 +18,7 @@
|
||||
" Odoo macros "
|
||||
|
||||
(import [os [path]])
|
||||
(import logging)
|
||||
(import [hy-odoo.xml [xmlroot xmln]])
|
||||
(setv logger (.getLogger logging __name__))
|
||||
|
||||
(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))
|
||||
|
||||
; XML helpers functions and macros
|
||||
|
||||
@ -104,19 +95,6 @@
|
||||
(ox-field {"name" "model" "eval" (+ "'" model "'")} [])
|
||||
(ox-field {"name" "value" "eval" action})]))
|
||||
|
||||
(defmacro/g! xml-write [filename tree]
|
||||
"Write XML file according to filename and given tree"
|
||||
`(do
|
||||
(import [os [path]]
|
||||
[xml.etree.ElementTree :as ET])
|
||||
(if-python2
|
||||
(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))
|
||||
(.debug logger (+ "Hy XML DSL : compiling " ~filename " to " ~g!output-path))
|
||||
(with [f (open ~g!fpath "w")] (.write f ~g!output-xml))))
|
||||
|
||||
; Odoo Backend macros
|
||||
|
||||
(defmacro/g! compute-fn [field dependencies body]
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
(import [xml.etree.ElementTree :as ET])
|
||||
|
||||
;; Helpers
|
||||
|
||||
(defn xmlroot [tree]
|
||||
"Special process for root XML Node"
|
||||
(setv rootel (.Element ET (get tree "tag") (get tree "attrs"))
|
||||
@ -45,3 +47,24 @@
|
||||
(if (instance? list attrs)
|
||||
(do (setv children attrs) (setv attrs {}))))
|
||||
{"tag" tag "attrs" (or attrs {}) "children" (or children [])})
|
||||
|
||||
;; Macros
|
||||
|
||||
(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/g! xml-write [filename tree]
|
||||
"Write XML file according to filename and given tree"
|
||||
`(do
|
||||
(import [os [path]]
|
||||
[xml.etree.ElementTree :as ET])
|
||||
(if-python2
|
||||
(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))
|
||||
(with [f (open ~g!fpath "w")] (.write f ~g!output-xml))))
|
||||
|
Loading…
Reference in New Issue
Block a user