Skip to content

Commit

Permalink
natt editor update
Browse files Browse the repository at this point in the history
  • Loading branch information
0xMartin committed Aug 11, 2024
1 parent fa67aad commit 30df825
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 775 deletions.
68 changes: 65 additions & 3 deletions natt-config-editor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import webbrowser
import os
import select
import json
import re

app = Flask(__name__)
socketio = SocketIO(app)
Expand All @@ -14,6 +16,7 @@
def index():
return render_template('index.html')


@app.route('/help')
def help():
return render_template('help.html')
Expand Down Expand Up @@ -104,7 +107,8 @@ def handle_stop_java():
if process:
process.terminate() # posle signal SIGTERM
process = None
emit('stopped', {'message': 'The testing process has been terminated by editor ...'})
emit('stopped', {
'message': 'The testing process has been terminated by editor ...'})


@socketio.on('validate')
Expand All @@ -120,12 +124,12 @@ def handle_validation(json):

try:
val_process = subprocess.Popen(['java', '-jar', '../NATT.jar', '-c', '../tmp-config.yaml', '-v'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, cwd='./work-dir')
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, cwd='./work-dir')
stdout, stderr = val_process.communicate()

if val_process.returncode == 0:
emit('validate-response', {'status': 'success',
'message': 'Configuration is valid'})
'message': 'Configuration is valid'})
else:
emit('validate-response', {'status': 'error', 'message': stderr})
except Exception as e:
Expand All @@ -136,6 +140,64 @@ def handle_validation(json):
process.stderr.close()
process.terminate()

@app.route('/get-snippets', methods=['POST'])
def get_snippets():
try:
# Define the path to the NATT.jar and working directory
jar_path = '../NATT.jar'
work_dir = './work-dir'

# Execute the command to run NATT.jar and capture the output
result = subprocess.run(
['java', '-jar', jar_path, '-kd'],
cwd=work_dir,
text=True,
capture_output=True
)

# Check if the command was successful
if result.returncode != 0:
return jsonify({"error": f"Error executing command: {result.stderr}"}), 500

# Extract the keyword list from the command output
keyword_list_match = re.search(
r'Documentation for registered keywords:\s*\[(.*)\]', result.stdout, re.S)
if not keyword_list_match:
return jsonify({"error": "Failed to find the keyword list in the output."}), 500

keyword_list_string = f'[{keyword_list_match.group(1)}]'

# Parse the keyword list JSON
try:
keyword_list = json.loads(keyword_list_string)
except json.JSONDecodeError as parse_error:
return jsonify({"error": f"Error parsing JSON: {str(parse_error)}"}), 500

# Create the keyword snippets
keyword_snippets = []
for keyword in keyword_list:
snippet = {
"caption": keyword["name"],
"snippet": f'{keyword["name"]}:\n' + '\n'.join([
f' {param}: ' + {
"STRING": '"example"',
"LONG": "100",
"DOUBLE": "10.5",
"BOOLEAN": "true",
"LIST": "[]"
}.get(keyword["types"][i], "example value")
for i, param in enumerate(keyword["parameters"])
]),
"meta": f'{keyword["kwGroup"]} - {keyword["description"]}'
}
keyword_snippets.append(snippet)

# Return the generated snippets as JSON
return jsonify({"snippets": keyword_snippets})

except Exception as e:
return jsonify({"error": str(e)}), 500


def showPage():
webbrowser.open_new("http://127.0.0.1:5000")
Expand Down
67 changes: 67 additions & 0 deletions natt-config-editor/static/css/index_style.css
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,71 @@ select {
.logo {
width: 300px;
height: 300px;
}

.keyword-item {
position: relative;
margin-bottom: 1rem;
border-bottom: 1px solid #444;
padding-bottom: 0.75rem;
}

.keyword-title {
font-weight: bold;
margin-bottom: 0.5rem;
color: #e1e1e1;
font-size: 1.2rem;
}

.keyword-group {
display: inline-block;
padding: 0.25rem 0.5rem;
border-radius: 1.25rem;
background-color: #555;
font-size: 0.9rem;
margin-left: 0.5rem;
}

.keyword-description {
margin-bottom: 0.5rem;
font-size: 0.9rem;
}

.keyword-parameters {
font-size: 0.8rem;
display: flex;
flex-wrap: wrap;
width: 100%;
}

.parameter-pill {
display: inline-flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
border-radius: 1.25rem;
font-size: 0.85rem;
margin: 0.25rem;
overflow: hidden;
}

.parameter-pill-name {
flex: 1;
padding-left: 0.4rem;
padding-top: 0.3rem;
padding-bottom: 0.3rem;
padding-right: 0.5rem;
background-color: #444;
border-top-left-radius: 1.25rem;
border-bottom-left-radius: 1.25rem;
font-weight: bold;
}

.parameter-pill-type {
font-size: 0.75rem;
background-color: #252525;
border-top-right-radius: 1.25rem;
border-bottom-right-radius: 1.25rem;
padding: 0.3rem;
white-space: nowrap;
}
Loading

0 comments on commit 30df825

Please sign in to comment.