Example #1
0
    def _analyze(self, commit):
        """Analyse a snapshot and the corresponding
        checkout version of the repository

        :param commit: a Perceval commit item
        """
        analysis = {}
        if self.analyzer_kind == PYREVERSE:
            module_path = os.path.join(self.worktreepath, self.entrypoint)

            if not GraalRepository.exists(module_path):
                logger.warning("module path %s does not exist at commit %s, analysis will be skipped"
                               % (module_path, commit['commit']))
                return analysis

            analysis = self.analyzer.analyze(module_path)
        else:
            for committed_file in commit['files']:
                file_path = committed_file['file']
                if self.in_paths:
                    found = [p for p in self.in_paths if file_path.endswith(p)]
                    if not found:
                        continue

                local_path = self.worktreepath + '/' + file_path
                if not GraalRepository.exists(local_path):
                    analysis.update({file_path: {DEPENDENCIES: []}})
                    continue

                dependencies = self.analyzer.analyze(local_path)
                analysis.update({file_path: dependencies})

        return analysis
    def test_exists(self):
        """Test whether the method exists works properly"""

        exists_path = os.path.join(self.tmp_path, 'existtest')

        self.assertFalse(GraalRepository.exists(exists_path))
        f = open(exists_path, 'w')
        f.close()
        self.assertTrue(GraalRepository.exists(exists_path))
Example #3
0
    def __init__(self,
                 uri,
                 git_path,
                 exec_path,
                 worktreepath=DEFAULT_WORKTREE_PATH,
                 entrypoint=None,
                 in_paths=None,
                 out_paths=None,
                 tag=None,
                 archive=None):
        super().__init__(uri,
                         git_path,
                         worktreepath,
                         entrypoint=entrypoint,
                         in_paths=in_paths,
                         out_paths=out_paths,
                         tag=tag,
                         archive=archive)

        if not GraalRepository.exists(exec_path):
            raise GraalError(cause="executable path %s not valid" % exec_path)

        self.exec_path = exec_path
        self.analyzer_kind = None
        self.analyzer = None
Example #4
0
    def _analyze(self, commit):
        """Analyse a commit and the corresponding
        checkout version of the repository

        :param commit: a Perceval commit item
        """
        analysis = []

        for committed_file in commit['files']:

            file_path = committed_file['file']
            if self.in_paths:
                found = [p for p in self.in_paths if file_path.endswith(p)]
                if not found:
                    continue

            local_path = self.worktreepath + '/' + file_path
            if not GraalRepository.exists(local_path):
                continue

            license_info = self.analyzer.analyze(local_path)
            license_info.update({'file_path': file_path})
            analysis.append(license_info)

        return analysis
Example #5
0
    def _analyze(self, commit):
        """Analyse a commit and the corresponding
        checkout version of the repository

        :param commit: a Perceval commit item
        """
        analysis = []
        files_to_process = []

        for committed_file in commit['files']:

            file_path = committed_file['file']
            if self.in_paths:
                found = [p for p in self.in_paths if file_path.endswith(p)]
                if not found:
                    continue

            local_path = self.worktreepath + '/' + file_path
            if not GraalRepository.exists(local_path):
                continue

            if self.analyzer_kind == NOMOS or self.analyzer_kind == SCANCODE:
                license_info = self.analyzer.analyze(local_path)
                license_info.update({'file_path': file_path})
                analysis.append(license_info)
            elif self.analyzer_kind == SCANCODE_CLI:
                files_to_process.append((file_path, local_path))

        if files_to_process:
            local_paths = [path[1] for path in files_to_process]
            analysis = self.analyzer.analyze(local_paths)
            for i in range(len(analysis['files'])):
                analysis['files'][i]['file_path'] = files_to_process[i][0]

        return analysis
Example #6
0
    def __init__(self, exec_path, cli=False):
        if not GraalRepository.exists(exec_path):
            raise GraalError(cause="executable path %s not valid" % exec_path)

        self.exec_path = exec_path
        self.cli = cli

        if self.cli:
            exec_path = self.exec_path.replace(SCANCODE_CLI_EXEC,
                                               CONFIGURE_EXEC)
            _ = subprocess.check_output([exec_path]).decode("utf-8")
