Example #1
0
    def analyze_file(self, an_uri):
        """Returns a FileDescription

        :param an_uri: the URI pointing to the file to be analyzed
        :rtype: :py:class:`damn_at.FileDescription`
        :raises: AnalyzerException, AnalyzerFileException, AnalyzerUnknownTypeException
        """
        if not is_existing_file(an_uri):
            raise AnalyzerFileException('E: Analyzer: No such file "%s"!' %
                                        (an_uri))
        mimetype = mimetypes.guess_type(an_uri, False)[0]
        if mimetype in self.analyzers:
            try:
                file_descr = self.analyzers[mimetype].plugin_object.analyze(
                    an_uri)
                file_descr.mimetype = mimetype
                self._file_metadata(an_uri, file_descr)
                return file_descr
            except Exception as ex:
                import traceback
                traceback.print_exc()
                raise AnalyzerException(
                    "E: Failed to analyze %s because of %s" %
                    (an_uri, str(ex)))
        else:
            raise AnalyzerUnknownTypeException(
                "E: Analyzer: No analyzer for %s (file: %s)" %
                (mimetype, an_uri))
Example #2
0
    def test_is_existing_file_b(self):
        """Test returns true when given a valid path"""

        f = tempfile.NamedTemporaryFile(delete=False)
        f.close()
        ret = utils.is_existing_file(f.name)
        self.assertTrue(ret)
Example #3
0
    def analyze_file(self, an_uri):
        """Returns a FileDescription

        :param an_uri: the URI pointing to the file to be analyzed
        :rtype: :py:class:`damn_at.FileDescription`
        :raises: AnalyzerException, AnalyzerFileException, AnalyzerUnknownTypeException
        """
        if not is_existing_file(an_uri):
            raise AnalyzerFileException('E: Analyzer: No such file "%s"!' % (an_uri))
        mimetype = mimetypes.guess_type(an_uri, False)[0]
        if mimetype in self.analyzers:
            try:
                file_descr = self.analyzers[mimetype].plugin_object.analyze(an_uri)
                file_descr.mimetype = mimetype
                self._file_metadata(an_uri, file_descr)
                return file_descr
            except Exception as ex:
                import traceback
                traceback.print_exc()
                raise AnalyzerException("E: Failed to analyze %s because of %s" % (an_uri, str(ex)))
        else:
            raise AnalyzerUnknownTypeException("E: Analyzer: No analyzer for %s (file: %s)" % (mimetype, an_uri))
Example #4
0
    def test_is_existing_file_a(self):
        """Test returns false when given a bad path"""

        ret = utils.is_existing_file('/foo/monkey/slug/shit')
        self.assertFalse(ret)
Example #5
0
 def is_in_store(self, store_id, an_hash):
     """
     Check if the given file hash is in the store.
     """
     return is_existing_file(os.path.join(self.store_path, hash_to_dir(an_hash)))
 def test_is_existing_file_b(self):
     """Test returns true when given a valid path"""
     f = tempfile.NamedTemporaryFile(delete=False)
     f.close()
     ret = utils.is_existing_file(f.name)
     self.assertTrue(ret)
    def test_is_existing_file_a(self):
        """Test returns false when given a bad path"""

        ret = utils.is_existing_file('/foo/monkey/slug/shit')
        self.assertFalse(ret)