diff --git a/doc/check/redefine.md b/doc/check/redefine.md index 8b1fbde76..fedf67dfd 100644 --- a/doc/check/redefine.md +++ b/doc/check/redefine.md @@ -47,7 +47,7 @@ En YAML : variables: - variable: name: my_variable - redefine: 'True' + redefine: true constraints: - check: - name: isspace @@ -103,6 +103,6 @@ En YAML : variables: - variable: name: my_variable - redefine: 'True' - remove_check: 'True' + redefine: true + remove_check: true ``` diff --git a/doc/condition/condition.md b/doc/condition/condition.md index 890d4a901..9821885a4 100644 --- a/doc/condition/condition.md +++ b/doc/condition/condition.md @@ -36,7 +36,7 @@ constraints: - name: hidden_if_in source: condition param: - - text: 'True' + - text: true target: - text: my_variable ``` @@ -119,8 +119,8 @@ En YAML : - condition: - name: hidden_if_in source: condition - optional: 'True' - apply_on_fallback: 'False' + optional: true + apply_on_fallback: false param: - text: 'yes' - text: 'maybe' diff --git a/doc/condition/redefine.md b/doc/condition/redefine.md index bcaa5443c..664f8c90c 100644 --- a/doc/condition/redefine.md +++ b/doc/condition/redefine.md @@ -34,7 +34,7 @@ constraints: - name: hidden_if_in source: condition param: - - text: 'True' + - text: true target: - text: my_variable ``` @@ -53,6 +53,6 @@ En YAML : variables: - variable: name: condition - redefine: 'True' - remove_condition: 'True' + redefine: true + remove_condition: true ``` diff --git a/doc/family/auto.md b/doc/family/auto.md index fdd31de70..55f516bc0 100644 --- a/doc/family/auto.md +++ b/doc/family/auto.md @@ -21,7 +21,7 @@ En YAML : variables: - variable: name: variable - multi: 'True' + multi: true value: - text: 'val1' - text: 'val2' diff --git a/doc/family/leadership.md b/doc/family/leadership.md index 7fa395276..838267c12 100644 --- a/doc/family/leadership.md +++ b/doc/family/leadership.md @@ -49,16 +49,16 @@ En YAML : variables: - family: name: family - leadership: 'True' + leadership: true variables: - variable: name: leader - multi: 'True' + multi: true - variable: name: follower1 - variable: name: follower2 - multi: 'True' + multi: true ``` ## Ajout d'une nouvelle variable suiveuse diff --git a/doc/family/simple.md b/doc/family/simple.md index 2705218e8..c3f545c14 100644 --- a/doc/family/simple.md +++ b/doc/family/simple.md @@ -124,5 +124,5 @@ En YAML : ``` - family: name: my_family - hidden: 'True' + hidden: true ``` diff --git a/doc/fill/examples.md b/doc/fill/examples.md index f8c8954e3..64808705b 100644 --- a/doc/fill/examples.md +++ b/doc/fill/examples.md @@ -22,7 +22,7 @@ variables: - variable: name: zones_list type: string - multi: 'True' + multi: true value: - text: 'zone1' - text: 'zone2' @@ -30,8 +30,8 @@ variables: - variable: name: netwokd_configurations type: filename - multi: 'True' - hidden: 'True' + multi: true + hidden: true ``` Calculons la valeur de la seconde variable à partir de la première : @@ -63,7 +63,7 @@ constraints: - name: join - name: multi type: boolean - text: 'True' + text: true target: - text: netwokd_configurations ``` diff --git a/doc/fill/redefine.md b/doc/fill/redefine.md index a701f52e1..42fd5a49e 100644 --- a/doc/fill/redefine.md +++ b/doc/fill/redefine.md @@ -47,7 +47,7 @@ En YAML : variables: - variable: name: my_calculated_variable - redefine: 'True' + redefine: true constraints: - fill: - name: return_yes @@ -103,6 +103,6 @@ En YAML : variables: - variable: name: my_calculated_variable - redefine: 'True' - remove_fill: 'True' + redefine: true + remove_fill: true ``` diff --git a/doc/fill/value.md b/doc/fill/value.md index 03fd61dd6..effe360c1 100644 --- a/doc/fill/value.md +++ b/doc/fill/value.md @@ -75,7 +75,7 @@ En YAML : variables: - variable: name: my_calculated_variable - hidden: 'True' + hidden: true ``` Si une condition "hidden_if_in" est spécifié à la variable, la valeur sera modifiable par l'utilisateur si elle n'est pas cachée mais elle sera systèmatiquement calculée (même si elle a déjà était modifiée) si la variable est cachée. @@ -121,7 +121,7 @@ variables: name: suffixes type: string description: Suffixes of dynamic family - multi: 'True' + multi: true value: - text: val1 - text: val2 diff --git a/doc/param/simple.md b/doc/param/simple.md index 80ac70e88..9890d5204 100644 --- a/doc/param/simple.md +++ b/doc/param/simple.md @@ -56,7 +56,7 @@ En YAML : ``` param: - type: boolean - text: 'True' + text: true ``` # Paramètre de type "nil" diff --git a/doc/param/variable.md b/doc/param/variable.md index 0d8854a11..5e6e1ac64 100644 --- a/doc/param/variable.md +++ b/doc/param/variable.md @@ -31,7 +31,7 @@ En YAML : ``` param: - type: variable - optional: 'True' + optional: true text: unknow_variable ``` @@ -54,7 +54,7 @@ En YAML : ``` param: - type: variable - propertyerror: 'False' + propertyerror: false text: variable1 ``` diff --git a/doc/service/README.md b/doc/service/README.md index c2247b9bc..c5f07d7b7 100644 --- a/doc/service/README.md +++ b/doc/service/README.md @@ -101,7 +101,7 @@ En YAML : ``` - service: - name: ldap_client - manage: 'False' + manage: false ``` Un service factice est généralement une service qui n'existe pas réellement (par exemple si on configure un client). Il n'est là que pour contenir des fichiers. @@ -119,7 +119,7 @@ En YAML : ``` - service: - name: test - disabled: 'True' + disabled: true ``` Dans ce cas, le service et les éléments qu'il compose ([fichier](file.md), [IP](ip.md) et [réécriture](override.md) seront désactivés. @@ -158,7 +158,7 @@ constraints: name: disabled_if_in source: condition param: - - text: 'False' + - text: false target: - type: servicelist text: test @@ -181,6 +181,6 @@ En YAML : ``` - service: - name: test - disabled: 'True' - undisable: 'True' + disabled: true + undisable: true ``` diff --git a/doc/service/file.md b/doc/service/file.md index b80b99a7c..168061b4e 100644 --- a/doc/service/file.md +++ b/doc/service/file.md @@ -109,7 +109,7 @@ services: variables: - variable: name: my_variable - multi: 'True' + multi: true value: - text: /etc/squid1/squid.conf - text: /etc/squid2/squid.conf @@ -157,13 +157,13 @@ services: variables: - variable: name: my_variable1 - multi: 'True' + multi: true value: - text: /etc/squid1/squid.conf - text: /etc/squid2/squid.conf - variable: name: my_variable2 - multi: 'True' + multi: true value: - text: squid1 - text: squid2 @@ -207,7 +207,7 @@ En YAML : ``` file: -- disabled: 'True' +- disabled: true text: /etc/squid/squid.conf ``` @@ -248,7 +248,7 @@ constraints: - name: disabled_if_in source: condition param: - - text: 'False' + - text: false target: - type: filelist text: squid diff --git a/doc/service/ip.md b/doc/service/ip.md index 0dc67e070..b1f2d98e5 100644 --- a/doc/service/ip.md +++ b/doc/service/ip.md @@ -81,7 +81,7 @@ constraints: - name: disabled_if_in source: condition param: - - text: 'False' + - text: false target: - type: iplist text: test_ip diff --git a/doc/target/family.md b/doc/target/family.md index e75de3070..a324ccae7 100644 --- a/doc/target/family.md +++ b/doc/target/family.md @@ -25,6 +25,6 @@ En YAML : ``` target: - type: family - optional: 'True' + optional: true text: my_family ``` diff --git a/doc/target/list.md b/doc/target/list.md index 8a0e6e198..b1625ebe7 100644 --- a/doc/target/list.md +++ b/doc/target/list.md @@ -63,6 +63,6 @@ En YAML : ``` target: - type: filelist - optional: 'True' + optional: true text: unknown ``` diff --git a/doc/target/variable.md b/doc/target/variable.md index 8b443a1ec..c40ce188c 100644 --- a/doc/target/variable.md +++ b/doc/target/variable.md @@ -23,6 +23,6 @@ En YAML : ``` target: -- optional: 'True' +- optional: true text: my_variable ``` diff --git a/doc/variable/README.md b/doc/variable/README.md index ea32dccc4..765b1d39f 100644 --- a/doc/variable/README.md +++ b/doc/variable/README.md @@ -120,7 +120,7 @@ En YAML : ``` - variable: name: my_variable - multi: 'True' + multi: true ``` ## Variable invisible @@ -141,7 +141,7 @@ En YAML : ``` - variable: name: my_variable - hidden: 'True' + hidden: true ``` ## Variable désactive @@ -161,7 +161,7 @@ En YAML : ``` - variable: name: my_variable - disabled: 'True' + disabled: true ``` ## Variable obligatoire @@ -177,7 +177,7 @@ En YAML : ``` - variable: name: my_variable - mandatory: 'True' + mandatory: true ``` Les variables booléans sont par défaut obligatoire. Pour qu'une variable booléan ne soit pas obligatoire il faut le préciser explicitement : @@ -192,7 +192,7 @@ En YAML : - variable: name: my_variable type: boolean - mandatory: 'False' + mandatory: false ``` Les variables avec une valeur par défaut (non calculée) sont également automatiquement obligatoire. @@ -230,7 +230,7 @@ En YAML : ``` - variable: name: my_variable - multi: 'True' + multi: true value: - text: value 1 - text: value 2 @@ -274,7 +274,7 @@ En YAML : ``` - variable: name: my_variable - redefine: 'True' + redefine: true description: New description ``` @@ -291,7 +291,7 @@ En YAML : ``` - variable: name: my_variable - exists: 'False' + exists: false ``` Si cette variable existe dans un autre dictionnaire, elle ne sera pas modifié ni recréé @@ -309,8 +309,8 @@ En YAML : ``` - variable: name: my_variable - exists: 'True' - hidden: 'True' + exists: true + hidden: true ``` ## Variable à valeur automatiquement modifiée @@ -330,7 +330,7 @@ En YAML : ``` - variable: name: my_variable - auto_save: 'True' + auto_save: true value: - text: my_value ``` @@ -365,7 +365,7 @@ En YAML : - text: 'False - variable: name: my_variable - auto_freeze: 'True' + auto_freeze: true ``` Dans ce cas la valeur est fixée à la valeur actuelle et elle ne sera plus modifiable par l'utilisateur. diff --git a/doc/variable/choice.md b/doc/variable/choice.md index 26bffb674..c47d04110 100644 --- a/doc/variable/choice.md +++ b/doc/variable/choice.md @@ -79,7 +79,7 @@ En YAML : - type: number text: '3' - type: boolean - text: 'True' + text: true - type: 'nil' ``` @@ -100,7 +100,7 @@ En YAML : ``` - variable: name: my_variable - redefine: 'True' + redefine: true choice: - text: val4 ``` @@ -121,8 +121,8 @@ En YAML : ``` - variable: name: my_variable - redefine: 'True' - remove_choice: 'True' + redefine: true + remove_choice: true choice: - text: val1 - text: val2 diff --git a/src/rougail/annotator/property.py b/src/rougail/annotator/property.py index f90168852..0ce81be70 100644 --- a/src/rougail/annotator/property.py +++ b/src/rougail/annotator/property.py @@ -84,7 +84,7 @@ class Annotator(Walk): variable.properties.append(prop) setattr(variable, prop, None) if hasattr(variable, 'unique') and variable.unique != 'nil': - if variable.unique == 'False': + if variable.unique == 'False' or variable.unique is False: variable.properties.append('notunique') else: variable.properties.append('unique') diff --git a/src/rougail/annotator/variable.py b/src/rougail/annotator/variable.py index a45702904..de629b13d 100644 --- a/src/rougail/annotator/variable.py +++ b/src/rougail/annotator/variable.py @@ -168,7 +168,11 @@ class Annotator(Walk): # pylint: disable=R0903 else: if not hasattr(value, 'type'): value.type = variable.type - value.name = CONVERT_OPTION.get(value.type, {}).get('func', str)(value.name) + try: + value.name = CONVERT_OPTION.get(value.type, {}).get('func', str)(value.name) + except Exception as err: + msg = _(f'the variable "{variable.name}" has an incorrect value "{value.name}" with "{variable.type}" type') + raise DictConsistencyError(msg, 88, variable.xmlfiles) value_to_del.sort(reverse=True) for idx in value_to_del: del variable.value[idx] diff --git a/src/rougail/data/rougail.yml b/src/rougail/data/rougail.yml index 3011525dc..e97c1ed91 100644 --- a/src/rougail/data/rougail.yml +++ b/src/rougail/data/rougail.yml @@ -20,6 +20,7 @@ mapping: mapping: text: required: false + type: str iplist: type: str netmask: @@ -40,16 +41,14 @@ mapping: mapping: text: required: false + type: str file_type: type: str enum: - "filename" - "variable" disabled: - type: str - enum: - - "True" - - "False" + type: bool included: type: str enum: @@ -64,10 +63,7 @@ mapping: - "jinja2" - "creole_legacy" redefine: - type: str - enum: - - "True" - - "False" + type: bool filelist: type: str group_type: @@ -111,10 +107,7 @@ mapping: name: type: str undisable: - type: str - enum: - - "True" - - "False" + type: bool type: type: str enum: @@ -132,17 +125,11 @@ mapping: - "creole" - "jinja2" disabled: - type: str - enum: - - "True" - - "False" + type: bool servicelist: type: str manage: - type: str - enum: - - "True" - - "False" + type: bool variables: required: false type: seq @@ -168,6 +155,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -183,15 +171,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str type: @@ -214,6 +196,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -231,73 +214,33 @@ mapping: provider: type: str remove_fill: - type: str - enum: - - "True" - - "False" + type: bool remove_condition: - type: str - enum: - - "True" - - "False" + type: bool remove_check: - type: str - enum: - - "True" - - "False" + type: bool remove_choice: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str auto_save: - type: str - enum: - - "True" - - "False" + type: bool auto_freeze: - type: str - enum: - - "True" - - "False" + type: bool mandatory: - type: str - enum: - - "True" - - "False" + type: bool exists: - type: str - enum: - - "True" - - "False" + type: bool redefine: - type: str - enum: - - "True" - - "False" + type: bool unique: - type: str - enum: - - "nil" - - "True" - - "False" + type: bool multi: - type: str - enum: - - "True" - - "False" + type: bool disabled: - type: str - enum: - - "True" - - "False" + type: bool hidden: - type: str - enum: - - "True" - - "False" + type: bool help: type: str description: @@ -352,6 +295,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -367,15 +311,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str type: @@ -398,6 +336,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -415,73 +354,33 @@ mapping: provider: type: str remove_fill: - type: str - enum: - - "True" - - "False" + type: bool remove_condition: - type: str - enum: - - "True" - - "False" + type: bool remove_check: - type: str - enum: - - "True" - - "False" + type: bool remove_choice: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str auto_save: - type: str - enum: - - "True" - - "False" + type: bool auto_freeze: - type: str - enum: - - "True" - - "False" + type: bool mandatory: - type: str - enum: - - "True" - - "False" + type: bool exists: - type: str - enum: - - "True" - - "False" + type: bool redefine: - type: str - enum: - - "True" - - "False" + type: bool unique: - type: str - enum: - - "nil" - - "True" - - "False" + type: bool multi: - type: str - enum: - - "True" - - "False" + type: bool disabled: - type: str - enum: - - "True" - - "False" + type: bool hidden: - type: str - enum: - - "True" - - "False" + type: bool help: type: str description: @@ -537,6 +436,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -552,15 +452,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str type: @@ -583,6 +477,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -600,73 +495,33 @@ mapping: provider: type: str remove_fill: - type: str - enum: - - "True" - - "False" + type: bool remove_condition: - type: str - enum: - - "True" - - "False" + type: bool remove_check: - type: str - enum: - - "True" - - "False" + type: bool remove_choice: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str auto_save: - type: str - enum: - - "True" - - "False" + type: bool auto_freeze: - type: str - enum: - - "True" - - "False" + type: bool mandatory: - type: str - enum: - - "True" - - "False" + type: bool exists: - type: str - enum: - - "True" - - "False" + type: bool redefine: - type: str - enum: - - "True" - - "False" + type: bool unique: - type: str - enum: - - "nil" - - "True" - - "False" + type: bool multi: - type: str - enum: - - "True" - - "False" + type: bool disabled: - type: str - enum: - - "True" - - "False" + type: bool hidden: - type: str - enum: - - "True" - - "False" + type: bool help: type: str description: @@ -722,6 +577,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -737,15 +593,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str type: @@ -768,6 +618,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -785,73 +636,33 @@ mapping: provider: type: str remove_fill: - type: str - enum: - - "True" - - "False" + type: bool remove_condition: - type: str - enum: - - "True" - - "False" + type: bool remove_check: - type: str - enum: - - "True" - - "False" + type: bool remove_choice: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str auto_save: - type: str - enum: - - "True" - - "False" + type: bool auto_freeze: - type: str - enum: - - "True" - - "False" + type: bool mandatory: - type: str - enum: - - "True" - - "False" + type: bool exists: - type: str - enum: - - "True" - - "False" + type: bool redefine: - type: str - enum: - - "True" - - "False" + type: bool unique: - type: str - enum: - - "nil" - - "True" - - "False" + type: bool multi: - type: str - enum: - - "True" - - "False" + type: bool disabled: - type: str - enum: - - "True" - - "False" + type: bool hidden: - type: str - enum: - - "True" - - "False" + type: bool help: type: str description: @@ -907,6 +718,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -922,15 +734,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str type: @@ -953,6 +759,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -970,73 +777,33 @@ mapping: provider: type: str remove_fill: - type: str - enum: - - "True" - - "False" + type: bool remove_condition: - type: str - enum: - - "True" - - "False" + type: bool remove_check: - type: str - enum: - - "True" - - "False" + type: bool remove_choice: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str auto_save: - type: str - enum: - - "True" - - "False" + type: bool auto_freeze: - type: str - enum: - - "True" - - "False" + type: bool mandatory: - type: str - enum: - - "True" - - "False" + type: bool exists: - type: str - enum: - - "True" - - "False" + type: bool redefine: - type: str - enum: - - "True" - - "False" + type: bool unique: - type: str - enum: - - "nil" - - "True" - - "False" + type: bool multi: - type: str - enum: - - "True" - - "False" + type: bool disabled: - type: str - enum: - - "True" - - "False" + type: bool hidden: - type: str - enum: - - "True" - - "False" + type: bool help: type: str description: @@ -1073,17 +840,11 @@ mapping: name: type: str leadership: - type: str - enum: - - "True" - - "False" + type: bool dynamic: type: str hidden: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str help: @@ -1093,17 +854,11 @@ mapping: name: type: str leadership: - type: str - enum: - - "True" - - "False" + type: bool dynamic: type: str hidden: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str help: @@ -1113,17 +868,11 @@ mapping: name: type: str leadership: - type: str - enum: - - "True" - - "False" + type: bool dynamic: type: str hidden: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str help: @@ -1133,17 +882,11 @@ mapping: name: type: str leadership: - type: str - enum: - - "True" - - "False" + type: bool dynamic: type: str hidden: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str help: @@ -1174,6 +917,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -1189,15 +933,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str type: @@ -1220,6 +958,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -1237,73 +976,33 @@ mapping: provider: type: str remove_fill: - type: str - enum: - - "True" - - "False" + type: bool remove_condition: - type: str - enum: - - "True" - - "False" + type: bool remove_check: - type: str - enum: - - "True" - - "False" + type: bool remove_choice: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str auto_save: - type: str - enum: - - "True" - - "False" + type: bool auto_freeze: - type: str - enum: - - "True" - - "False" + type: bool mandatory: - type: str - enum: - - "True" - - "False" + type: bool exists: - type: str - enum: - - "True" - - "False" + type: bool redefine: - type: str - enum: - - "True" - - "False" + type: bool unique: - type: str - enum: - - "nil" - - "True" - - "False" + type: bool multi: - type: str - enum: - - "True" - - "False" + type: bool disabled: - type: str - enum: - - "True" - - "False" + type: bool hidden: - type: str - enum: - - "True" - - "False" + type: bool help: type: str description: @@ -1358,6 +1057,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -1373,15 +1073,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str type: @@ -1404,6 +1098,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -1421,73 +1116,33 @@ mapping: provider: type: str remove_fill: - type: str - enum: - - "True" - - "False" + type: bool remove_condition: - type: str - enum: - - "True" - - "False" + type: bool remove_check: - type: str - enum: - - "True" - - "False" + type: bool remove_choice: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str auto_save: - type: str - enum: - - "True" - - "False" + type: bool auto_freeze: - type: str - enum: - - "True" - - "False" + type: bool mandatory: - type: str - enum: - - "True" - - "False" + type: bool exists: - type: str - enum: - - "True" - - "False" + type: bool redefine: - type: str - enum: - - "True" - - "False" + type: bool unique: - type: str - enum: - - "nil" - - "True" - - "False" + type: bool multi: - type: str - enum: - - "True" - - "False" + type: bool disabled: - type: str - enum: - - "True" - - "False" + type: bool hidden: - type: str - enum: - - "True" - - "False" + type: bool help: type: str description: @@ -1524,17 +1179,11 @@ mapping: name: type: str leadership: - type: str - enum: - - "True" - - "False" + type: bool dynamic: type: str hidden: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str help: @@ -1565,6 +1214,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -1580,15 +1230,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str type: @@ -1611,6 +1255,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -1628,73 +1273,33 @@ mapping: provider: type: str remove_fill: - type: str - enum: - - "True" - - "False" + type: bool remove_condition: - type: str - enum: - - "True" - - "False" + type: bool remove_check: - type: str - enum: - - "True" - - "False" + type: bool remove_choice: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str auto_save: - type: str - enum: - - "True" - - "False" + type: bool auto_freeze: - type: str - enum: - - "True" - - "False" + type: bool mandatory: - type: str - enum: - - "True" - - "False" + type: bool exists: - type: str - enum: - - "True" - - "False" + type: bool redefine: - type: str - enum: - - "True" - - "False" + type: bool unique: - type: str - enum: - - "nil" - - "True" - - "False" + type: bool multi: - type: str - enum: - - "True" - - "False" + type: bool disabled: - type: str - enum: - - "True" - - "False" + type: bool hidden: - type: str - enum: - - "True" - - "False" + type: bool help: type: str description: @@ -1749,6 +1354,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -1764,15 +1370,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str type: @@ -1795,6 +1395,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -1812,73 +1413,33 @@ mapping: provider: type: str remove_fill: - type: str - enum: - - "True" - - "False" + type: bool remove_condition: - type: str - enum: - - "True" - - "False" + type: bool remove_check: - type: str - enum: - - "True" - - "False" + type: bool remove_choice: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str auto_save: - type: str - enum: - - "True" - - "False" + type: bool auto_freeze: - type: str - enum: - - "True" - - "False" + type: bool mandatory: - type: str - enum: - - "True" - - "False" + type: bool exists: - type: str - enum: - - "True" - - "False" + type: bool redefine: - type: str - enum: - - "True" - - "False" + type: bool unique: - type: str - enum: - - "nil" - - "True" - - "False" + type: bool multi: - type: str - enum: - - "True" - - "False" + type: bool disabled: - type: str - enum: - - "True" - - "False" + type: bool hidden: - type: str - enum: - - "True" - - "False" + type: bool help: type: str description: @@ -1915,17 +1476,11 @@ mapping: name: type: str leadership: - type: str - enum: - - "True" - - "False" + type: bool dynamic: type: str hidden: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str help: @@ -1956,6 +1511,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -1971,15 +1527,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str type: @@ -2002,6 +1552,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -2019,73 +1570,33 @@ mapping: provider: type: str remove_fill: - type: str - enum: - - "True" - - "False" + type: bool remove_condition: - type: str - enum: - - "True" - - "False" + type: bool remove_check: - type: str - enum: - - "True" - - "False" + type: bool remove_choice: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str auto_save: - type: str - enum: - - "True" - - "False" + type: bool auto_freeze: - type: str - enum: - - "True" - - "False" + type: bool mandatory: - type: str - enum: - - "True" - - "False" + type: bool exists: - type: str - enum: - - "True" - - "False" + type: bool redefine: - type: str - enum: - - "True" - - "False" + type: bool unique: - type: str - enum: - - "nil" - - "True" - - "False" + type: bool multi: - type: str - enum: - - "True" - - "False" + type: bool disabled: - type: str - enum: - - "True" - - "False" + type: bool hidden: - type: str - enum: - - "True" - - "False" + type: bool help: type: str description: @@ -2140,6 +1651,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -2155,15 +1667,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str type: @@ -2186,6 +1692,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -2203,73 +1710,33 @@ mapping: provider: type: str remove_fill: - type: str - enum: - - "True" - - "False" + type: bool remove_condition: - type: str - enum: - - "True" - - "False" + type: bool remove_check: - type: str - enum: - - "True" - - "False" + type: bool remove_choice: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str auto_save: - type: str - enum: - - "True" - - "False" + type: bool auto_freeze: - type: str - enum: - - "True" - - "False" + type: bool mandatory: - type: str - enum: - - "True" - - "False" + type: bool exists: - type: str - enum: - - "True" - - "False" + type: bool redefine: - type: str - enum: - - "True" - - "False" + type: bool unique: - type: str - enum: - - "nil" - - "True" - - "False" + type: bool multi: - type: str - enum: - - "True" - - "False" + type: bool disabled: - type: str - enum: - - "True" - - "False" + type: bool hidden: - type: str - enum: - - "True" - - "False" + type: bool help: type: str description: @@ -2306,17 +1773,11 @@ mapping: name: type: str leadership: - type: str - enum: - - "True" - - "False" + type: bool dynamic: type: str hidden: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str help: @@ -2347,6 +1808,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -2362,15 +1824,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str type: @@ -2393,6 +1849,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -2410,73 +1867,33 @@ mapping: provider: type: str remove_fill: - type: str - enum: - - "True" - - "False" + type: bool remove_condition: - type: str - enum: - - "True" - - "False" + type: bool remove_check: - type: str - enum: - - "True" - - "False" + type: bool remove_choice: - type: str - enum: - - "True" - - "False" + type: bool mode: type: str auto_save: - type: str - enum: - - "True" - - "False" + type: bool auto_freeze: - type: str - enum: - - "True" - - "False" + type: bool mandatory: - type: str - enum: - - "True" - - "False" + type: bool exists: - type: str - enum: - - "True" - - "False" + type: bool redefine: - type: str - enum: - - "True" - - "False" + type: bool unique: - type: str - enum: - - "nil" - - "True" - - "False" + type: bool multi: - type: str - enum: - - "True" - - "False" + type: bool disabled: - type: str - enum: - - "True" - - "False" + type: bool hidden: - type: str - enum: - - "True" - - "False" + type: bool help: type: str description: @@ -2528,6 +1945,7 @@ mapping: mapping: text: required: false + type: str type: type: str enum: @@ -2537,10 +1955,7 @@ mapping: - "filelist" - "iplist" optional: - type: str - enum: - - "True" - - "False" + type: bool param: required: false type: seq @@ -2549,6 +1964,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -2564,15 +1980,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str name: @@ -2591,6 +2001,7 @@ mapping: mapping: text: required: false + type: str type: type: str enum: @@ -2600,10 +2011,7 @@ mapping: - "filelist" - "iplist" optional: - type: str - enum: - - "True" - - "False" + type: bool param: required: false type: seq @@ -2612,6 +2020,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -2627,15 +2036,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str name: @@ -2659,6 +2062,7 @@ mapping: mapping: text: required: false + type: str type: type: str enum: @@ -2668,10 +2072,7 @@ mapping: - "filelist" - "iplist" optional: - type: str - enum: - - "True" - - "False" + type: bool param: required: false type: seq @@ -2680,6 +2081,7 @@ mapping: mapping: text: required: false + type: any type: type: str enum: @@ -2695,15 +2097,9 @@ mapping: - "suffix" - "index" optional: - type: str - enum: - - "True" - - "False" + type: bool propertyerror: - type: str - enum: - - "True" - - "False" + type: bool name: type: str name: @@ -2716,15 +2112,9 @@ mapping: - "mandatory_if_in" - "mandatory_if_not_in" apply_on_fallback: - type: str - enum: - - "True" - - "False" + type: bool optional: - type: str - enum: - - "True" - - "False" + type: bool source: type: str version: diff --git a/src/rougail/objspace.py b/src/rougail/objspace.py index c21d74c00..0e857f9a8 100644 --- a/src/rougail/objspace.py +++ b/src/rougail/objspace.py @@ -62,7 +62,7 @@ class RootRougailObject: # pylint: disable=R0903 if not isinstance(xmlfiles, list): xmlfiles = [xmlfiles] self.xmlfiles = xmlfiles - if name: + if name is not None: self.name = name @@ -94,7 +94,9 @@ def convert_boolean(value: str) -> bool: return value if value == 'True': return True - return False + elif value == 'False': + return False + raise Exception(f'unknown boolean value {value}') class RougailObjSpace: @@ -319,8 +321,11 @@ class RougailObjSpace: return child.attrib['name'] + '.' + child.attrib.get('type', 'service') if 'name' in child.attrib: return child.attrib['name'] - if child.text and child.tag in self.forced_text_elts_as_name: - return child.text.strip() + if child.text is not None and child.tag in self.forced_text_elts_as_name: + text = child.text + if isinstance(text, str): + text = text.strip() + return text return None def create_or_update_redefinable_object(self, @@ -411,8 +416,10 @@ class RougailObjSpace: """ if child.text is None or child.tag in self.forced_text_elts_as_name: return - text = child.text.strip() - if text: + text = child.text + if isinstance(text, str): + text = text.strip() + if text != '': variableobj.text = text def set_attributes(self, diff --git a/src/rougail/reflector.py b/src/rougail/reflector.py index 97d1af0aa..7b85358a2 100644 --- a/src/rougail/reflector.py +++ b/src/rougail/reflector.py @@ -1,4 +1,4 @@ -"""load XML file from directory +"""load XML and YAML file from directory Created by: EOLE (http://eole.orion.education.fr) @@ -32,6 +32,7 @@ from os.path import join, isfile from os import listdir from lxml.etree import DTD, parse, XMLSyntaxError # pylint: disable=E0611 +from pykwalify.compat import yml from pykwalify.core import Core from pykwalify.errors import SchemaError @@ -41,6 +42,7 @@ from .error import DictConsistencyError FORCE_SUBYAML = ['override'] +SCHEMA_DATA = {} class Reflector: @@ -65,6 +67,7 @@ class Reflector: if not isfile(yamlschema_filename): raise IOError(_(f"no such YAML Schema file: {yamlschema_filename}")) self.yamlschema_filename = yamlschema_filename + self.schema_data = None def load_dictionaries_from_folders(self, folders: List[str], @@ -114,8 +117,14 @@ class Reflector: def load_yml_file(self, filename: str, ): + global SCHEMA_DATA + if self.yamlschema_filename not in SCHEMA_DATA: + with open(self.yamlschema_filename, 'r') as fh: + SCHEMA_DATA[self.yamlschema_filename] = yml.load(fh) try: - document = Core(source_file=filename, schema_files=[self.yamlschema_filename]) + document = Core(source_file=filename, + schema_data=SCHEMA_DATA[self.yamlschema_filename], + ) except XMLSyntaxError as err: raise DictConsistencyError(_(f'not a XML file: {err}'), 52, [filename]) from err try: diff --git a/tests/dictionaries/00load_autofreeze/yml/00-base.yml b/tests/dictionaries/00load_autofreeze/yml/00-base.yml index 7fe5ac004..46e2f524c 100644 --- a/tests/dictionaries/00load_autofreeze/yml/00-base.yml +++ b/tests/dictionaries/00load_autofreeze/yml/00-base.yml @@ -2,11 +2,11 @@ version: '0.10' variables: - variable: name: myvar - auto_freeze: 'True' + auto_freeze: true value: - text: 'no' - variable: name: server_deployed type: boolean value: - - text: 'False' + - text: false diff --git a/tests/dictionaries/00load_autofreezeexpert/yml/00-base.yml b/tests/dictionaries/00load_autofreezeexpert/yml/00-base.yml index 71e503b69..1e1a4b0db 100644 --- a/tests/dictionaries/00load_autofreezeexpert/yml/00-base.yml +++ b/tests/dictionaries/00load_autofreezeexpert/yml/00-base.yml @@ -2,7 +2,7 @@ version: '0.10' variables: - variable: name: my_var - auto_freeze: 'True' + auto_freeze: true mode: expert value: - text: 'no' @@ -10,4 +10,4 @@ variables: name: server_deployed type: boolean value: - - text: 'False' + - text: false diff --git a/tests/dictionaries/00load_autosave/yml/00-base.yml b/tests/dictionaries/00load_autosave/yml/00-base.yml index 6f1b7e59c..6f0501647 100644 --- a/tests/dictionaries/00load_autosave/yml/00-base.yml +++ b/tests/dictionaries/00load_autosave/yml/00-base.yml @@ -11,6 +11,6 @@ variables: name: mode_conteneur_actif type: string description: No change - auto_save: 'True' + auto_save: true value: - text: non diff --git a/tests/dictionaries/00load_autosaveexpert/yml/00-base.yml b/tests/dictionaries/00load_autosaveexpert/yml/00-base.yml index e0f1dfb9a..b6ee766ad 100644 --- a/tests/dictionaries/00load_autosaveexpert/yml/00-base.yml +++ b/tests/dictionaries/00load_autosaveexpert/yml/00-base.yml @@ -11,7 +11,7 @@ variables: name: mode_conteneur_actif type: string description: No change - auto_save: 'True' + auto_save: true mode: expert value: - text: non diff --git a/tests/dictionaries/00load_comment/yml/00-base.yml b/tests/dictionaries/00load_comment/yml/00-base.yml index b0ee492a2..9b4819ab1 100644 --- a/tests/dictionaries/00load_comment/yml/00-base.yml +++ b/tests/dictionaries/00load_comment/yml/00-base.yml @@ -8,6 +8,6 @@ variables: name: mode_conteneur_actif type: string description: No change - hidden: 'True' + hidden: true value: - text: non diff --git a/tests/dictionaries/00load_notype/yml/00-base.yml b/tests/dictionaries/00load_notype/yml/00-base.yml index cc328a176..5b826e614 100644 --- a/tests/dictionaries/00load_notype/yml/00-base.yml +++ b/tests/dictionaries/00load_notype/yml/00-base.yml @@ -8,7 +8,7 @@ variables: name: mode_conteneur_actif type: string description: No change - hidden: 'True' + hidden: true value: - text: non - variable: diff --git a/tests/dictionaries/00load_save/yml/00-base.yml b/tests/dictionaries/00load_save/yml/00-base.yml index b0ee492a2..9b4819ab1 100644 --- a/tests/dictionaries/00load_save/yml/00-base.yml +++ b/tests/dictionaries/00load_save/yml/00-base.yml @@ -8,6 +8,6 @@ variables: name: mode_conteneur_actif type: string description: No change - hidden: 'True' + hidden: true value: - text: non diff --git a/tests/dictionaries/00load_subfolder/yml/99-base.yml b/tests/dictionaries/00load_subfolder/yml/99-base.yml index b0ee492a2..9b4819ab1 100644 --- a/tests/dictionaries/00load_subfolder/yml/99-base.yml +++ b/tests/dictionaries/00load_subfolder/yml/99-base.yml @@ -8,6 +8,6 @@ variables: name: mode_conteneur_actif type: string description: No change - hidden: 'True' + hidden: true value: - text: non diff --git a/tests/dictionaries/00load_subfolder/yml/subfolder/00-base.yml b/tests/dictionaries/00load_subfolder/yml/subfolder/00-base.yml index 75c3d0581..fe8199b1f 100644 --- a/tests/dictionaries/00load_subfolder/yml/subfolder/00-base.yml +++ b/tests/dictionaries/00load_subfolder/yml/subfolder/00-base.yml @@ -8,6 +8,6 @@ variables: name: mode_conteneur_actif1 type: string description: No change - hidden: 'True' + hidden: true value: - text: non diff --git a/tests/dictionaries/01auto_autofreeze/xml/00-base.xml b/tests/dictionaries/01auto_autofreeze/xml/00-base.xml index fcfc4feb4..64580adeb 100644 --- a/tests/dictionaries/01auto_autofreeze/xml/00-base.xml +++ b/tests/dictionaries/01auto_autofreeze/xml/00-base.xml @@ -2,7 +2,7 @@ - no + False