Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Python
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
xAAL
Code
Python
Commits
2fb5c26d
"dapps/git@gitlab.imt-atlantique.fr:iota-imt/goshimmer.git" did not exist on "0525328dc1fe3c76139ddcd3b9e910598fa28b55"
Commit
2fb5c26d
authored
5 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Formating, fix ruff errors
parent
b74d37e6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
libs/lib/xaal/lib/aioengine.py
+22
-22
22 additions, 22 deletions
libs/lib/xaal/lib/aioengine.py
libs/lib/xaal/lib/core.py
+3
-2
3 additions, 2 deletions
libs/lib/xaal/lib/core.py
libs/lib/xaal/lib/engine.py
+4
-3
4 additions, 3 deletions
libs/lib/xaal/lib/engine.py
with
29 additions
and
27 deletions
libs/lib/xaal/lib/aioengine.py
+
22
−
22
View file @
2fb5c26d
...
@@ -5,7 +5,7 @@ from . import config
...
@@ -5,7 +5,7 @@ from . import config
from
.
import
tools
from
.
import
tools
from
.messages
import
MessageParserError
from
.messages
import
MessageParserError
from
.aionetwork
import
AsyncNetworkConnector
from
.aionetwork
import
AsyncNetworkConnector
from
.exceptions
import
*
from
.exceptions
import
XAALError
,
CallbackError
import
time
import
time
from
enum
import
Enum
from
enum
import
Enum
...
@@ -23,7 +23,7 @@ class AsyncEngine(core.EngineMixin):
...
@@ -23,7 +23,7 @@ class AsyncEngine(core.EngineMixin):
__slots__
=
[
'
__txFifo
'
,
'
_loop
'
,
'
_tasks
'
,
'
_hooks
'
,
'
_watchdog_task
'
,
'
_kill_counter
'
,
'
running_event
'
,
'
watchdog_event
'
,
'
started_event
'
]
__slots__
=
[
'
__txFifo
'
,
'
_loop
'
,
'
_tasks
'
,
'
_hooks
'
,
'
_watchdog_task
'
,
'
_kill_counter
'
,
'
running_event
'
,
'
watchdog_event
'
,
'
started_event
'
]
def
__init__
(
self
,
address
=
config
.
address
,
port
=
config
.
port
,
hops
=
config
.
hops
,
key
=
config
.
key
):
def
__init__
(
self
,
address
=
config
.
address
,
port
=
config
.
port
,
hops
=
config
.
hops
,
key
=
config
.
key
):
core
.
EngineMixin
.
__init__
(
self
,
address
,
port
,
hops
,
key
)
core
.
EngineMixin
.
__init__
(
self
,
address
,
port
,
hops
,
key
)
self
.
__txFifo
=
asyncio
.
Queue
()
# tx msg fifo
self
.
__txFifo
=
asyncio
.
Queue
()
# tx msg fifo
...
@@ -132,7 +132,7 @@ class AsyncEngine(core.EngineMixin):
...
@@ -132,7 +132,7 @@ class AsyncEngine(core.EngineMixin):
async
def
handle_action_request
(
self
,
msg
,
target
):
async
def
handle_action_request
(
self
,
msg
,
target
):
try
:
try
:
result
=
await
run_action
(
msg
,
target
)
result
=
await
run_action
(
msg
,
target
)
if
result
!=
None
:
if
result
is
None
:
self
.
send_reply
(
dev
=
target
,
targets
=
[
msg
.
source
],
action
=
msg
.
action
,
body
=
result
)
self
.
send_reply
(
dev
=
target
,
targets
=
[
msg
.
source
],
action
=
msg
.
action
,
body
=
result
)
except
CallbackError
as
e
:
except
CallbackError
as
e
:
self
.
send_error
(
target
,
e
.
code
,
e
.
description
)
self
.
send_error
(
target
,
e
.
code
,
e
.
description
)
...
@@ -148,7 +148,7 @@ class AsyncEngine(core.EngineMixin):
...
@@ -148,7 +148,7 @@ class AsyncEngine(core.EngineMixin):
self
.
_loop
=
asyncio
.
get_event_loop
()
self
.
_loop
=
asyncio
.
get_event_loop
()
return
self
.
_loop
return
self
.
_loop
def
new_task
(
self
,
coro
,
name
=
None
):
def
new_task
(
self
,
coro
,
name
=
None
):
# we maintain a task list, to be able to stop/start the engine
# we maintain a task list, to be able to stop/start the engine
# on demand. needed by HASS
# on demand. needed by HASS
task
=
self
.
get_loop
().
create_task
(
coro
,
name
=
name
)
task
=
self
.
get_loop
().
create_task
(
coro
,
name
=
name
)
...
@@ -207,11 +207,11 @@ class AsyncEngine(core.EngineMixin):
...
@@ -207,11 +207,11 @@ class AsyncEngine(core.EngineMixin):
logger
.
warning
(
'
Engine already started
'
)
logger
.
warning
(
'
Engine already started
'
)
return
return
self
.
started_event
.
set
()
self
.
started_event
.
set
()
self
.
new_task
(
self
.
boot_task
(),
name
=
'
Boot
'
)
self
.
new_task
(
self
.
boot_task
(),
name
=
'
Boot
'
)
self
.
new_task
(
self
.
receive_task
(),
name
=
'
RecvQ
'
)
self
.
new_task
(
self
.
receive_task
(),
name
=
'
RecvQ
'
)
self
.
new_task
(
self
.
send_task
(),
name
=
'
SendQ
'
)
self
.
new_task
(
self
.
send_task
(),
name
=
'
SendQ
'
)
self
.
new_task
(
self
.
timer_task
(),
name
=
'
Timers
'
)
self
.
new_task
(
self
.
timer_task
(),
name
=
'
Timers
'
)
self
.
new_task
(
console
(
locals
()),
name
=
'
Console
'
)
self
.
new_task
(
console
(
locals
()),
name
=
'
Console
'
)
def
setup_alives_timer
(
self
):
def
setup_alives_timer
(
self
):
# needed on stop-start sequence
# needed on stop-start sequence
...
@@ -227,11 +227,11 @@ class AsyncEngine(core.EngineMixin):
...
@@ -227,11 +227,11 @@ class AsyncEngine(core.EngineMixin):
self
.
started_event
.
clear
()
self
.
started_event
.
clear
()
# cancel all tasks
# cancel all tasks
for
task
in
self
.
all_tasks
():
for
task
in
self
.
all_tasks
():
if
task
!=
self
.
_watchdog_task
:
if
task
!=
self
.
_watchdog_task
:
task
.
cancel
()
task
.
cancel
()
await
asyncio
.
sleep
(
0.1
)
await
asyncio
.
sleep
(
0.1
)
def
sigkill_handler
(
self
,
signal
,
frame
):
def
sigkill_handler
(
self
,
signal
,
frame
):
print
(
""
,
end
=
"
\r
"
)
#remove the uggly ^C
print
(
""
,
end
=
"
\r
"
)
#remove the uggly ^C
if
not
self
.
is_running
():
if
not
self
.
is_running
():
logger
.
warning
(
'
Engine already stopped
'
)
logger
.
warning
(
'
Engine already stopped
'
)
...
@@ -250,9 +250,9 @@ class AsyncEngine(core.EngineMixin):
...
@@ -250,9 +250,9 @@ class AsyncEngine(core.EngineMixin):
def
run
(
self
):
def
run
(
self
):
if
not
self
.
started_event
.
is_set
():
if
not
self
.
started_event
.
is_set
():
self
.
start
()
self
.
start
()
if
self
.
_watchdog_task
==
None
:
if
self
.
_watchdog_task
is
None
:
# start the watchdog task
# start the watchdog task
self
.
_watchdog_task
=
self
.
new_task
(
self
.
watchdog_task
(),
name
=
'
Watchdog task
'
)
self
.
_watchdog_task
=
self
.
new_task
(
self
.
watchdog_task
(),
name
=
'
Watchdog task
'
)
self
.
get_loop
().
run_until_complete
(
self
.
_watchdog_task
)
self
.
get_loop
().
run_until_complete
(
self
.
_watchdog_task
)
else
:
else
:
logger
.
warning
(
'
Engine already running
'
)
logger
.
warning
(
'
Engine already running
'
)
...
@@ -268,7 +268,7 @@ class AsyncEngine(core.EngineMixin):
...
@@ -268,7 +268,7 @@ class AsyncEngine(core.EngineMixin):
remain
=
round
(
t
.
deadline
-
now
,
1
)
remain
=
round
(
t
.
deadline
-
now
,
1
)
rows
.
append
([
str
(
t
.
func
),
t
.
period
,
t
.
counter
,
remain
])
rows
.
append
([
str
(
t
.
func
),
t
.
period
,
t
.
counter
,
remain
])
print
(
'
= Timers
'
)
print
(
'
= Timers
'
)
print
(
tabulate
(
rows
,
headers
=
headers
,
tablefmt
=
"
fancy_grid
"
))
print
(
tabulate
(
rows
,
headers
=
headers
,
tablefmt
=
"
fancy_grid
"
))
def
dump_tasks
(
self
):
def
dump_tasks
(
self
):
...
@@ -277,7 +277,7 @@ class AsyncEngine(core.EngineMixin):
...
@@ -277,7 +277,7 @@ class AsyncEngine(core.EngineMixin):
for
t
in
self
.
all_tasks
():
for
t
in
self
.
all_tasks
():
rows
.
append
([
t
.
get_name
(),
str
(
t
.
get_coro
()),
id
(
t
.
get_loop
())])
rows
.
append
([
t
.
get_name
(),
str
(
t
.
get_coro
()),
id
(
t
.
get_loop
())])
print
(
'
= Tasks
'
)
print
(
'
= Tasks
'
)
print
(
tabulate
(
rows
,
headers
=
headers
,
tablefmt
=
"
fancy_grid
"
))
print
(
tabulate
(
rows
,
headers
=
headers
,
tablefmt
=
"
fancy_grid
"
))
def
dump_devices
(
self
):
def
dump_devices
(
self
):
headers
=
[
"
addr
"
,
"
dev_type
"
,
"
info
"
]
headers
=
[
"
addr
"
,
"
dev_type
"
,
"
info
"
]
...
@@ -285,7 +285,7 @@ class AsyncEngine(core.EngineMixin):
...
@@ -285,7 +285,7 @@ class AsyncEngine(core.EngineMixin):
for
d
in
self
.
devices
:
for
d
in
self
.
devices
:
rows
.
append
([
d
.
address
,
d
.
dev_type
,
d
.
info
])
rows
.
append
([
d
.
address
,
d
.
dev_type
,
d
.
info
])
print
(
'
= Devices
'
)
print
(
'
= Devices
'
)
print
(
tabulate
(
rows
,
headers
=
headers
,
tablefmt
=
"
fancy_grid
"
))
print
(
tabulate
(
rows
,
headers
=
headers
,
tablefmt
=
"
fancy_grid
"
))
def
dump_hooks
(
self
):
def
dump_hooks
(
self
):
headers
=
[
"
Type
"
,
"
Hook
"
]
headers
=
[
"
Type
"
,
"
Hook
"
]
...
@@ -293,7 +293,7 @@ class AsyncEngine(core.EngineMixin):
...
@@ -293,7 +293,7 @@ class AsyncEngine(core.EngineMixin):
for
h
in
self
.
_hooks
:
for
h
in
self
.
_hooks
:
rows
.
append
([
h
.
type
,
str
(
h
.
func
)])
rows
.
append
([
h
.
type
,
str
(
h
.
func
)])
print
(
'
= Hooks
'
)
print
(
'
= Hooks
'
)
print
(
tabulate
(
rows
,
headers
=
headers
,
tablefmt
=
"
fancy_grid
"
))
print
(
tabulate
(
rows
,
headers
=
headers
,
tablefmt
=
"
fancy_grid
"
))
def
dump
(
self
):
def
dump
(
self
):
self
.
dump_devices
()
self
.
dump_devices
()
...
@@ -302,7 +302,7 @@ class AsyncEngine(core.EngineMixin):
...
@@ -302,7 +302,7 @@ class AsyncEngine(core.EngineMixin):
self
.
dump_hooks
()
self
.
dump_hooks
()
def
get_device
(
self
,
uuid
):
def
get_device
(
self
,
uuid
):
uuid
=
tools
.
get_uuid
(
uuid
)
uuid
=
tools
.
get_uuid
(
uuid
)
for
dev
in
self
.
devices
:
for
dev
in
self
.
devices
:
if
dev
.
address
==
uuid
:
if
dev
.
address
==
uuid
:
return
dev
return
dev
...
@@ -340,7 +340,7 @@ async def run_action(msg,device):
...
@@ -340,7 +340,7 @@ async def run_action(msg,device):
result
=
method
(
**
params
)
result
=
method
(
**
params
)
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
error
(
e
)
logger
.
error
(
e
)
raise
XAALError
(
"
Error in method:%s params:%s
"
%
(
msg
.
action
,
params
))
raise
XAALError
(
"
Error in method:%s params:%s
"
%
(
msg
.
action
,
params
))
return
result
return
result
...
@@ -353,7 +353,7 @@ class HookType(Enum):
...
@@ -353,7 +353,7 @@ class HookType(Enum):
class
Hook
(
object
):
class
Hook
(
object
):
__slots__
=
[
'
type
'
,
'
func
'
,
'
args
'
,
'
kwargs
'
]
__slots__
=
[
'
type
'
,
'
func
'
,
'
args
'
,
'
kwargs
'
]
def
__init__
(
self
,
type_
,
func
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
type_
,
func
,
*
args
,
**
kwargs
):
self
.
type
=
type_
self
.
type
=
type_
self
.
func
=
func
self
.
func
=
func
self
.
args
=
args
self
.
args
=
args
...
@@ -363,9 +363,9 @@ class Hook(object):
...
@@ -363,9 +363,9 @@ class Hook(object):
#####################################################
#####################################################
# Debugging console
# Debugging console
#####################################################
#####################################################
async
def
console
(
locals
=
locals
(),
port
=
None
):
async
def
console
(
locals
=
locals
(),
port
=
None
):
"""
launch a console to enable remote engine inspection
"""
"""
launch a console to enable remote engine inspection
"""
if
port
==
None
:
if
port
is
None
:
# let's find a free port if not specified
# let's find a free port if not specified
def
find_free_port
():
def
find_free_port
():
import
socketserver
import
socketserver
...
...
This diff is collapsed.
Click to expand it.
libs/lib/xaal/lib/core.py
+
3
−
2
View file @
2fb5c26d
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
#
#
from
.messages
import
MessageType
,
MessageAction
,
MessageFactory
,
ALIVE_ADDR
from
.messages
import
MessageType
,
MessageAction
,
MessageFactory
,
ALIVE_ADDR
from
.exceptions
import
*
from
.exceptions
import
EngineError
,
XAALError
import
time
import
time
import
inspect
import
inspect
...
@@ -75,7 +75,7 @@ class EngineMixin(object):
...
@@ -75,7 +75,7 @@ class EngineMixin(object):
def
queue_msg
(
self
,
msg
):
def
queue_msg
(
self
,
msg
):
logger
.
critical
(
"
To be implemented queue_msg: %s
"
,
msg
)
logger
.
critical
(
"
To be implemented queue_msg: %s
"
,
msg
)
def
send_request
(
self
,
dev
,
targets
,
action
,
body
=
None
):
def
send_request
(
self
,
dev
,
targets
,
action
,
body
=
None
):
"""
queue a new request
"""
"""
queue a new request
"""
msg
=
self
.
msg_factory
.
build_msg
(
dev
,
targets
,
MessageType
.
REQUEST
,
action
,
body
)
msg
=
self
.
msg_factory
.
build_msg
(
dev
,
targets
,
MessageType
.
REQUEST
,
action
,
body
)
self
.
queue_msg
(
msg
)
self
.
queue_msg
(
msg
)
...
@@ -222,6 +222,7 @@ class EngineMixin(object):
...
@@ -222,6 +222,7 @@ class EngineMixin(object):
def
is_running
(
self
):
def
is_running
(
self
):
logger
.
critical
(
"
To be implemented is_running
"
)
logger
.
critical
(
"
To be implemented is_running
"
)
return
False
#####################################################
#####################################################
# Timer class
# Timer class
...
...
This diff is collapsed.
Click to expand it.
libs/lib/xaal/lib/engine.py
+
4
−
3
View file @
2fb5c26d
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
from
.
import
core
from
.
import
core
from
.network
import
NetworkConnector
from
.network
import
NetworkConnector
from
.exceptions
import
*
from
.exceptions
import
MessageParserError
,
CallbackError
,
XAALError
from
.
import
config
from
.
import
config
import
time
import
time
...
@@ -126,7 +126,7 @@ class Engine(core.EngineMixin):
...
@@ -126,7 +126,7 @@ class Engine(core.EngineMixin):
"""
"""
try
:
try
:
result
=
run_action
(
msg
,
target
)
result
=
run_action
(
msg
,
target
)
if
result
!=
None
:
if
result
is
not
None
:
self
.
send_reply
(
dev
=
target
,
targets
=
[
msg
.
source
],
action
=
msg
.
action
,
body
=
result
)
self
.
send_reply
(
dev
=
target
,
targets
=
[
msg
.
source
],
action
=
msg
.
action
,
body
=
result
)
except
CallbackError
as
e
:
except
CallbackError
as
e
:
self
.
send_error
(
target
,
e
.
code
,
e
.
description
)
self
.
send_error
(
target
,
e
.
code
,
e
.
description
)
...
@@ -144,7 +144,8 @@ class Engine(core.EngineMixin):
...
@@ -144,7 +144,8 @@ class Engine(core.EngineMixin):
now
=
time
.
time
()
now
=
time
.
time
()
# little hack to avoid to check timer to often.
# little hack to avoid to check timer to often.
# w/ this enable timer precision is bad, but far enougth
# w/ this enable timer precision is bad, but far enougth
if
(
now
-
self
.
__last_timer
)
<
0.4
:
return
if
(
now
-
self
.
__last_timer
)
<
0.4
:
return
for
t
in
self
.
timers
:
for
t
in
self
.
timers
:
if
t
.
deadline
<
now
:
if
t
.
deadline
<
now
:
...
...
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