Ejemplo n.º 1
0
 def __init__(self, exec_path, kind=NOMOS):
     self.kind = kind
     if kind == SCANCODE:
         self.analyzer = ScanCode(exec_path)
     elif kind == SCANCODE_CLI:
         self.analyzer = ScanCode(exec_path, cli=True)
     else:
         self.analyzer = Nomos(exec_path)
Ejemplo n.º 2
0
    def test_analyze(self):
        """Test whether nomos returns the expected fields data"""

        nomos = Nomos(exec_path=NOMOS_PATH)
        kwargs = {'file_path': os.path.join(self.tmp_data_path, ANALYZER_TEST_FILE)}
        result = nomos.analyze(**kwargs)

        self.assertIn('licenses', result)
Ejemplo n.º 3
0
    def test_analyze_error(self, check_output_mock):
        """Test whether an exception is thrown in case of errors"""

        check_output_mock.side_effect = subprocess.CalledProcessError(-1, "command", output=b'output')

        nomos = Nomos(exec_path=NOMOS_PATH)
        kwargs = {'file_path': os.path.join(self.tmp_data_path, ANALYZER_TEST_FILE)}
        with self.assertRaises(GraalError):
            _ = nomos.analyze(**kwargs)
Ejemplo n.º 4
0
    def test_init(self):
        """Test the analyzer is properly initialized"""

        nomos = Nomos(exec_path=NOMOS_PATH)
        self.assertEqual(nomos.exec_path, NOMOS_PATH)
        self.assertIsNotNone(nomos.search_pattern)

        with self.assertRaises(GraalError):
            _ = Nomos("/tmp/invalid")
Ejemplo n.º 5
0
class LicenseAnalyzer:
    """Class to analyse the content of files

    :param exec_path: path of the license analyzer executable
    :param kind: the analyzer kind (e.g., NOMOS, SCANCODE)
    """
    def __init__(self, exec_path, kind=NOMOS):
        if kind == SCANCODE:
            self.analyzer = ScanCode(exec_path)
        else:
            self.analyzer = Nomos(exec_path)

    def analyze(self, file_path):
        """Analyze the content of a file using Nomos

        :param file_path: file path

        :returns a dict containing the results of the analysis, like the one below
        {
          'licenses': [..]
        }
        """
        kwargs = {'file_path': file_path}
        analysis = self.analyzer.analyze(**kwargs)

        return analysis
Ejemplo n.º 6
0
class LicenseAnalyzer:
    """Class to analyse the content of files

    :param exec_path: path of the license analyzer executable
    :param kind: the analyzer kind (e.g., NOMOS, SCANCODE, SCANCODE_CLI)
    """
    def __init__(self, exec_path, kind=NOMOS):
        self.kind = kind
        if kind == SCANCODE:
            self.analyzer = ScanCode(exec_path)
        elif kind == SCANCODE_CLI:
            self.analyzer = ScanCode(exec_path, cli=True)
        else:
            self.analyzer = Nomos(exec_path)

    def analyze(self, file_path):
        """Analyze the content of a file using Nomos/Scancode

        :param file_path: file path (in case of scancode)
        :param file_paths: file paths ( in case of scancode_cli for concurrent execution on files )

        :returns a dict containing the results of the analysis, like the one below
        {
          'licenses': [..],
          'copyrights': [..]
        }
        """
        if self.kind == SCANCODE_CLI:
            kwargs = {'file_paths': file_path}
        else:
            kwargs = {'file_path': file_path}

        analysis = self.analyzer.analyze(**kwargs)

        return analysis
Ejemplo n.º 7
0
 def __init__(self, exec_path, kind=NOMOS):
     if kind == SCANCODE:
         self.analyzer = ScanCode(exec_path)
     else:
         self.analyzer = Nomos(exec_path)