mirror of
https://github.com/thiagoralves/OpenPLC_v3.git
synced 2026-02-06 19:03:28 +08:00
[RTOP-23] File context in openplc.py and restapi minor fix
This commit is contained in:
@@ -1 +1 @@
|
||||
890590.st
|
||||
Dockerfile
|
||||
|
||||
@@ -114,9 +114,9 @@ class runtime:
|
||||
compilation_status_str = ""
|
||||
|
||||
# Extract debug information from program
|
||||
f = open('./st_files/' + st_file, "r")
|
||||
combined_lines = f.read()
|
||||
f.close()
|
||||
with open('./st_files/' + st_file, "r") as f:
|
||||
combined_lines = f.read()
|
||||
|
||||
combined_lines = combined_lines.split('\n')
|
||||
program_lines = []
|
||||
c_debug_lines = []
|
||||
@@ -132,9 +132,9 @@ class runtime:
|
||||
# Could not find debug info on program uploaded
|
||||
if os.path.isfile('./st_files/' + st_file + '.dbg'):
|
||||
# Debugger info exists on file - open it
|
||||
f = open('./st_files/' + st_file + '.dbg', "r")
|
||||
c_debug = f.read()
|
||||
f.close()
|
||||
with open('./st_files/' + st_file + '.dbg', "r") as f:
|
||||
c_debug = f.read()
|
||||
|
||||
else:
|
||||
# No debug info... probably a program generated from the old editor. Use the blank debug info just to compile the program
|
||||
f = open('./core/debug.blank', "r")
|
||||
@@ -142,9 +142,8 @@ class runtime:
|
||||
f.close()
|
||||
|
||||
# Write c_debug file
|
||||
f = open('./core/debug.cpp', "w")
|
||||
f.write(c_debug)
|
||||
f.close()
|
||||
with open('./core/debug.cpp', "w") as f:
|
||||
f.write(c_debug)
|
||||
|
||||
# Start compilation
|
||||
a = subprocess.Popen(['./scripts/compile_program.sh', str(st_file)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
@@ -155,17 +154,15 @@ class runtime:
|
||||
c_debug = '\n'.join(c_debug_lines)
|
||||
|
||||
# Write c_debug file
|
||||
f = open('./core/debug.cpp', "w")
|
||||
f.write(c_debug)
|
||||
f.close()
|
||||
with open('./core/debug.cpp', "w") as f:
|
||||
f.write(c_debug)
|
||||
|
||||
#Write program and debug files
|
||||
f = open('./st_files/' + st_file, "w")
|
||||
f.write(program)
|
||||
f.close()
|
||||
f = open('./st_files/' + st_file + '.dbg', "w")
|
||||
f.write(c_debug)
|
||||
f.close()
|
||||
with open('./st_files/' + st_file, "w") as f:
|
||||
f.write(program)
|
||||
|
||||
with open('./st_files/' + st_file + '.dbg', "w") as f:
|
||||
f.write(c_debug)
|
||||
|
||||
# Start compilation
|
||||
a = subprocess.Popen(['./scripts/compile_program.sh', str(st_file)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
|
||||
@@ -1 +1 @@
|
||||
rpi
|
||||
blank_linux
|
||||
|
||||
@@ -1 +1 @@
|
||||
rpi
|
||||
linux
|
||||
|
||||
31
webserver/st_files/Dockerfile
Normal file
31
webserver/st_files/Dockerfile
Normal file
@@ -0,0 +1,31 @@
|
||||
FROM debian:bullseye-20240722
|
||||
|
||||
COPY . /workdir
|
||||
|
||||
WORKDIR /workdir
|
||||
|
||||
RUN mkdir /docker_persistent
|
||||
|
||||
VOLUME /docker_persistent
|
||||
|
||||
# setup docker
|
||||
RUN ./install.sh docker \
|
||||
&& touch /docker_persistent/mbconfig.cfg \
|
||||
&& touch /docker_persistent/persistent.file \
|
||||
&& mkdir /docker_persistent/st_files \
|
||||
&& cp /workdir/webserver/openplc.db /docker_persistent/openplc.db \
|
||||
&& mv /workdir/webserver/openplc.db /workdir/webserver/openplc_default.db \
|
||||
&& cp /workdir/webserver/dnp3.cfg /docker_persistent/dnp3.cfg \
|
||||
&& mv /workdir/webserver/dnp3.cfg /workdir/webserver/dnp3_default.cfg \
|
||||
&& cp -r /workdir/webserver/st_files/ /docker_persistent/st_files/ \
|
||||
&& mv /workdir/webserver/st_files /workdir/webserver/st_files_default \
|
||||
&& cp /workdir/webserver/active_program /docker_persistent/active_program \
|
||||
&& mv /workdir/webserver/active_program /workdir/webserver/active_program_default \
|
||||
&& ln -s /docker_persistent/mbconfig.cfg /workdir/webserver/mbconfig.cfg \
|
||||
&& ln -s /docker_persistent/persistent.file /workdir/webserver/persistent.file \
|
||||
&& ln -s /docker_persistent/openplc.db /workdir/webserver/openplc.db \
|
||||
&& ln -s /docker_persistent/dnp3.cfg /workdir/webserver/dnp3.cfg \
|
||||
&& ln -s /docker_persistent/st_files /workdir/webserver/st_files \
|
||||
&& ln -s /docker_persistent/active_program /workdir/webserver/active_program
|
||||
|
||||
ENTRYPOINT ["./start_openplc.sh"]
|
||||
@@ -48,7 +48,7 @@ def restapi_callback_get(argument: str, data: dict) -> dict:
|
||||
|
||||
elif argument == "compilation-status":
|
||||
status = openplc_runtime.is_compiling
|
||||
return {"compilation-status": status}
|
||||
return {"is-compiling": status}
|
||||
|
||||
elif argument == "compilation-logs":
|
||||
logs = openplc_runtime.compilation_status()
|
||||
@@ -67,14 +67,14 @@ def restapi_callback_post(argument: str, data: dict) -> dict:
|
||||
# TODO logging debug level
|
||||
print(f"POST | [{__name__}] Received argument: {argument}, data: {data}")
|
||||
|
||||
if argument == "upload_file":
|
||||
if argument == "upload-file":
|
||||
try:
|
||||
# TODO validate filename, content and size
|
||||
st_file = flask.request.files['file']
|
||||
# TODO save file
|
||||
print(st_file.filename)
|
||||
st_file.save("st_files/")
|
||||
|
||||
st_file.save(f"st_files/{st_file.filename}")
|
||||
return {"UploadFile": "Success"}
|
||||
|
||||
except:
|
||||
return {"UploadFile": "Fail"}
|
||||
|
||||
@@ -82,14 +82,19 @@ def restapi_callback_post(argument: str, data: dict) -> dict:
|
||||
if (openplc_runtime.status() == "Compiling"):
|
||||
return {"RuntimeStatus": "Compiling"}
|
||||
|
||||
# st_file = flask.request.args.get('file')
|
||||
st_file = flask.request.files['file']
|
||||
openplc_runtime.compile_program(st_file)
|
||||
try:
|
||||
# TODO return compilation result and validate filename
|
||||
# st_file = flask.request.args.get('file')
|
||||
st_file = flask.request.files['file']
|
||||
# print(f"st_files/{st_file.filename}")
|
||||
openplc_runtime.compile_program(f"{st_file.filename}")
|
||||
return {"CompilationStatus": "Program Compiled"}
|
||||
|
||||
return {"RuntimeStatus": "Program Compiled"}
|
||||
except Exception as e:
|
||||
return {"CompilationStatus": e}
|
||||
|
||||
else:
|
||||
return {"error": "Unknown argument"}
|
||||
return {"PostError": "Unknown argument"}
|
||||
|
||||
|
||||
class User(flask_login.UserMixin):
|
||||
|
||||
Reference in New Issue
Block a user