From 7db3e2c2a9130b2b2cd9683acb0461ff9c16872b Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 18 Nov 2020 22:18:16 +0100 Subject: [PATCH] allow filename with \ --- src/rougail/template.py | 17 +++++++++++- .../01base_file_utfchar/00-base.xml | 20 ++++++++++++++ .../01base_file_utfchar/__init__.py | 0 .../01base_file_utfchar/makedict/base.json | 1 + .../systemd-makefs@dev-disk-by\\x2dpartlabel" | 1 + .../01base_file_utfchar/tiramisu/__init__.py | 0 .../01base_file_utfchar/tiramisu/base.py | 26 +++++++++++++++++++ .../systemd-makefs@dev-disk-by\\x2dpartlabel" | 1 + .../40empty_param/makedict/base.json | 1 - .../40empty_param2/makedict/base.json | 1 - tests/test_2_makedict.py | 4 +-- 11 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 tests/dictionaries/01base_file_utfchar/00-base.xml create mode 100644 tests/dictionaries/01base_file_utfchar/__init__.py create mode 100644 tests/dictionaries/01base_file_utfchar/makedict/base.json create mode 100644 "tests/dictionaries/01base_file_utfchar/result/etc/systemd-makefs@dev-disk-by\\x2dpartlabel" create mode 100644 tests/dictionaries/01base_file_utfchar/tiramisu/__init__.py create mode 100644 tests/dictionaries/01base_file_utfchar/tiramisu/base.py create mode 100644 "tests/dictionaries/01base_file_utfchar/tmpl/systemd-makefs@dev-disk-by\\x2dpartlabel" diff --git a/src/rougail/template.py b/src/rougail/template.py index a2d583b3..a38d7e69 100644 --- a/src/rougail/template.py +++ b/src/rougail/template.py @@ -10,7 +10,7 @@ import logging from typing import Dict, Any from subprocess import call from os import listdir, makedirs -from os.path import dirname, join, isfile +from os.path import dirname, join, isfile, abspath, normpath from Cheetah.Template import Template as ChtTemplate from Cheetah.NameMapper import NotFound as CheetahNotFound @@ -92,6 +92,21 @@ class CheetahTemplate(ChtTemplate): file=filename, searchList=[context, eosfunc, extra_context]) + # FORK of Cheetah fonction, do not replace '\\' by '/' + def serverSidePath(self, path=None, + normpath=normpath, + abspath=abspath + ): + + if path: + return normpath(abspath(path)) +# return normpath(abspath(path.replace("\\", '/'))) + elif hasattr(self, '_filePath') and self._filePath: + return normpath(abspath(self._filePath)) + else: + return None + + class CreoleLeader: def __init__(self, value, follower=None, index=None): diff --git a/tests/dictionaries/01base_file_utfchar/00-base.xml b/tests/dictionaries/01base_file_utfchar/00-base.xml new file mode 100644 index 00000000..1cc04c79 --- /dev/null +++ b/tests/dictionaries/01base_file_utfchar/00-base.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + non + + + + + + diff --git a/tests/dictionaries/01base_file_utfchar/__init__.py b/tests/dictionaries/01base_file_utfchar/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/01base_file_utfchar/makedict/base.json b/tests/dictionaries/01base_file_utfchar/makedict/base.json new file mode 100644 index 00000000..8dc1e947 --- /dev/null +++ b/tests/dictionaries/01base_file_utfchar/makedict/base.json @@ -0,0 +1 @@ +{"rougail.general.mode_conteneur_actif": "non", "services.test.files.systemd_makefs@dev_disk_by\\x2dpartlabel.group": "root", "services.test.files.systemd_makefs@dev_disk_by\\x2dpartlabel.mode": "0644", "services.test.files.systemd_makefs@dev_disk_by\\x2dpartlabel.name": "/etc/systemd-makefs@dev-disk-by\\x2dpartlabel", "services.test.files.systemd_makefs@dev_disk_by\\x2dpartlabel.owner": "root", "services.test.files.systemd_makefs@dev_disk_by\\x2dpartlabel.source": "systemd-makefs@dev-disk-by\\x2dpartlabel", "services.test.files.systemd_makefs@dev_disk_by\\x2dpartlabel.templating": true, "services.test.files.systemd_makefs@dev_disk_by\\x2dpartlabel.activate": true} diff --git "a/tests/dictionaries/01base_file_utfchar/result/etc/systemd-makefs@dev-disk-by\\x2dpartlabel" "b/tests/dictionaries/01base_file_utfchar/result/etc/systemd-makefs@dev-disk-by\\x2dpartlabel" new file mode 100644 index 00000000..d907505b --- /dev/null +++ "b/tests/dictionaries/01base_file_utfchar/result/etc/systemd-makefs@dev-disk-by\\x2dpartlabel" @@ -0,0 +1 @@ +non diff --git a/tests/dictionaries/01base_file_utfchar/tiramisu/__init__.py b/tests/dictionaries/01base_file_utfchar/tiramisu/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/01base_file_utfchar/tiramisu/base.py b/tests/dictionaries/01base_file_utfchar/tiramisu/base.py new file mode 100644 index 00000000..40fbf605 --- /dev/null +++ b/tests/dictionaries/01base_file_utfchar/tiramisu/base.py @@ -0,0 +1,26 @@ +import imp +func = imp.load_source('func', 'tests/dictionaries/../eosfunc/test.py') +for key, value in dict(locals()).items(): + if key != ['imp', 'func']: + setattr(func, key, value) +try: + from tiramisu3 import * +except: + from tiramisu import * +from rougail.tiramisu import ConvertDynOptionDescription +option_3 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='Description', multi=False, default='non', values=('oui', 'non')) +option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3]) +option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2]) +option_8 = StrOption(name='group', doc='group', multi=False, default='root') +option_9 = StrOption(name='mode', doc='mode', multi=False, default='0644') +option_10 = StrOption(name='name', doc='name', multi=False, default='/etc/systemd-makefs@dev-disk-by\\x2dpartlabel') +option_11 = StrOption(name='owner', doc='owner', multi=False, default='root') +option_12 = StrOption(name='source', doc='source', multi=False, default='systemd-makefs@dev-disk-by\\x2dpartlabel') +option_13 = BoolOption(name='templating', doc='templating', multi=False, default=True) +option_14 = BoolOption(name='activate', doc='activate', multi=False, default=True) +option_7 = OptionDescription(name='systemd_makefs@dev_disk_by\\x2dpartlabel', doc='systemd-makefs@dev-disk-by\\x2dpartlabel', children=[option_8, option_9, option_10, option_11, option_12, option_13, option_14]) +option_6 = OptionDescription(name='files', doc='files', children=[option_7]) +option_5 = OptionDescription(name='test', doc='test', children=[option_6]) +option_5.impl_set_information("manage", True) +option_4 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_5]) +option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_4]) diff --git "a/tests/dictionaries/01base_file_utfchar/tmpl/systemd-makefs@dev-disk-by\\x2dpartlabel" "b/tests/dictionaries/01base_file_utfchar/tmpl/systemd-makefs@dev-disk-by\\x2dpartlabel" new file mode 100644 index 00000000..a29cfeaf --- /dev/null +++ "b/tests/dictionaries/01base_file_utfchar/tmpl/systemd-makefs@dev-disk-by\\x2dpartlabel" @@ -0,0 +1 @@ +%%mode_conteneur_actif diff --git a/tests/dictionaries/40empty_param/makedict/base.json b/tests/dictionaries/40empty_param/makedict/base.json index e5019d07..0dd31190 100644 --- a/tests/dictionaries/40empty_param/makedict/base.json +++ b/tests/dictionaries/40empty_param/makedict/base.json @@ -1,2 +1 @@ {"rougail.proxy_authentifie.toto1": null, "rougail.proxy_authentifie.toto2": "3127"} - diff --git a/tests/dictionaries/40empty_param2/makedict/base.json b/tests/dictionaries/40empty_param2/makedict/base.json index e5019d07..0dd31190 100644 --- a/tests/dictionaries/40empty_param2/makedict/base.json +++ b/tests/dictionaries/40empty_param2/makedict/base.json @@ -1,2 +1 @@ {"rougail.proxy_authentifie.toto1": null, "rougail.proxy_authentifie.toto2": "3127"} - diff --git a/tests/test_2_makedict.py b/tests/test_2_makedict.py index ba438859..a823fe23 100644 --- a/tests/test_2_makedict.py +++ b/tests/test_2_makedict.py @@ -17,6 +17,8 @@ for test in listdir(dico_dirs): if isdir(join(dico_dirs, test, 'tiramisu')): test_ok.add(test) +debug = False +#debug = True excludes = set([]) #excludes = set(['70container_services']) test_ok -= excludes @@ -33,8 +35,6 @@ def test_dir(request): async def launch_flattener(test_dir): - debug = False - #debug = True makedict_dir = join(test_dir, 'makedict') makedict_file = join(makedict_dir, 'base.json')