summaryrefslogtreecommitdiff
path: root/doc/widget_hierarchy.py
diff options
context:
space:
mode:
authorGustavo Lima Chaves <glima@profusion.mobi>2012-06-05 22:41:21 +0000
committerGustavo Lima Chaves <glima@profusion.mobi>2012-06-05 22:41:21 +0000
commitcdf9bf6d02ad3ab52c84f7ef4651b72fe6605990 (patch)
tree10482424ec1d5f9c83a064a6b276b8b1678a1d28 /doc/widget_hierarchy.py
parentb64b8a7ef55f20b1a571f4bbf33d0a586d5eb859 (diff)
[elm] Welcome pretty widget hierarchy images on docs.
The Makefile rule building that is commented out -- meant to be run locally once in a while (when changes on overall widget tree happen) and changed images commited. SVN revision: 71721
Diffstat (limited to 'doc/widget_hierarchy.py')
-rwxr-xr-xdoc/widget_hierarchy.py135
1 files changed, 135 insertions, 0 deletions
diff --git a/doc/widget_hierarchy.py b/doc/widget_hierarchy.py
new file mode 100755
index 000000000..a53d29a57
--- /dev/null
+++ b/doc/widget_hierarchy.py
@@ -0,0 +1,135 @@
1#!/usr/bin/env python
2
3import re
4import os
5import sys
6import pickle
7from optparse import OptionParser
8
9def print_node(a, b, back=False):
10 print '"%s" -> "%s"' % (a, b), " [dir=back];" if back else ";"
11
12def topological_sort(dep_map, value):
13 hierarchy = []
14
15 def sort_do(dep_map, value):
16 if value is None:
17 return
18
19 hierarchy.insert(0, value)
20 sort_do(dep_map, dep_map.get(value, None))
21
22 sort_do(dep_map, value)
23
24 return hierarchy
25
26def hierachy_build(files_list):
27 cls_map = {"Elm_Widget_Smart_Class": "widget"}
28
29 for path in files_list:
30 contents = ''.join(l[:-1] for l in open(path))
31 m = re.search(class_re, contents)
32 if m is not None:
33 items.setdefault(m.group(3), []).append(m.group(1))
34 if m.group(2) != m.group(3):
35 cls_map[m.group(2)] = m.group(1)
36
37 for k, v in items.iteritems():
38 clsname = cls_map.get(k, k)
39 for c in v:
40 hierarchy[c] = clsname
41
42def files_list_build(d):
43 files_list = []
44 for f in os.listdir(d):
45 if f.endswith('.c'):
46 files_list.append(d + '/' + f)
47
48 return files_list
49
50#widget name, widget class, parent class
51class_re = 'EVAS_SMART_SUBCLASS_NEW.*?,.*?_elm_(\w+).*?,.*?(\w+).*?,.*?(\w+)'
52
53usage = "usage: %prog -s -d <DIRECTORY> -o <OUTPUT_FILE>\n" \
54 " %prog -w <WIDGET_NAME> -i <INPUT_FILE>\n" \
55 " %prog -t -i <INPUT_FILE>\n"
56parser = OptionParser(usage=usage)
57parser.add_option(
58 "-s", "--scan", action="store_true", dest="scan",
59 help="scan for .h/.c files and build the whole widget tree")
60parser.add_option(
61 "-d", "--directory", dest="scan_dir", default=None, type="str",
62 help="directory where to scan for .h/.c files")
63parser.add_option(
64 "-o", "--output", dest="output_file", default=None, type="str",
65 help="path of the output scanning file (widget tree)")
66
67parser.add_option(
68 "-w", "--widget", dest="widget", default=None, type="str",
69 help="name of an specific widget to generate a hierarchy tree for")
70parser.add_option(
71 "-i", "--input", dest="input_file", default=None, type="str",
72 help="path of the input (widget tree) where to get data from")
73
74parser.add_option(
75 "-t", "--tree", action="store_true", dest="tree",
76 help="generate the whole hierarchy tree")
77
78opts, args = parser.parse_args()
79
80if (not opts.scan and not opts.widget and not opts.tree) \
81 or (opts.scan and opts.widget) \
82 or (opts.scan and opts.tree) or \
83 (opts.tree and opts.widget):
84 sys.exit(parser.print_usage())
85
86if opts.scan and (not opts.scan_dir or not opts.output_file):
87 sys.exit(parser.print_usage())
88
89if opts.widget and not opts.input_file:
90 sys.exit(parser.print_usage())
91
92if opts.tree and not opts.input_file:
93 sys.exit(parser.print_usage())
94
95items = {}
96hierarchy = {}
97
98if opts.scan:
99 files = files_list_build(opts.scan_dir)
100 hierachy_build(files)
101 pickle.dump(hierarchy, open(opts.output_file, "wb" ))
102 sys.exit()
103
104if opts.tree:
105 print "digraph elm { node [shape=box];"
106 print "rankdir=RL;"
107
108 f = open(opts.input_file)
109 if not f:
110 sys.exit("Bad input file path")
111
112 hierarchy = pickle.load(f)
113 for cls, parent in hierarchy.items():
114 print_node(cls, parent, True);
115
116 print "}"
117
118if opts.widget:
119 print "digraph elm { node [shape=box];"
120
121 f = open(opts.input_file)
122 if not f:
123 sys.exit("Bad input file path")
124
125 hierarchy = pickle.load(f)
126 l = topological_sort(hierarchy, opts.widget)
127
128 def pairs(lst):
129 for i in range(1, len(lst)):
130 yield lst[i-1], lst[i]
131
132 for i1, i2 in pairs(l):
133 print_node(i1, i2);
134
135 print "}"