Allow to specify some XML fields value as relative to the subdirectory path

This commit is contained in:
Nicolas Évrard
2026-02-24 22:39:38 +01:00
parent 652f497110
commit 7c0d6a295a
5 changed files with 20 additions and 3 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add path attribute on XML fields to specfiy a relative path value
* Allow to include subdirectories in tryton.cfg
* Add route for login / logout with cookie
* Add contextual ``_log`` to force logging events
+4
View File
@@ -218,6 +218,10 @@ Here is the list of valid tags:
``pyson``
Convert the evaluated value into :ref:`PYSON <ref-pyson>` string.
``path``
Prepend to the value the directory name of the path of the configuration
file importing the XML file.
``depends``
Set value only if all modules in the comma separated module list value
are activated.
+12 -2
View File
@@ -2,6 +2,7 @@
# this repository contains the full copyright notices and license terms.
import datetime
import logging
import os.path
import re
import time
from collections import defaultdict
@@ -194,6 +195,7 @@ class RecordTagHandler:
self.current_field = None
self.cdata = None
self.start_cdata = None
self.is_path_field = False
def startElement(self, name, attributes):
@@ -240,6 +242,7 @@ class RecordTagHandler:
ref_attr = attributes.get('ref', '')
eval_attr = attributes.get('eval', '')
pyson_attr = bool(int(attributes.get('pyson', '0')))
self.is_path_field = bool(int(attributes.get('path', '0')))
context = {}
context['time'] = time
@@ -310,6 +313,10 @@ class RecordTagHandler:
self.values[self.current_field] = \
CDATA_END.sub('', self.values[self.current_field])
self.cdata = 'done'
if self.is_path_field:
self.values[self.current_field] = os.path.join(
self.mh.base_path, self.values[self.current_field])
self.is_path_field = False
self.current_field = None
return self
@@ -385,6 +392,7 @@ class TrytondXmlHandler(sax.handler.ContentHandler):
self.skip_data = False
self.modules = modules
self.languages = languages
self.base_path = None
# Tag handlders are used to delegate the processing
self.taghandlerlist = {
@@ -402,11 +410,11 @@ class TrytondXmlHandler(sax.handler.ContentHandler):
self.sax_parser.setFeature(sax.handler.feature_namespaces, 0)
self.sax_parser.setContentHandler(self)
def parse_xmlstream(self, stream):
def parse_xmlstream(self, stream, base_path):
"""
Take a byte stream has input and parse the xml content.
"""
self.base_path = base_path
source = sax.InputSource()
source.setByteStream(stream)
@@ -415,6 +423,8 @@ class TrytondXmlHandler(sax.handler.ContentHandler):
self.sax_parser.parse(source)
except Exception as e:
raise ParsingError("in %s" % self.current_state()) from e
self.base_path = None
return self.to_delete
def startElement(self, name, attributes):
+2 -1
View File
@@ -315,7 +315,8 @@ def load_module_graph(graph, pool, update=None, lang=None, indexes=None):
# Feed the parser with xml content:
with tools.file_open(
os.path.join(module, filename), 'rb') as fp:
tryton_parser.parse_xmlstream(fp)
tryton_parser.parse_xmlstream(
fp, base_path=os.path.dirname(filename))
modules_todo.append((module, list(tryton_parser.to_delete)))
+1
View File
@@ -20,6 +20,7 @@ attlist.field &= attribute search { text }?
attlist.field &= attribute ref { text }?
attlist.field &= attribute eval { text }?
attlist.field &= attribute pyson { "0" | "1" }?
attlist.field &= attribute path { "0" | "1" }?
attlist.field &= attribute type { "xml" }?
attlist.field &= attribute depends { text }?
menuitem = element menuitem { attlist.menuitem, empty }