Exchanging data between analysis level and application level

Inside a given plugin, data can be exchanged between code that run during analysis and code that run at the end of application through intermediate files.

Each execution unit will trigger events from analysis level extension that will accumulate data into a intermediate files. During end_analysis those files can be read in order to perform a global operation.

_images/data_exchange.png

During analysis by calling cast.analysers.AnalysisLevelExtension.get_intermediate_file():

def MyExtension(cast.analysers.jee.Extension):

    def start_analysis(self, options):

        f = self.get_intermediate_file("file.txt")
        f.write('hello world')

At the end of application by calling cast.application.ApplicationLevelExtension.get_intermediate_file(),

ApplicationLevelExtension.get_intermediate_file(name)

Return an intermediate file by name. The file is open in read mode.

Return type:fileinput.FileInput

Raises an exception when the file does not exist.

that will act as an open ‘fake file’ corresponding to the contatenation of all intermediate files of the given name:

class ExtensionApplication(cast.application.ApplicationLevelExtension):

    def end_application(self, application):

        for line in self.get_intermediate_file("file.txt"):
            # should print hello world! to log
            logging.info(line)

Or by calling cast.application.ApplicationLevelExtension.get_intermediate_files(),

ApplicationLevelExtension.get_intermediate_files(name)

Return all the intermediate files of given name. The files are open in read mode.

Return type:list of read opened files

that will return each intermediate opened file one by one:

class ExtensionApplication(cast.application.ApplicationLevelExtension):

    def end_application(self, application):

        for f in self.get_intermediate_files("file.txt"):
            # should print hello world! to log
            logging.info(f.read())

The name of the file must be unique per plugin.