Skip to content

Commit

Permalink
perm.py: remove broken hack for excluding transitive edges
Browse files Browse the repository at this point in the history
Graphviz includes the tred program for computing transitive reduction
so use this to post process the complete graph instead.  This means
that graphs containing edges that drop more than one perm that are not
implied by transitivity are displayed correctly.
  • Loading branch information
ronorton committed Jul 18, 2024
1 parent 1a107c1 commit 1064c99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion archdoc/misc/perms/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
all: perms.svg

perms.dot: perms.py
./perms.py > $@
./perms.py | tred > $@

%.svg : %.dot
dot -Tsvg -o $@ $<
Expand Down
26 changes: 12 additions & 14 deletions archdoc/misc/perms/perms.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,28 +134,26 @@ def comb_to_str(c):
return '_'.join(cs) or "0"

# Now we output a graph representation of the useful combinations in dot format.
# To make it pretty we add edges for the subset partial order, excluding edges
# implied by transitivity.
# To make it pretty we add edges for the subset partial order.

print("digraph {")

# Output the names of nodes in the graph
for x in useful_combinations:
print(comb_to_str(x))

# Output the edges for the subset relation. To exclude transitive edges
# we stick to pairs of combinations that differ in size by one. This
# doesn't work for all graphs but seems to be OK for us.
# Output the edges for the subset relation. This results in many redundant edges
# but fortunately graphviz provides `tred` for computing the transitive
# reduction.
for x in useful_combinations:
for y in useful_combinations:
if len(x) + 1 == len(y):
xs = set(x)
ys = set(y)
if xs.issubset(ys):
# find the permission in ys not in xs to use as label
diff = (ys - xs).pop()
x_str=comb_to_str(x)
y_str=comb_to_str(y)
print(f"{y_str} -> {x_str} [label=\"{diff}\", fontsize=10]")
xs = set(x)
ys = set(y)
if xs < ys:
# find the permissions in ys not in xs to use as label
diff = ys - xs
x_str=comb_to_str(x)
y_str=comb_to_str(y)
print(f"{y_str} -> {x_str} [label=\"{comb_to_str(diff)}\", fontsize=10]")

print("}")

0 comments on commit 1064c99

Please sign in to comment.