Skip to content

Instantly share code, notes, and snippets.

@jul
Last active May 5, 2020
Embed
What would you like to do?
transformer un dict en graph version 0.0.7
#!/usr/bin/env python3
# usage python3 dict2graph.py | xdot -
DIGRAPH = """digraph structs {
graph [
rankdir= "TD"
bgcolor=white
]
node [
fontsize=12
shape=record
width=2
]
%s
}
"""
from archery import mdict
from archery.barrack import make_from_path, mapping_row_iter
FSM = sum(map(lambda p:make_from_path(mdict,p), [
( "INIT-REBOOT","REBOOTING", "REQUEST"),
( "REBOOTING", "INIT", "NAK restart"),
( "REBOOTING", "BOUND", "ACK t1,t2"),
( "INIT", "SELECTING", "Send DISCOVER" ),
( "SELECTING", "SELECTING", "Pool OFFER"),
( "SELECTING", "REQUESTING", "send REQUEST w offer"),
( "REQUESTING", "REQUESTING", "Discard OFFER"),
( "REQUESTING", "BOUND", "ACK offer"),
( "REQUESTING", "INIT", "NAK offer"),
( "BOUND", "BOUND", "OFFER/ACK/NAK discard"),
( "BOUND", "RENEWING", "REQUEST on t1 expires"),
( "RENEWING", "BOUND", "ACK lease"),
( "RENEWING", "REBINDING", "on t2 exp bct REQUEST"),
( "REBINDING", "BOUND", "ACK t1,t2"),
( "REBINDING", "INIT", "lease exp, NAK stop net"),
( "RENEWING", "INIT", "NAK, halt net"),
]), mdict())
print(DIGRAPH % ("\t" + "\n\t".join(
map(
lambda p: '''"%s" -> "%s" [label="%s"];''' % p,
mapping_row_iter(FSM)
))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment