Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
web-ros3rag
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
web-ros3rag
Commits
d51a74f1
Commit
d51a74f1
authored
2 years ago
by
René Schöne
Browse files
Options
Downloads
Patches
Plain Diff
use logging, and silence post messages of webserver
parent
430d30a8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+19
-8
19 additions, 8 deletions
main.py
with
19 additions
and
8 deletions
main.py
+
19
−
8
View file @
d51a74f1
...
...
@@ -7,6 +7,7 @@ import base64
import
flask
import
yaml
import
sys
import
logging
import
dash
from
dash
import
dcc
...
...
@@ -482,7 +483,7 @@ def append_to_mqtt_log(_n_intervals, clear_n_clicks, filter_options, topics_to_f
topic_match
,
topic
=
utils
.
topic_match
(
topics_to_filter
,
msg
)
if
topic
==
svg_image_topic
:
new_svg_img_src
=
'
/static/
'
+
utils
.
parse_log_msg
(
msg
)[
2
]
print
(
'
found new svg:
'
+
new_svg_img_src
)
logging
.
info
(
'
found new svg:
%s
'
,
new_svg_img_src
)
if
topic
not
in
(
option
[
'
label
'
]
for
option
in
filter_options
):
filter_options
.
append
({
'
label
'
:
topic
,
'
value
'
:
topic
})
if
topic
in
topics_enabled_once_seen
:
...
...
@@ -557,7 +558,7 @@ def update_svg_name(name):
def
serve_image
(
image_path
):
image_name
=
'
{}.svg
'
.
format
(
image_path
)
image_directory
=
config
[
'
image_directory
'
]
print
(
'
{}/{}
'
.
format
(
image_directory
,
image_name
)
)
logging
.
debug
(
'
%s/%s
'
,
image_directory
,
image_name
)
# if image_name not in list_of_images:
# raise Exception('"{}" is excluded from the allowed static files'.format(image_path))
return
flask
.
send_from_directory
(
image_directory
,
image_name
)
...
...
@@ -565,14 +566,14 @@ def serve_image(image_path):
def
on_mqtt_connect
(
_client
,
_userdata
,
_flags
,
_rc
,
_properties
=
None
):
# Callback for mqtt client when connected
print
(
f
'
\n
Connected to
{
config
[
"
mqtt_server
"
]
}
at
{
datetime
.
datetime
.
now
().
isoformat
()
}
'
)
logging
.
info
(
'
Connected to
%s at %s
'
,
config
[
"
mqtt_server
"
]
,
datetime
.
datetime
.
now
().
isoformat
())
ready_event
.
set
()
mqttc
.
subscribe
(
topic
=
'
#
'
)
threading
.
Thread
(
target
=
publish_test_message
).
start
()
def
on_mqtt_disconnect
(
_client
,
_userdata
,
_rc
):
print
(
'
Lost connection at
'
+
datetime
.
datetime
.
now
().
isoformat
())
logging
.
info
(
'
Lost connection at
%s
'
,
datetime
.
datetime
.
now
().
isoformat
())
ready_event
.
clear
()
...
...
@@ -608,17 +609,27 @@ def publish_test_message():
if
__name__
==
'
__main__
'
:
print
(
'
Starting web-ros3rag
'
)
logging
.
basicConfig
(
level
=
'
DEBUG
'
,
format
=
'
%(asctime)-15s %(levelname)-8s %(message)s
'
,
handlers
=
[
logging
.
StreamHandler
()
])
# silence logger of webserver
log_werkzeug
=
logging
.
getLogger
(
'
werkzeug
'
)
log_werkzeug
.
setLevel
(
logging
.
ERROR
)
logging
.
info
(
'
Starting web-ros3rag
'
)
try
:
with
open
(
CONFIG_FILENAME
,
'
r
'
)
as
fd
:
config
=
yaml
.
safe_load
(
fd
)
except
FileNotFoundError
as
e
:
print
(
f
'
Could not open
{
CONFIG_FILENAME
}
. Aborting.
'
)
logging
.
error
(
'
Could not open
%s. Aborting.
'
,
CONFIG_FILENAME
)
sys
.
exit
(
1
)
if
not
config
[
'
image_directory
'
]:
print
(
'
image_directory not specified. Aborting.
'
)
logging
.
error
(
'
image_directory not specified. Aborting.
'
)
sys
.
exit
(
1
)
dockerized
=
config
.
get
(
'
docker
'
)
...
...
@@ -630,7 +641,7 @@ if __name__ == '__main__':
mqttc
.
connect_async
(
config
[
'
mqtt_server
'
])
mqttc
.
loop_start
()
if
not
ready_event
.
wait
(
2.0
):
# wait 2 seconds
print
(
f
'
Could not connect to mqtt at
{
config
[
"
mqtt_server
"
]
}
in time!
'
)
logging
.
warning
(
'
Could not connect to mqtt at
%s in time!
'
,
config
[
"
mqtt_server
"
])
if
dockerized
:
app
.
run_server
(
host
=
'
0.0.0.0
'
,
port
=
8050
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment