Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Franck Pommereau
/
snakes
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
2013-11-26 11:11:34 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5bc14b1b121ef698aacca87678398172d9e6320e
5bc14b1b
1 parent
935eb383
improved plugin modules
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
7 deletions
snakes/plugins/modules.py
snakes/plugins/modules.py
View file @
5bc14b1
...
...
@@ -7,6 +7,12 @@ Moreover, when nodes are attached to a net, they inherit the modules
from this net. When nodes are merged, their sets of modules is added
to build the set of modules of the new node.
The plugin implements a very basic notion of modules, un particular,
it does not support hierarchy and when a module is attached to a node,
it is not possible to remove it. So modules are only a way to remember
where a node comes from and to tag nodes as we aggregate nets, e.g.,
through compositions (see plugin `ops`).
Internally, modules are stored in a label called `"modules"` (see
plugin `snakes.plugins.labels`).
...
...
@@ -23,11 +29,17 @@ set(['hello'])
>>> n2.add_place(Place("r"))
>>> n2.add_place(Place("s", modules="spam"))
>>> n = n1|n2
>>> list(sorted((p.name, p.modules()) for p in n.place()))
[('[p|]', set(['hello'])),
('[q|]', set(['hello'])),
('[|r]', set(['world'])),
('[|s]', set(['world', 'spam']))]
>>> list(sorted((p.name, list(sorted(p.modules()))) for p in n.place()))
[('[p|]', ['hello']),
('[q|]', ['hello']),
('[|r]', ['world']),
('[|s]', ['spam', 'world'])]
>>> n.modules("egg")
>>> list(sorted((p.name, list(sorted(p.modules()))) for p in n.place()))
[('[p|]', ['egg', 'hello']),
('[q|]', ['egg', 'hello']),
('[|r]', ['egg', 'world']),
('[|s]', ['egg', 'spam', 'world'])]
"""
from
snakes.plugins
import
plugin
,
new_instance
...
...
@@ -65,8 +77,10 @@ def extend (module) :
def
modules
(
self
,
modules
=
None
)
:
if
modules
is
None
:
return
self
.
label
(
"modules"
)
else
:
self
.
label
(
modules
=
set
(
iterate
(
modules
)))
mod
=
set
(
iterate
(
modules
))
self
.
label
(
modules
=
mod
)
for
node
in
self
.
node
()
:
node
.
modules
(
mod
|
node
.
modules
())
def
add_place
(
self
,
place
,
**
options
)
:
mod
=
set
(
iterate
(
options
.
pop
(
"modules"
,
self
.
modules
())))
module
.
PetriNet
.
add_place
(
self
,
place
,
**
options
)
...
...
Please
register
or
login
to post a comment