diff options
author | Antonio Cuñat Alario <toni@cunyat.net> | 2019-12-10 18:39:30 +0100 |
---|---|---|
committer | Antonio Cuñat Alario <toni@cunyat.net> | 2019-12-10 18:39:30 +0100 |
commit | 22184e3d47b1de68c6ff7beaa78986e5ba7d20a8 (patch) | |
tree | 46ea4fdeb9de90d7212bb80e51cfaf54087ba608 | |
parent | 4f09f8a0d32f76b60e548800b31a2bb58c10a95b (diff) | |
download | vyos-1x-22184e3d47b1de68c6ff7beaa78986e5ba7d20a8.tar.gz vyos-1x-22184e3d47b1de68c6ff7beaa78986e5ba7d20a8.zip |
scripts: import: T1836: add regex filter for condition import
Add import multiple values to a regex xml expression
-rwxr-xr-x | scripts/import-conf-mode-commands | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/scripts/import-conf-mode-commands b/scripts/import-conf-mode-commands index 3980b0cf4..996b31c9c 100755 --- a/scripts/import-conf-mode-commands +++ b/scripts/import-conf-mode-commands @@ -34,9 +34,10 @@ TAG_NODE = 2 def parse_command_data(t): regs = { - 'help': r'\bhelp:(.*)(?:\n|$)', - 'priority': r'\bpriority:(.*)(?:\n|$)', - 'type': r'\btype:(.*)(?:\n|$)' + 'help': r'\bhelp:(.*)(?:\n|$)', + 'priority': r'\bpriority:(.*)(?:\n|$)', + 'type': r'\btype:(.*)(?:\n|$)', + 'syntax_expression_var': r'\bsyntax:expression: \$VAR\(\@\) in (.*)' } data = {'multi': False, 'help': ""} @@ -129,6 +130,20 @@ def walk(tree, base_path, name): constraint_elem = etree.Element('constraint') has_constraint = False + # Add regexp field for multiple options + if data['syntax_expression_var']: + regex = etree.Element('regex') + constraint_error=etree.Element('constraintErrorMessage') + values = re.search(r'(.+) ; (.+)', data['syntax_expression_var']).group(1) + message = re.search(r'(.+) ; (.+)', data['syntax_expression_var']).group(2) + values = re.findall(r'\"(.+?)\"', values) + regex.text = '|'.join(values) + constraint_error.text = re.sub('\".*?VAR.*?\"', '', message) + constraint_error.text = re.sub(r'[\"|\\]', '', message) + constraint_elem.append(regex) + props_elem.append(constraint_elem) + props_elem.append(constraint_error) + if data['val_help']: for vh in data['val_help']: vh_elem = etree.Element('valueHelp') |