coccigrep provides an abstraction for running spatch in the scope of searching for information in C source code.

There is two interesting classes:

To build a request:

Documentation of module

exception coccigrep.CocciConfigException(value)[source]

Exception raised when configuration parameter are not correct.

For example, it is returned if spatch command can not be found.

exception coccigrep.CocciException(value)[source]

Generic class for coccigrep exception

class coccigrep.CocciGrep[source]

Core class of the module: setup and run.

This class is the core of the module. It is responsible of initialisation and running of the request.


Add operation to the list of supported operations

Parameters:new_ops (list of str) – list of filenames (ending by .cocci)
display(mode='raw', before=0, after=0, oformat='term')[source]

Display output for complete request

  • mode (str) – display mode
  • before (int) – number of lines to display before match
  • after (int) – number of lines to display after match
  • oformat (str) – format of output for color (term, html)

the result of the search as a str


Get list of available operations

Returns:list of operations in a list of str

Run the search against the files given in argument

This function is doing the main job. It will run spatch with the correct parameters by using subprocess or it will use multiprocessing if a concurrency level greater than 1 has been asked.

Parameters:files (list of str) – list of filenames
Raise :CocciRunException or CocciConfigException

Set concurrency level (number of spatch command to run in parallel)

Parameters:ncpus (int) – number of process to launch in parallel

Set path or command name for spatch

Parameters:cmd (str) – Name of parth of the spatch command

Activate verbose mode

setup(stype, attribut, operation)[source]
  • stype (str) – structure name, used to replace ‘$type’ in the cocci file
  • attribut (str) – basically attribut of the structure, used to replace ‘$attribut’ in the cocci file
  • operation (str) – search operation to do
Raise :


class coccigrep.CocciGrepConfig[source]

Configuration handling class

This class parses configuration and can be used to access to configuration item via get operations. CocciGrepConfig is derived from SafeConfigParser

class coccigrep.CocciMatch(mfile, mline, mcol, mlineend, mcolend)[source]

Store a match and take care of its display

display(stype, mode='raw', oformat='term', before=0, after=0)[source]

Display output for a single match

  • mode (str) – display mode
  • oformat (str) – format of output for color (term, html)
  • before (int) – number of lines to display before match
  • after (int) – number of lines to display after match
class coccigrep.CocciProcess(cmd, verbose)[source]

Class used for running spatch command in the case of multiprocessing

exception coccigrep.CocciRunException(value)[source]

Exception raised when running parameters are not correct.

For example, it is returned if a required argument is missing.

Table Of Contents

Previous topic

Welcome to coccigrep’s documentation!

This Page