Example #7
0
    def _analyze(self, commit):
        """Analyse a commit and the corresponding
        checkout version of the repository.

        :param commit: a Perceval commit item
        """
        analysis = []

        if self.analyzer_kind in [LIZARD_FILE, SCC_FILE]:
            for committed_file in commit['files']:

                file_path = committed_file['file']
                if self.in_paths:
                    found = [p for p in self.in_paths if file_path.endswith(p)]
                    if not found:
                        continue

                local_path = self.worktreepath + '/' + file_path
                if not GraalRepository.exists(local_path):
                    file_info = {
                        'blanks': None,
                        'comments': None,
                        'loc': None,
                        'ccn': None,
                        'avg_ccn': None,
                        'avg_loc': None,
                        'avg_tokens': None,
                        'num_funs': None,
                        'tokens': None,
                        'file_path': file_path,
                    }
                    if self.details:
                        file_info['funs'] = []

                    if committed_file.get("newfile", None):
                        file_path = committed_file["newfile"]
                        local_path = self.worktreepath + '/' + file_path
                        analysis.append(file_info)
                    elif committed_file.get("action", None) == "D":
                        analysis.append(file_info)
                        continue
                    else:
                        continue

                file_info = self.analyzer.analyze(local_path)
                file_info.update({'file_path': file_path})
                analysis.append(file_info)
        else:
            files_affected = [
                file_info['file'] for file_info in commit['files']
            ]
            analysis = self.analyzer.analyze(self.worktreepath, files_affected)

        return analysis
Example #8
0
    def _analyze(self, commit):
        """Analyse a snapshot and the corresponding
        checkout version of the repository

        :param commit: a Perceval commit item
        """
        analysis = {}
        if self.analyzer_kind in [FLAKE8, PYLINT]:
            module_path = os.path.join(self.worktreepath, self.entrypoint)

            if not GraalRepository.exists(module_path):
                logger.warning(
                    "module path %s does not exist at commit %s, analysis will be skipped"
                    % (module_path, commit['commit']))
                return {}

            analysis = self.analyzer.analyze(module_path, self.worktreepath)
        else:
            for committed_file in commit['files']:
                file_path = committed_file['file']
                if self.in_paths:
                    found = [p for p in self.in_paths if file_path.endswith(p)]
                    if not found:
                        continue

                local_path = self.worktreepath + '/' + file_path
                if not GraalRepository.exists(local_path):
                    analysis.update({file_path: {SMELLS: []}})
                    continue

                smells = self.analyzer.analyze(local_path)
                digested_smells = {
                    SMELLS: [
                        smell.replace(self.worktreepath, '')
                        for smell in smells[SMELLS]
                    ]
                }
                analysis.update({file_path: digested_smells})

        return analysis
Example #9
0
    def _analyze(self, commit):
        """Analyse a snapshot and the corresponding
        checkout version of the repository

        :param commit: a Perceval commit item
        """
        module_path = os.path.join(self.worktreepath, self.entrypoint)

        if not GraalRepository.exists(module_path):
            logger.warning("module path %s does not exist at commit %s, analysis will be skipped"
                           % (module_path, commit['commit']))
            return {}

        analysis = self.dependency_analyzer.analyze(module_path)
        return analysis
Example #10
0
    def __init__(self, exec_path, analysis):
        if not GraalRepository.exists(exec_path):
            raise GraalError(cause="executable path %s not valid" % exec_path)

        self.exec_path = exec_path
        self.analysis = analysis
Example #11
0
    def __init__(self, exec_path):
        if not GraalRepository.exists(exec_path):
            raise GraalError(cause="executable path %s not valid" % exec_path)

        self.exec_path = exec_path
        self.search_pattern = re.compile(r'license\(s\) .*$')
Example #12
0
# repository url
repo_uri = args.uri

# commit SHA
sha = '9230281aa93a593939f9dfff4a207f9e8140cb4f'

# worktree directory path
worktreepath = '/tmp/worktrees'

# path of repository cloned
repo_dir = '/tmp/repo'

print("Cloning stated..")

# Cloning the repo if it is not present
if not GraalRepository.exists(repo_dir):
    repo = GraalRepository.clone(repo_uri, repo_dir)
elif os.path.isdir(repo_dir):
    repo = GraalRepository(repo_uri, repo_dir)

# creating a new worktree if not already present
if GraalRepository.exists(worktreepath):
    shutil.rmtree(worktreepath)

repo.worktree(worktreepath)

# preforming checkout at given SHA
repo.checkout(sha)

print("cloning done")