-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_tools.py
43 lines (31 loc) · 1.5 KB
/
debug_tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# coding=utf-8
from dsn.s_expr.legato import NoteCapo
def print_nouts(possible_timelines, present_nout_hash):
# Shows how the Nouts ref, but does not go inside notes
present_nout = possible_timelines.get(present_nout_hash)
prev_nout = possible_timelines.get(present_nout.previous_hash)
if prev_nout == NoteCapo():
result = ""
else:
result = print_nouts(possible_timelines, present_nout.previous_hash) + "\n"
return result + repr(present_nout_hash) + ': ' + repr(present_nout)
def print_nouts_2(possible_timelines, present_nout_hash, indentation, seen):
def short_repr_nout(nout):
if hasattr(nout, 'note'):
return repr(nout.note)
return "CAPO"
# Shows how the Nouts ref recursively
if present_nout_hash.as_bytes() in seen:
return (indentation * " ") + ":..."
seen.add(present_nout_hash.as_bytes())
present_nout = possible_timelines.get(present_nout_hash)
if present_nout == NoteCapo():
result = ""
else:
result = print_nouts_2(possible_timelines, present_nout.previous_hash, indentation, seen) + "\n\n"
if hasattr(present_nout, 'note') and hasattr(present_nout.note, 'nout_hash'):
horizontal_recursion = "\n" + print_nouts_2(possible_timelines, present_nout.note.nout_hash, indentation + 4,
seen)
else:
horizontal_recursion = ""
return result + (indentation * " ") + short_repr_nout(present_nout) + horizontal_recursion