3 import coccilib
.coccigui
4 import coccilib
.coccigui
.coccigui
5 from threading
import Thread
, Lock
7 from copy
import deepcopy
10 """In order to implement an output class for use with Coccinelle,
11 one can inherit from this class and overload register_match with
12 the same number of arguments.
14 include_match will be overwritten by inheriting from your actual
15 class, and thus if your class is a.b.C then Coccinelle will create
16 a Python class "class Coccinelle(a.b.C)" that hooks include_match
17 into the O'Caml internals.
19 def include_match(self
, b
):
22 def register_match(self
, include
, messages
):
25 def combine(self
, meta_variable
, locations
):
26 nmv
= deepcopy(meta_variable
)
27 nloc
= [deepcopy(loc
) for loc
in locations
]
28 nmv
.location
= nloc
[0]
36 class Console(Output
):
40 def register_match(self
, include
, messages
):
41 self
.include_match(include
)
43 for variable
, message
in messages
:
44 print "%s:%s:%s: %s - %s" % (variable
.location
.file, variable
.location
.line
, variable
.location
.column
, message
, variable
)
46 class GtkRunner(Thread
):
52 def add_row(self
, cocci
, l
):
53 for i
in xrange(0, len(l
)):
54 l
[i
] = (l
[i
][1], l
[i
][0].location
.file, l
[i
][0].location
.line
, l
[i
][0].location
.column
)
58 self
.rows
.append((cocci
, l
))
65 return len(self
.rows
) > 0
72 return self
.rows
.pop(0)
78 cocci
, l
= self
.get_row()
79 self
.gui
.add_result(cocci
, l
)
80 gobject
.timeout_add(1000, self
.update
)
83 self
.gui
= coccilib
.coccigui
.coccigui
.pycocci()
84 globals()['gtk_sock'] = self
.gui
85 gobject
.timeout_add(1000, self
.update
)
87 gtk
.gdk
.threads_init()
88 gtk
.gdk
.threads_enter()
92 gtk
.gdk
.threads_leave()
94 globals().pop('gtk_thread')
95 globals().pop('gtk_sock')
98 def check_availability(self
):
99 if not globals().has_key('gtk_sock'):
101 globals()['gtk_thread'] = t
102 globals()['gtk_thread'].start()
105 def register_match(self
, include
, messages
):
106 self
.check_availability()
108 self
.include_match(include
)
110 globals()['gtk_thread'].add_row(self
.cocci_file
, messages
)
113 self
.check_availability()
115 globals()['gtk_thread'].join()