Exemplo n.º 1
0
 def get_custom_res_obj_representation(script):
     ''' Get the representation of the custom result object.
     This is the data repr. that shall stored '''
     cres = script.cres
     if isinstance(cres, CustomResultObjInterface):
         return cres.get_custom_result_obj_repr()
     elif ScriptUtil.is_result_object(cres):
         return cres.write_to_json()
     return str(cres)
Exemplo n.º 2
0
 def get_custom_res_obj_representation(script):
     """ Get the representation of the custom result object.
     This is the data repr. that shall stored """
     cres = script.cres
     if isinstance(cres, CustomResultObjInterface):
         return cres.get_custom_result_obj_repr()
     elif ScriptUtil.is_result_object(cres):
         return cres.write_to_json()
     return str(cres)
Exemplo n.º 3
0
    def store_result_for_apk(self, apk, script):
        '''
        Store the results in the file system.

        If a custom result object is used in `script` and it's not a `ResultObject`,
        str(custom res object) will be used for writing to disk.

        Parameters
        ----------
        apk: Apk
        script: AndroScript

        Raises
        ------
        FileSysStoreException

        Returns
        -------
        str
            Path to result file.
        '''
        try:
            res_filename = self.get_apk_res_filename(apk, script)
            with open(res_filename, "w") as f:
                log.debug("storing results for %s, %s to %s", apk.short_description(), script, res_filename)
                if not script.uses_custom_result_object():
                    f.write(script.res.write_to_json())
                else:
                    res = self.get_custom_res_obj_representation(script)
                    # log json if custom res obj is `ResultObject
                    if ScriptUtil.is_result_object(res):
                        res = res.write_to_json()
                    f.write(res)
            return res_filename
        except IOError as e:
            raise FileSysStoreException(res_filename, str(apk), self, e)