Skip to content

Commit

Permalink
Handle package_uids for DiscoveredPackages #411
Browse files Browse the repository at this point in the history
    * Remove create_discovered_packages2 and create_codebase_resources2

Signed-off-by: Jono Yang <jyang@nexb.com>
  • Loading branch information
JonoYang committed May 6, 2022
1 parent 1957ab8 commit b406ac0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions scanpipe/pipelines/scan_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def build_inventory_from_scan(self):
"""
project = self.project
scanned_codebase = scancode.get_virtual_codebase(project, str(self.scan_output))
scancode.create_discovered_packages2(project, scanned_codebase)
scancode.create_codebase_resources2(project, scanned_codebase)
scancode.create_discovered_packages(project, scanned_codebase)
scancode.create_codebase_resources(project, scanned_codebase)

def make_summary_from_scan_results(self):
"""
Expand Down
7 changes: 7 additions & 0 deletions scanpipe/pipes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ def update_or_create_package(project, package_data, codebase_resource=None):
else:
package = DiscoveredPackage.create_from_data(project, package_data)

# Update package_uids list in package.extra_data
package_uid = package_data.get("package_uid")
if package_uid:
package_uids = package.extra_data.get("package_uids", [])
package_uids.append(package_uid)
package.update_extra_data({"package_uids": package_uids})

return package


Expand Down
12 changes: 4 additions & 8 deletions scanpipe/pipes/scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@
from django.apps import apps
from django.conf import settings

import packagedcode
from commoncode import fileutils
from commoncode.resource import VirtualCodebase
from extractcode import api as extractcode_api
from packagedcode.models import PackageData
from packageurl import PackageURL
from scancode import ScancodeError
from scancode import Scanner
from scancode import api as scancode_api
Expand Down Expand Up @@ -392,11 +389,10 @@ def create_codebase_resources(project, scanned_codebase):
)

# associate DiscoveredPackage to Resource, if applicable
for purl_uid in scanned_resource.for_packages:
purl = PackageURL.from_string(purl_uid)
# TODO: take package_uid qualifier into consideration
package = DiscoveredPackage.objects.filter(type=purl.type, name=purl.name, version=purl.version)
package = package[0]
for package_uid in scanned_resource.for_packages:
package = DiscoveredPackage.objects.get(
extra_data__contains={"package_uids": [package_uid]}
)
set_codebase_resource_for_package(
codebase_resource=cbr, discovered_package=package
)
Expand Down

0 comments on commit b406ac0

Please sign in to comment.