|
2 | 2 | from app.modules.hubfile.services import HubfileService |
3 | 3 | from flask import send_file, jsonify |
4 | 4 | from app.modules.flamapy import flamapy_bp |
5 | | -from flamapy.interfaces.python.flamapy_feature_model import FLAMAFeatureModel |
6 | | -from flamapy.core.exceptions import FlamaException |
7 | 5 | import os |
8 | 6 |
|
9 | | -from antlr4 import CommonTokenStream, FileStream |
10 | | -from uvl.UVLCustomLexer import UVLCustomLexer |
11 | | -from uvl.UVLPythonParser import UVLPythonParser |
12 | | -from antlr4.error.ErrorListener import ErrorListener |
13 | | - |
14 | 7 | logger = logging.getLogger(__name__) |
15 | 8 |
|
16 | 9 |
|
17 | | -@flamapy_bp.route("/flamapy/check_uvl/<int:file_id>", methods=["GET"]) |
18 | | -def check_uvl(file_id): |
19 | | - class CustomErrorListener(ErrorListener): |
20 | | - def __init__(self): |
21 | | - self.errors = [] |
22 | | - |
23 | | - def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e): |
24 | | - if "\\t" in msg: |
25 | | - warning_message = ( |
26 | | - f"The UVL has the following warning that prevents reading it: " |
27 | | - f"Line {line}:{column} - {msg}" |
28 | | - ) |
29 | | - print(warning_message) |
30 | | - self.errors.append(warning_message) |
31 | | - else: |
32 | | - error_message = ( |
33 | | - f"The UVL has the following error that prevents reading it: " |
34 | | - f"Line {line}:{column} - {msg}" |
35 | | - ) |
36 | | - self.errors.append(error_message) |
37 | | - |
38 | | - try: |
39 | | - hubfile = HubfileService().get_by_id(file_id) |
40 | | - input_stream = FileStream(hubfile.get_path()) |
41 | | - lexer = UVLCustomLexer(input_stream) |
42 | | - |
43 | | - error_listener = CustomErrorListener() |
44 | | - |
45 | | - lexer.removeErrorListeners() |
46 | | - lexer.addErrorListener(error_listener) |
47 | | - |
48 | | - stream = CommonTokenStream(lexer) |
49 | | - parser = UVLPythonParser(stream) |
50 | | - |
51 | | - parser.removeErrorListeners() |
52 | | - parser.addErrorListener(error_listener) |
53 | | - |
54 | | - # Optional: Commented out for now |
55 | | - # tree = parser.featureModel() |
56 | | - |
57 | | - if error_listener.errors: |
58 | | - return jsonify({"errors": error_listener.errors}), 400 |
59 | | - |
60 | | - # After parsing, try transforming the model |
61 | | - try: |
62 | | - # Assuming some logic here like loading and validating the model |
63 | | - # This part should contain your logic for using the Flamapy transformation |
64 | | - FLAMAFeatureModel(hubfile.get_path()) # Example usage |
65 | | - # You can optionally print or process the model here |
66 | | - return jsonify({"message": "Valid Model"}), 200 |
67 | | - |
68 | | - except FlamaException as fe: |
69 | | - return jsonify({"error": f"Model transformation failed: {str(fe)}"}), 400 |
70 | | - |
71 | | - except Exception as e: |
72 | | - return jsonify({"error": str(e)}), 500 |
73 | | - |
74 | | - |
75 | | -@flamapy_bp.route("/flamapy/valid/<int:file_id>", methods=["GET"]) |
| 10 | +@flamapy_bp.route('/flamapy/valid/<int:file_id>', methods=['GET']) |
76 | 11 | def valid(file_id): |
77 | 12 | return jsonify({"success": True, "file_id": file_id}) |
78 | 13 |
|
@@ -104,7 +39,7 @@ def to_glencoe(file_id): |
104 | 39 | return download_transformed_file(file_id, '.json', 'glencoe') |
105 | 40 |
|
106 | 41 |
|
107 | | -@flamapy_bp.route("/flamapy/to_cnf/<int:file_id>", methods=["GET"]) |
| 42 | +@flamapy_bp.route('/flamapy/to_cnf/<int:file_id>', methods=['GET']) |
108 | 43 | def to_cnf(file_id): |
109 | 44 | return download_transformed_file(file_id, '.cnf', 'dimacs') |
110 | 45 |
|
|
0 commit comments