diff options
author | Daniil Baturin <daniil@baturin.org> | 2017-09-16 20:02:52 +0200 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2017-09-16 20:02:52 +0200 |
commit | 046123c4f7e0ada2aa6b66558735f6cd704b3663 (patch) | |
tree | 961323a24e77f0ded12e119625af270d8fac7313 /scripts | |
parent | 076c0bc9cc45606ef75e75cacf046cde652f005c (diff) | |
download | vyos-1x-046123c4f7e0ada2aa6b66558735f6cd704b3663.tar.gz vyos-1x-046123c4f7e0ada2aa6b66558735f6cd704b3663.zip |
T396: add support for value constraint tags to the build-command-templates script
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/build-command-templates | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/scripts/build-command-templates b/scripts/build-command-templates index 6cfaa2bc1..09c7dc8c4 100755 --- a/scripts/build-command-templates +++ b/scripts/build-command-templates @@ -28,6 +28,11 @@ import functools from lxml import etree as ET +# Defaults + +validator_dir = "/opt/vyatta/libexec/validators" +default_constraint_err_msg = "Invalid value" + ## Get arguments @@ -100,6 +105,37 @@ def get_properties(p): except: props["val_help"] = [] + # Get the constraint statements + try: + error_msg = default_constraint_err_msg + # Get the error message if it's there + try: + error_msg = p.find("constraintErrorMessage").text + except: + pass + + vce = p.findall("constraint") + vc = [] + for v in vce: + if v.find("regex") is not None: + vc.append("pattern $VAR(@) \"{0}\"; {1}".format(v.find("regex").text, error_msg)) + else: + validator = v.find("validator") + v_name = validator.get("name") + + # XXX: lxml returns None for empty arguments + v_argument = None + try: + v_argument = validator.get("argument") + except: + pass + if v_argument is None: + v_argument = "" + vc.append("exec {0}/{1} {2} $VAR(@); {3}".format(validator_dir, v_name, v_argument, error_msg)) + props["constraints"] = vc + except: + props["constraints"] = [] + # Get the completion help strings try: che = p.findall("completionHelp") @@ -163,6 +199,10 @@ def make_node_def(props): if "comp_help" in props: node_def += "allowed: {0}\n".format(props["comp_help"]) + if "constraints" in props: + for c in props["constraints"]: + node_def += "syntax:expression: {0}\n".format(c) + if "owner" in props: node_def += "end: sudo sh -c \"{0}\"\n".format(props["owner"]) |