Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stechuhr-client
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
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pandemic_Response
stechuhr-client
Commits
1c1d2dae
Commit
1c1d2dae
authored
4 years ago
by
David Huss
Browse files
Options
Downloads
Patches
Plain Diff
Implement dynamic id_pattern changes from server
parent
dad102ce
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
stechuhr_client/client.py
+35
-5
35 additions, 5 deletions
stechuhr_client/client.py
stechuhr_client/config.py
+3
-1
3 additions, 1 deletion
stechuhr_client/config.py
with
38 additions
and
6 deletions
stechuhr_client/client.py
+
35
−
5
View file @
1c1d2dae
...
@@ -41,6 +41,15 @@ EVENT_FORMAT = "llHHI"
...
@@ -41,6 +41,15 @@ EVENT_FORMAT = "llHHI"
EVENT_SIZE
=
struct
.
calcsize
(
EVENT_FORMAT
)
EVENT_SIZE
=
struct
.
calcsize
(
EVENT_FORMAT
)
def
string_to_list
(
s
:
str
,
delimiter
:
str
=
"
\n
"
)
->
List
[
str
]:
"""
Split a string to a list derived from a delimiter. If the string contains
no delimiter, still return a list containing the string
"""
if
delimiter
in
s
:
return
s
.
split
(
delimiter
)
else
:
return
[
s
]
def
repeat
(
l
,
index
):
def
repeat
(
l
,
index
):
...
@@ -320,16 +329,36 @@ def read_key_input(input_queue, config, logger):
...
@@ -320,16 +329,36 @@ def read_key_input(input_queue, config, logger):
time
.
sleep
(
0.01
)
time
.
sleep
(
0.01
)
def
update_id_patterns
(
config
)
->
'
Config
'
:
def
update_id_patterns
(
config
,
logger
)
->
'
Config
'
:
"""
Update the id_patterns from the server via http
"""
if
config
[
"
server
"
][
"
port
"
]
==
80
:
if
config
[
"
server
"
][
"
port
"
]
==
80
:
protocol
=
"
http
"
protocol
=
"
http
"
else
:
else
:
protocol
=
"
https
"
protocol
=
"
https
"
url
=
'
{}://{}/config/database/id_patterns
'
.
format
(
protocol
,
config
[
"
server
"
][
"
address
"
].
rstrip
(
"
/
"
))
url
=
'
{}://{}/config/database/id_patterns
'
.
format
(
protocol
,
config
[
"
server
"
][
"
address
"
].
rstrip
(
"
/
"
))
r
=
requests
.
get
(
url
)
logger
.
debug
(
"
Requesting id_pattern update at address: {}
"
.
format
(
url
))
print
(
r
.
text
)
# config["client"]["id_patterns"]
# Send request
r
=
requests
.
get
(
url
,
timeout
=
config
[
"
server
"
][
"
timeout
"
])
# If the response was ok update the pattern if it changed, else display a warning
if
r
.
ok
:
patterns
=
string_to_list
(
r
.
text
)
if
set
(
patterns
)
==
set
(
config
[
"
client
"
][
"
id_patterns
"
]):
logger
.
debug
(
"
No change in serverside id_pattern, so didn
'
t update
"
)
else
:
# Only compile the patterns once we know something changed
patterns
=
[
re
.
compile
(
p
)
for
p
in
patterns
]
config
[
"
client
"
][
"
id_patterns
"
]
=
patterns
logger
.
info
(
"
Received a newly updated patterns list from the server
"
)
else
:
logger
.
warn
(
"
Server at
\"
{}
\"
responded with {}
"
.
format
(
url
,
r
.
status
))
return
config
def
main
():
def
main
():
logger
=
logging
.
getLogger
(
APPLICATION_NAME
)
logger
=
logging
.
getLogger
(
APPLICATION_NAME
)
...
@@ -374,9 +403,10 @@ def main():
...
@@ -374,9 +403,10 @@ def main():
else
:
else
:
time
.
sleep
(
0.01
)
time
.
sleep
(
0.01
)
# Update the patterns at the pace defined by config["server"]["update_frequency"]
if
last_pattern_update
is
None
or
time
.
time
()
-
last_pattern_update
>
config
[
"
server
"
][
"
update_frequency
"
]:
if
last_pattern_update
is
None
or
time
.
time
()
-
last_pattern_update
>
config
[
"
server
"
][
"
update_frequency
"
]:
last_pattern_update
=
time
.
time
()
last_pattern_update
=
time
.
time
()
update_id_patterns
(
config
)
config
=
update_id_patterns
(
config
,
logger
)
time
.
sleep
(
0.01
)
time
.
sleep
(
0.01
)
...
...
This diff is collapsed.
Click to expand it.
stechuhr_client/config.py
+
3
−
1
View file @
1c1d2dae
...
@@ -26,7 +26,9 @@ address = "127.0.0.1"
...
@@ -26,7 +26,9 @@ address = "127.0.0.1"
port = 80
port = 80
timeout = 5
timeout = 5
verify_cert = true
verify_cert = true
update_frequency = 10
# Frequency of requesting pattern updates from the server in seconds
update_frequency = 600
[client]
[client]
location =
"
lerchenfeld/mensa
"
location =
"
lerchenfeld/mensa
"
...
...
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