Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Franck Pommereau
/
ttc.js
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Franck Pommereau
2023-04-06 13:38:26 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
608dcc1adb33ff13f01e92cf33671e33676d30ed
608dcc1a
1 parent
be38c0f5
improved 'when', fixed simul.disconnect
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
3 deletions
ttc/run.py
ttc/simul.py
ttc/run.py
View file @
608dcc1
...
...
@@ -411,13 +411,19 @@ class ShellRunner (Runner) :
"""
for
evt
in
event
:
self
.
watch
(
evt
)
async
def
cmd_when
(
self
,
event
:
str
,
cmd
:
str
,
*
args
:
str
)
:
async
def
cmd_when
(
self
,
event
:
str
,
c
ount
:
int
,
c
md
:
str
,
*
args
:
str
)
:
"""execute command on specified event
- event: watched event
- count: number of occurrences (0 => infinite)
- cmd: a shell command
- args: arguments for cmd"""
def
cb
(
e
,
*
a
)
:
loop
=
asyncio
.
get_event_loop
()
asyncio
.
run_coroutine_threadsafe
(
self
.
_cmd_call
(
cmd
,
args
),
loop
)
cb
.
count
-=
1
if
cb
.
count
==
0
:
self
.
ignore
(
event
)
cb
.
count
=
count
self
.
watch
(
event
,
cb
)
async
def
cmd_ignore
(
self
,
*
event
:
str
)
:
"""ignore specified events
...
...
ttc/simul.py
View file @
608dcc1
...
...
@@ -57,9 +57,9 @@ class Simulator (object) :
self
.
cb
=
{}
self
.
_ident
=
0
def
connect
(
self
,
pattern
,
cb
)
:
ident
=
self
.
_ident
self
.
_ident
+=
1
self
.
cb
[
self
.
_ident
]
=
(
pattern
,
cb
)
return
self
.
_ident
def
disconnect
(
self
,
ident
)
:
self
.
cb
.
pop
(
ident
,
None
)
async
def
ttc_event
(
self
,
name
,
*
args
)
:
...
...
@@ -76,7 +76,7 @@ class Simulator (object) :
if
a
is
NONE
:
args
[
i
]
=
None
done
=
set
()
for
pat
,
fun
in
self
.
cb
.
values
(
)
:
for
pat
,
fun
in
list
(
self
.
cb
.
values
()
)
:
if
fun
in
done
:
continue
if
match
(
event
,
pat
)
:
...
...
Please
register
or
login
to post a comment