1 from copy
import deepcopy
4 """In order to implement an output class for use with Coccinelle,
5 one can inherit from this class and overload register_match with
6 the same number of arguments.
8 include_match will be overwritten by inheriting from your actual
9 class, and thus if your class is a.b.C then Coccinelle will create
10 a Python class "class Coccinelle(a.b.C)" that hooks include_match
11 into the O'Caml internals.
13 def include_match(self
, b
):
16 def register_match(self
, include
, messages
):
19 def combine(self
, meta_variable
, locations
):
20 nmv
= deepcopy(meta_variable
)
21 nloc
= [deepcopy(loc
) for loc
in locations
]
22 nmv
.location
= nloc
[0]
30 def print_main (self
, *args
):
31 from coccilib
.org
import print_main
34 def print_sec (self
, *args
):
35 from coccilib
.org
import print_sec
38 def print_secs (self
, *args
):
39 from coccilib
.org
import print_secs
42 class Console(Output
):
46 def register_match(self
, include
, messages
):
47 self
.include_match(include
)
49 for variable
, message
in messages
:
50 print "%s:%s:%s: %s - %s" % (variable
.location
.file, variable
.location
.line
, variable
.location
.column
, message
, variable
)
52 from threading
import Thread
53 class GtkRunner(Thread
):
55 from threading
import Lock
60 def add_row(self
, cocci
, l
):
61 for i
in xrange(0, len(l
)):
62 l
[i
] = (l
[i
][1], l
[i
][0].location
.file, l
[i
][0].location
.line
, l
[i
][0].location
.column
)
66 self
.rows
.append((cocci
, l
))
73 return len(self
.rows
) > 0
80 return self
.rows
.pop(0)
87 cocci
, l
= self
.get_row()
88 self
.gui
.add_result(cocci
, l
)
89 gobject
.timeout_add(1000, self
.update
)
93 import coccilib
.coccigui
.coccigui
94 self
.gui
= coccilib
.coccigui
.coccigui
.pycocci()
95 globals()['gtk_sock'] = self
.gui
96 gobject
.timeout_add(1000, self
.update
)
98 gtk
.gdk
.threads_init()
99 gtk
.gdk
.threads_enter()
103 gtk
.gdk
.threads_leave()
105 globals().pop('gtk_thread')
106 globals().pop('gtk_sock')
109 def check_availability(self
):
111 if not globals().has_key('gtk_sock'):
113 globals()['gtk_thread'] = t
114 globals()['gtk_thread'].start()
117 def register_match(self
, include
, messages
):
118 self
.check_availability()
120 self
.include_match(include
)
122 globals()['gtk_thread'].add_row(self
.cocci_file
, messages
)
125 self
.check_availability()
127 globals()['gtk_thread'].join()