From a250794432a58e86fbb7e912751e1f48c115a009 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Fri, 26 Jan 2024 09:59:45 +0100 Subject: [PATCH] [FIX] runbot: adapt attrs remove all attrs in xml views To help with that, a scripts was written, minimal but sufficent #!/usr/bin/python3 import glob import re from ast import literal_eval def leaf_to_python(leaf): if len(leaf) != 3: raise ValueError('This script doesnt support leaf', leaf) field, operator, value = leaf if operator == '=': return f'not {field}' if value is False else field if value is True else f'{field} == {value!r}' if operator == '!=': return f'not {field}' if value is True else field if value is False else f'{field} != {value!r}' if operator == 'in': return f'{field} in {value!r}' if operator == 'not in': return f'{field} not in {value!r}' raise ValueError('This script doesnt support operator', operator) for file in glob.glob('**/*.xml', recursive=True): with open(file) as f: content = f.read() attrs_list = re.findall(r'attrs="{.*}"', content) if attrs_list: for attrs in attrs_list: match = re.match(r'''attrs="{'(invisible|readonly)': ?(\[.*\])}"''', attrs) attr = match.groups()[0] domain = literal_eval(match.groups()[1]) condition = ' and '.join([leaf_to_python(leaf) for leaf in domain]) replace = f'{attr}="{condition}"' content = content.replace(attrs, replace) with open(file, 'w') as fw: fw.write(content) --- runbot/views/build_error_views.xml | 18 ++++++++-------- runbot/views/config_views.xml | 22 ++++++++++---------- runbot/views/custom_trigger_wizard_views.xml | 6 +++--- runbot/views/dashboard_views.xml | 6 +++--- runbot/views/dockerfile_views.xml | 2 +- runbot/views/repo_views.xml | 2 +- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/runbot/views/build_error_views.xml b/runbot/views/build_error_views.xml index f80ab77f..570c5818 100644 --- a/runbot/views/build_error_views.xml +++ b/runbot/views/build_error_views.xml @@ -6,8 +6,8 @@
- - + +
@@ -18,13 +18,13 @@ - - + + - + @@ -59,7 +59,7 @@ - + @@ -70,7 +70,7 @@ - + @@ -167,7 +167,7 @@ - + @@ -225,7 +225,7 @@ - +
diff --git a/runbot/views/config_views.xml b/runbot/views/config_views.xml index 77e77a8b..05308eb5 100644 --- a/runbot/views/config_views.xml +++ b/runbot/views/config_views.xml @@ -6,7 +6,7 @@ -
+
This record is protected and can only be edited by config administrator.
@@ -35,7 +35,7 @@ -
+
This record is protected and can only be edited by config administrator.
@@ -48,7 +48,7 @@ - + @@ -57,34 +57,34 @@ - + - + - + - + - + - + @@ -110,12 +110,12 @@ - + - + diff --git a/runbot/views/custom_trigger_wizard_views.xml b/runbot/views/custom_trigger_wizard_views.xml index d70241e9..ef505a1a 100644 --- a/runbot/views/custom_trigger_wizard_views.xml +++ b/runbot/views/custom_trigger_wizard_views.xml @@ -20,9 +20,9 @@ - - - + + + diff --git a/runbot/views/dashboard_views.xml b/runbot/views/dashboard_views.xml index 05c43e27..dace2bb9 100644 --- a/runbot/views/dashboard_views.xml +++ b/runbot/views/dashboard_views.xml @@ -25,7 +25,7 @@ - + @@ -40,11 +40,11 @@ - + - + diff --git a/runbot/views/dockerfile_views.xml b/runbot/views/dockerfile_views.xml index 9ffa18da..2858f6d2 100644 --- a/runbot/views/dockerfile_views.xml +++ b/runbot/views/dockerfile_views.xml @@ -6,7 +6,7 @@ - + diff --git a/runbot/views/repo_views.xml b/runbot/views/repo_views.xml index f651422e..49b4af5b 100644 --- a/runbot/views/repo_views.xml +++ b/runbot/views/repo_views.xml @@ -8,7 +8,7 @@
- +