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 def print_main(self
, msg
, p
) :
37 print "* TODO [[view:%s::face=ovl-face1::linb=%s::colb=%s::cole=%s][%s %s::%s]]" % (p
[0].file,p
[0].line
,p
[0].column
,p
[0].column_end
,msg
,p
[0].file,p
[0].line
)
39 def print_sec(self
, msg
, p
) :
40 print "[[view:%s::face=ovl-face2::linb=%s::colb=%s::cole=%s][%s]]" % (p
[0].file,p
[0].line
,p
[0].column
,p
[0].column_end
,msg
)
42 def print_secs(self
, msg
, ps
) :
44 print "[[view:%s::face=ovl-face2::linb=%s::colb=%s::cole=%s][%s]]" % (i
.file,i
.line
,i
.column
,i
.column_end
,msg
)
46 class Console(Output
):
50 def register_match(self
, include
, messages
):
51 self
.include_match(include
)
53 for variable
, message
in messages
:
54 print "%s:%s:%s: %s - %s" % (variable
.location
.file, variable
.location
.line
, variable
.location
.column
, message
, variable
)
56 class GtkRunner(Thread
):
62 def add_row(self
, cocci
, l
):
63 for i
in xrange(0, len(l
)):
64 l
[i
] = (l
[i
][1], l
[i
][0].location
.file, l
[i
][0].location
.line
, l
[i
][0].location
.column
)
68 self
.rows
.append((cocci
, l
))
75 return len(self
.rows
) > 0
82 return self
.rows
.pop(0)
88 cocci
, l
= self
.get_row()
89 self
.gui
.add_result(cocci
, l
)
90 gobject
.timeout_add(1000, self
.update
)
93 self
.gui
= coccilib
.coccigui
.coccigui
.pycocci()
94 globals()['gtk_sock'] = self
.gui
95 gobject
.timeout_add(1000, self
.update
)
97 gtk
.gdk
.threads_init()
98 gtk
.gdk
.threads_enter()
102 gtk
.gdk
.threads_leave()
104 globals().pop('gtk_thread')
105 globals().pop('gtk_sock')
108 def check_availability(self
):
109 if not globals().has_key('gtk_sock'):
111 globals()['gtk_thread'] = t
112 globals()['gtk_thread'].start()
115 def register_match(self
, include
, messages
):
116 self
.check_availability()
118 self
.include_match(include
)
120 globals()['gtk_thread'].add_row(self
.cocci_file
, messages
)
123 self
.check_availability()
125 globals()['gtk_thread'].join()