|
1 | 1 | from flask import Blueprint, jsonify, request |
| 2 | + |
2 | 3 | from utils import exceptions |
3 | 4 | from utils.plane import PlaneEnum |
4 | 5 | from command.controller.specs_manager import AAZSpecsManager |
|
7 | 8 | bp = Blueprint('specs', __name__, url_prefix='/AAZ/Specs') |
8 | 9 |
|
9 | 10 |
|
| 11 | +# modules |
| 12 | +@bp.route("/CommandTree/Simple", methods=("GET",)) |
| 13 | +def simple_command_tree(): |
| 14 | + manager = AAZSpecsManager() |
| 15 | + tree = manager.simple_tree |
| 16 | + if not tree: |
| 17 | + raise exceptions.ResourceNotFind("Command group not exist") |
| 18 | + tree = tree.to_primitive() |
| 19 | + return jsonify(tree) |
| 20 | + |
| 21 | + |
10 | 22 | # modules |
11 | 23 | @bp.route("/CommandTree/Nodes/<names_path:node_names>", methods=("GET",)) |
12 | 24 | def command_tree_node(node_names): |
@@ -38,6 +50,23 @@ def command_tree_leaf(node_names, leaf_name): |
38 | 50 | return jsonify(result) |
39 | 51 |
|
40 | 52 |
|
| 53 | +@bp.route("/CommandTree/Nodes/Leaves", methods=("POST",)) |
| 54 | +def command_tree_leaves(): |
| 55 | + data = request.get_json() |
| 56 | + result = [] |
| 57 | + manager = AAZSpecsManager() |
| 58 | + |
| 59 | + for command_names in data: |
| 60 | + if command_names[0] != AAZSpecsManager.COMMAND_TREE_ROOT_NAME: |
| 61 | + raise exceptions.ResourceNotFind(f"Command not exist: {' '.join(command_names)}") |
| 62 | + command_names = command_names[1:] |
| 63 | + leaf = manager.find_command(*command_names) |
| 64 | + if not leaf: |
| 65 | + raise exceptions.ResourceNotFind(f"Command not exist: {' '.join(command_names)}") |
| 66 | + result.append(leaf.to_primitive()) |
| 67 | + return jsonify(result) |
| 68 | + |
| 69 | + |
41 | 70 | @bp.route("/CommandTree/Nodes/<names_path:node_names>/Leaves/<name:leaf_name>/Versions/<base64:version_name>", methods=("GET",)) |
42 | 71 | def aaz_command_in_version(node_names, leaf_name, version_name): |
43 | 72 | if node_names[0] != AAZSpecsManager.COMMAND_TREE_ROOT_NAME: |
|
0 commit comments