From 703250c34f81b6ac39963dbfa775a4bc8f33a5f4 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sun, 28 Nov 2021 17:04:47 +0100 Subject: [PATCH] reorder dictionaries not only in same directory --- src/rougail/xmlreflector.py | 37 +++++++++++-------- .../00load_subfolder/tiramisu/base.py | 4 +- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/rougail/xmlreflector.py b/src/rougail/xmlreflector.py index 19e7831d1..6021f1aa9 100644 --- a/src/rougail/xmlreflector.py +++ b/src/rougail/xmlreflector.py @@ -61,19 +61,26 @@ class XMLReflector: :param xmlfolders: list of full folder's name """ + filenames = {} for xmlfolder in xmlfolders: - filenames = [join(xmlfolder, filename) for filename in listdir(xmlfolder) if \ - filename.endswith('.xml')] - filenames.sort() - if not filenames: - raise DictConsistencyError(_('there is no XML file'), 77, [xmlfolder]) - for xmlfile in filenames: - try: - document = parse(xmlfile) - except XMLSyntaxError as err: - raise DictConsistencyError(_(f'not a XML file: {err}'), 52, [xmlfile]) from err - if not self.dtd.validate(document): - dtd_error = self.dtd.error_log.filter_from_errors()[0] - msg = _(f'not a valid XML file: {dtd_error}') - raise DictConsistencyError(msg, 43, [xmlfile]) - yield xmlfile, document.getroot() + for filename in listdir(xmlfolder): + if not filename.endswith('.xml'): + continue + if filename in filenames: + raise DictConsistencyError(_(f'duplicate xml file name {filename}'), 78, [xmlfolder]) + filenames[filename] = join(xmlfolder, filename) + if not filenames: + raise DictConsistencyError(_('there is no XML file'), 77, [xmlfolder]) + file_names = list(filenames.keys()) + file_names.sort() + for filename in file_names: + xmlfile = filenames[filename] + try: + document = parse(xmlfile) + except XMLSyntaxError as err: + raise DictConsistencyError(_(f'not a XML file: {err}'), 52, [xmlfile]) from err + if not self.dtd.validate(document): + dtd_error = self.dtd.error_log.filter_from_errors()[0] + msg = _(f'not a valid XML file: {dtd_error}') + raise DictConsistencyError(msg, 43, [xmlfile]) + yield xmlfile, document.getroot() diff --git a/tests/dictionaries/00load_subfolder/tiramisu/base.py b/tests/dictionaries/00load_subfolder/tiramisu/base.py index 9ffd7df51..f5981b865 100644 --- a/tests/dictionaries/00load_subfolder/tiramisu/base.py +++ b/tests/dictionaries/00load_subfolder/tiramisu/base.py @@ -14,8 +14,8 @@ try: from tiramisu3 import * except: from tiramisu import * -option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"})) -option_4 = StrOption(name="mode_conteneur_actif1", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"})) +option_3 = StrOption(name="mode_conteneur_actif1", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"})) +option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"})) option_2 = OptionDescription(name="general", doc="général", children=[option_3, option_4], properties=frozenset({"normal"})) option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])