コード例 #1
0
 def _transform_licenses(self):
     if self._raw_data.get('LicenseUrl'):
         from f8a_worker.process import IndianaJones  # download_file
         # It's here due to circular dependencies
         from f8a_worker.workers import LicenseCheckTask  # run_scancode
         self._data['declared_licenses'] = [self._raw_data['LicenseUrl']]
         with TemporaryDirectory() as tmpdir:
             try:
                 # Get file from 'LicenseUrl' and let LicenseCheckTask decide what license it is
                 if IndianaJones.download_file(self._raw_data['LicenseUrl'],
                                               tmpdir):
                     scancode_results = LicenseCheckTask.run_scancode(
                         tmpdir)
                     if scancode_results.get('summary',
                                             {}).get('sure_licenses'):
                         self._data['declared_licenses'] = \
                             scancode_results['summary']['sure_licenses']
             except Exception:
                 # Don't raise if IndianaJones or LicenseCheckTask fail
                 pass
コード例 #2
0
    def _handle_dotnet_solution(self, data):
        """Handle nuget package metadata."""
        # TODO: reduce cyclomatic complexity
        if not data.get('Metadata'):
            return {}
        data = data['Metadata']
        key_map = (
            ('Id', 'name'),
            ('Description', ),
            ('ProjectUrl', 'homepage'),
            # ('Summary',), ('Copyright',),
            # ('RequireLicenseAcceptance', 'require_license_acceptance'),
        )
        transformed = self.transform_keys(data, key_map)

        if data.get('Authors'):
            transformed['author'] = ','.join(data['Authors'])

        if data.get('LicenseUrl'):
            from f8a_worker.process import IndianaJones  # download_file
            # It's here due to circular dependencies
            from f8a_worker.workers import LicenseCheckTask  # run_scancode
            transformed['declared_licenses'] = [data['LicenseUrl']]
            with TemporaryDirectory() as tmpdir:
                try:
                    # Get file from 'LicenseUrl' and let LicenseCheckTask decide what license it is
                    if IndianaJones.download_file(data['LicenseUrl'], tmpdir):
                        scancode_results = LicenseCheckTask.run_scancode(
                            tmpdir)
                        if scancode_results.get('summary',
                                                {}).get('sure_licenses'):
                            transformed['declared_licenses'] = \
                                scancode_results['summary']['sure_licenses']
                except Exception:
                    # Don't raise if IndianaJones or LicenseCheckTask fail
                    pass

        # transform
        # "DependencyGroups": [
        #    {
        #        "Packages": [
        #            {
        #                "Id": "NETStandard.Library",
        #                "VersionRange": {"OriginalString": "1.6.0"}
        #            }
        #        ]
        #    }
        # ]
        # to ["NETStandard.Library 1.6.0"]
        deps = set()
        for dep_group in data.get('DependencyGroups', []):
            for package in dep_group.get('Packages', []):
                deps.add('{} {}'.format(
                    package.get('Id', ''),
                    package.get('VersionRange', {}).get('OriginalString', '')))
        if deps:
            transformed['dependencies'] = list(deps)

        repository = data.get('Repository')
        if isinstance(repository, dict) and repository:
            transformed['code_repository'] = {
                'type': repository.get('Type'),
                'url': repository.get('Url')
            }
        elif 'ProjectUrl' in data:
            transformed['code_repository'] = self._identify_gh_repo(
                data['ProjectUrl'])

        version = data.get('Version')
        if isinstance(version, dict) and version:
            transformed['version'] = '{}.{}.{}'.format(
                version.get('Major', ''), version.get('Minor', ''),
                version.get('Patch', ''))

        if data.get('Tags'):
            transformed['keywords'] = self._split_keywords(data['Tags'])

        return transformed