details: https://code.tryton.org/tryton/commit/a40ad82e4bae
branch: default
user: Nicolas Évrard <[email protected]>
date: Tue Feb 24 22:39:38 2026 +0100
description:
Allow to specify some XML fields value as relative to the subdirectory
path
diffstat:
trytond/CHANGELOG | 1 +
trytond/doc/topics/modules/index.rst | 4 ++++
trytond/trytond/convert.py | 14 ++++++++++++--
trytond/trytond/modules/__init__.py | 3 ++-
trytond/trytond/tryton.rnc | 1 +
5 files changed, 20 insertions(+), 3 deletions(-)
diffs (115 lines):
diff -r 7e5cc250906c -r a40ad82e4bae trytond/CHANGELOG
--- a/trytond/CHANGELOG Sat Feb 28 00:16:45 2026 +0100
+++ b/trytond/CHANGELOG Tue Feb 24 22:39:38 2026 +0100
@@ -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
diff -r 7e5cc250906c -r a40ad82e4bae trytond/doc/topics/modules/index.rst
--- a/trytond/doc/topics/modules/index.rst Sat Feb 28 00:16:45 2026 +0100
+++ b/trytond/doc/topics/modules/index.rst Tue Feb 24 22:39:38 2026 +0100
@@ -218,6 +218,10 @@
``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.
diff -r 7e5cc250906c -r a40ad82e4bae trytond/trytond/convert.py
--- a/trytond/trytond/convert.py Sat Feb 28 00:16:45 2026 +0100
+++ b/trytond/trytond/convert.py Tue Feb 24 22:39:38 2026 +0100
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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):
diff -r 7e5cc250906c -r a40ad82e4bae trytond/trytond/modules/__init__.py
--- a/trytond/trytond/modules/__init__.py Sat Feb 28 00:16:45 2026 +0100
+++ b/trytond/trytond/modules/__init__.py Tue Feb 24 22:39:38 2026 +0100
@@ -315,7 +315,8 @@
# 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)))
diff -r 7e5cc250906c -r a40ad82e4bae trytond/trytond/tryton.rnc
--- a/trytond/trytond/tryton.rnc Sat Feb 28 00:16:45 2026 +0100
+++ b/trytond/trytond/tryton.rnc Tue Feb 24 22:39:38 2026 +0100
@@ -20,6 +20,7 @@
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 }