From bafa2c7ad0d12cf841446705b1d597059ce2a6b0 Mon Sep 17 00:00:00 2001
From: Hakim Achterberg <hakim.achterberg@gmail.com>
Date: Tue, 6 Feb 2024 11:42:00 +0100
Subject: [PATCH] Change subsituation used in use of header.py so it will not
give an error in import, fixing issue #57 with the smoke test unable to
import header.py
---
xnat/convert_xsd.py | 7 +++++--
xnat/header.py | 12 ++++++------
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/xnat/convert_xsd.py b/xnat/convert_xsd.py
index 5e51da8..a1cd694 100644
--- a/xnat/convert_xsd.py
+++ b/xnat/convert_xsd.py
@@ -23,6 +23,7 @@ import inspect
import keyword
import os
import re
+from string import Template
from xml.etree import ElementTree
from . import core
@@ -1340,7 +1341,9 @@ class SchemaParser(object):
self.logger.info('Writing result')
schemas = '\n'.join('# - {}'.format(s) for s in self.schemas)
- code_file.write(FILE_HEADER.format(schemas=schemas,
- file_secondary_lookup=SECONDARY_LOOKUP_FIELDS['xnat:fileData']))
+ string_template = Template(FILE_HEADER)
+ code_str = string_template.safe_substitute(SCHEMAS=schemas,
+ FILE_SECONDARY_LOOKUP=SECONDARY_LOOKUP_FIELDS['xnat:fileData'])
+ code_file.write(code_str)
code_file.write('\n\n\n'.join(c.tostring().strip() for c in self if c.name is not None))
diff --git a/xnat/header.py b/xnat/header.py
index 781b941..f37c9e9 100644
--- a/xnat/header.py
+++ b/xnat/header.py
@@ -69,7 +69,7 @@ class XNATSubObjectMixin(XNATSubObject):
class FileData(XNATObjectMixin):
- SECONDARY_LOOKUP_FIELD = "{file_secondary_lookup}"
+ SECONDARY_LOOKUP_FIELD = "$FILE_SECONDARY_LOOKUP"
_XSI_TYPE = 'xnat:fileData'
def __init__(self, uri=None, xnat_session=None, id_=None, datafields=None, parent=None, fieldname=None, overwrites=None, name=None):
@@ -188,23 +188,23 @@ class FileData(XNATObjectMixin):
if parent.data_dir is None:
return None
- data_path = f"{{parent.data_dir}}/{{self.path}}"
+ data_path = f"{parent.data_dir}/{self.path}"
if not os.path.exists(data_path):
- self.logger.info(f'Determined data_path to be {{data_path}}, but it does not exist!')
+ self.logger.info(f'Determined data_path to be {data_path}, but it does not exist!')
return None
return data_path
# Empty class lookup to place all new lookup values
-XNAT_CLASS_LOOKUP = {{
+XNAT_CLASS_LOOKUP = {
"xnat:fileData": FileData,
-}}
+}
# The following code represents the data structure of the XNAT server
# It is automatically generated using
-# {schemas}
+# $SCHEMAS
--
GitLab