aboutsummaryrefslogtreecommitdiff
path: root/use2dot/change_graph.py
blob: 50d1c34ff19c0ab3dffee7d67b2668ad735b1358 (plain)
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
#!/usr/bin/env python3

import re
import colorsys
import hashlib
import sys

def md5(str):
    return hashlib.md5(str.encode("UTF-8")).hexdigest()

def rgb(str):
    return md5(str)[0:6]

def main(args):

    if len(args) < 3:
        print("Usage: ./change_graph.py <infile> <outfile>")
        return

    [_, infile, outfile, *rest] = args

    with open(infile) as f:
        lines = f.readlines()
        # [3:-1]

    f = open(outfile, 'w')

    for line in lines:
        m = re.search('^( *"\(([^)]*)\)" -> "(\([^)]*\))");', line)
        if m:
            f.write(f'{m.group(1)} [color="#{rgb(m.group(2))}"];\n')
        else:
            f.write(line)
        # colorsys.hsv_to_rgb(


#  "(server macro)" -> "(ice-9 regex)";

if __name__ == "__main__":
    main(sys.argv)