Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/id_explicite.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
inputs:
stdin: 0
- {fd: 0, name: stdin}
outputs:
stdout: 1
- {fd: 1, name: stdout}
nodes:
- command: [cat]
inputs:
0: stdin
- {fd: 0, name: stdin}
outputs:
1: stdout
- {fd: 1, name: stdout}
8 changes: 4 additions & 4 deletions examples/join_explicite.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
outputs:
stdout: 1
- {fd: 1, name: stdout}
nodes:
- command: [echo, one]
outputs:
1: stdout
- {fd: 1, name: stdout}
- command: [echo, two]
outputs:
1: stdout
- {fd: 1, name: stdout}
- command: [echo, three]
outputs:
1: stdout
- {fd: 1, name: stdout}
8 changes: 4 additions & 4 deletions examples/join_pipe.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
nodes:
- command: [echo, one]
outputs:
1: into_cat
- {fd: 1, name: into_cat}
- command: [echo, two]
outputs:
1: into_cat
- {fd: 1, name: into_cat}
- command: [echo, three]
outputs:
1: into_cat
- {fd: 1, name: into_cat}
- command: [cat]
inputs:
0: into_cat
- {fd: 0, name: into_cat}
2 changes: 1 addition & 1 deletion examples/orphaned_read_end.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nodes:
- command: [/bin/true]
outputs:
1: a_pipe
- {fd: 1, name: a_pipe}
2 changes: 1 addition & 1 deletion examples/orphaned_write_end.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nodes:
- command: [/bin/true]
inputs:
0: a_pipe
- {fd: 0, name: a_pipe}
26 changes: 13 additions & 13 deletions examples/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@ nodes:
# ncat tcp server waiting for many connections
- command: [ncat, -v, -l, -k, -p7000]
inputs:
0: send
- {fd: 0, name: send}
outputs:
2: log
1: received
- {fd: 2, name: log}
- {fd: 1, name: received}

# periodic echo of current date is sent to opened connections
- command: [bash, -c, 'while true; do date; sleep 10; done']
outputs:
1: send
- {fd: 1, name: send}

# log being saved to a file
- command: [bash, -c, 'cat > logfile.txt']
inputs:
0: log
- {fd: 0, name: log}

# incoming data is echoed back but also processed by our fancy machinery
- command: [tee, /proc/self/fd/3]
inputs:
0: received
- {fd: 0, name: received}
outputs:
1: send
3: unfiltered_exprs
- {fd: 1, name: send}
- {fd: 3, name: unfiltered_exprs}

# pass only lines beginning with #
- command: [sed, -rn, -u, 's/^#(.*)/\1/p']
inputs:
0: unfiltered_exprs
- {fd: 0, name: unfiltered_exprs}
outputs:
1: exprs
- {fd: 1, name: exprs}

# evaluate expressions and send results
- command: [xargs, -L1, expr]
inputs:
0: exprs
- {fd: 0, name: exprs}
outputs:
1: send
2: send
- {fd: 1, name: send}
- {fd: 2, name: send}
5 changes: 5 additions & 0 deletions logfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Listening on :::7000
Ncat: Listening on 0.0.0.0:7000
Ncat: Connection from 127.0.0.1.
Ncat: Connection from 127.0.0.1:56596.
25 changes: 16 additions & 9 deletions pgspawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
logger = logging.getLogger(__name__)


def bimap_dict(key_f, val_f, d):
def connection_arr2dict(arr):
return {
key_f(k): val_f(v)
for k, v in d.items()
int(c['fd']): str(c['name'])
for c in arr
}


def connection_arr2dict_inv(arr):
return {
str(c['name']): int(c['fd'])
for c in arr
}


Expand Down Expand Up @@ -39,9 +46,9 @@ def from_dict(cls, description):

return cls(
command=[str(p) for p in description['command']],
inputs=bimap_dict(int, str, description.get('inputs', {})),
outputs=bimap_dict(int, str, description.get('outputs', {})),
sockets=bimap_dict(int, str, description.get('sockets', {})),
inputs=connection_arr2dict(description.get('inputs', [])),
outputs=connection_arr2dict(description.get('outputs', [])),
sockets=connection_arr2dict(description.get('sockets', [])),
separate_group=bool(description.get('separate_group', False)),
signals=[str2sig(str(s)) for s in description.get('signals', [])],
)
Expand All @@ -55,9 +62,9 @@ def from_dict(cls, description):
logger.warning("Unknown keys in graph description dict: {}".format(unknown_keys))

g = cls(
inputs=bimap_dict(str, int, description.get('inputs', {})),
outputs=bimap_dict(str, int, description.get('outputs', {})),
sockets=bimap_dict(str, int, description.get('sockets', {})),
inputs=connection_arr2dict_inv(description.get('inputs', [])),
outputs=connection_arr2dict_inv(description.get('outputs', [])),
sockets=connection_arr2dict_inv(description.get('sockets', [])),
nodes=list(map(Node.from_dict, description.get('nodes', []))),
)

Expand Down
15 changes: 15 additions & 0 deletions test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env pgspawn
nodes:
- command: [minos/minos, 0, 3, "-,1"]
inputs:
0: program
3: program_inner
outputs:
#1: test
- command: [cat, programs/cnew.c.bin]
outputs: {1: program}
- command: [cat, programs/hello.asm.bin]
outputs: {1: program_inner}
- command: [./stdin-eq, "parent\nhello world\n"]
inputs:
0: test