Skip to content

Commit

Permalink
Fix namespace assignment from distro ID
Browse files Browse the repository at this point in the history
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
  • Loading branch information
AyanSinhaMahapatra committed May 8, 2024
1 parent 8797c9f commit 4c9e044
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 34 deletions.
30 changes: 20 additions & 10 deletions src/packagedcode/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,34 @@ class EtcOsReleaseHandler(models.NonAssemblableDatafileHandler):
@classmethod
def parse(cls, location, package_only=False):
distro = Distro.from_os_release_file(location)
distro_identifier = distro.identifier
distro_identifier = None
if distro:
distro_identifier = distro.identifier

if not distro_identifier:
return

pretty_name = distro.pretty_name and distro.pretty_name.lower() or ''

# TODO: It is misleading to use package data fields
# name and namespace to store distro/os infomration,
# we should consider using extra_data fields instead.

if distro_identifier == 'debian':
namespace = 'debian'
name = 'debian'

if 'distroless' in pretty_name:
name = 'distroless'
elif pretty_name.startswith('debian'):
name = 'distroless'
namespace = 'distroless'
else:
namespace = 'debian'

elif distro_identifier == 'ubuntu' and distro.id_like == 'debian':
namespace = 'debian'
name = 'ubuntu'
namespace = 'ubuntu'
name = 'debian'

elif distro_identifier.startswith('fedora') or distro.id_like == 'fedora':
namespace = distro_identifier
name = distro.id_like or distro_identifier
elif distro_identifier.startswith('fedora') or distro.id_like == 'fedora':
name = distro_identifier or distro.id_like
namespace = distro.id_like

else:
# FIXME: this needs to be seriously updated
Expand Down
2 changes: 1 addition & 1 deletion src/packagedcode/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ def get_distro_identifier_rootfs(cls, root_resource, codebase):
# there can be only one distro
distro = os_release_res.package_data and os_release_res.package_data[0]
if distro:
identifier = distro.get("name")
identifier = distro.get("namespace")
break

return identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@
"package_data": [
{
"type": "linux-distro",
"namespace": "debian",
"name": "ubuntu",
"namespace": "ubuntu",
"name": "debian",
"version": "22.04",
"qualifiers": {},
"subpath": null,
Expand Down Expand Up @@ -393,7 +393,7 @@
"repository_download_url": null,
"api_data_url": null,
"datasource_id": "etc_os_release",
"purl": "pkg:linux-distro/debian/[email protected]"
"purl": "pkg:linux-distro/ubuntu/debian@22.04"
}
],
"for_packages": [],
Expand Down
34 changes: 17 additions & 17 deletions tests/packagedcode/data/plugin/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,41 @@ Package type: about
description: AboutCode ABOUT file
path_patterns: '*.ABOUT'
--------------------------------------------
Package type: alpine
Package type: android
datasource_id: android_apk
documentation URL: https://en.wikipedia.org/wiki/Apk_(file_format)
primary language: Java
description: Android application package
path_patterns: '*.apk'
--------------------------------------------
Package type: android_lib
datasource_id: android_aar_library
documentation URL: https://developer.android.com/studio/projects/android-library
primary language: Java
description: Android library archive
path_patterns: '*.aar'
--------------------------------------------
Package type: apk
datasource_id: alpine_apk_archive
documentation URL: https://wiki.alpinelinux.org/wiki/Alpine_package_format
primary language: None
description: Alpine Linux .apk package archive
path_patterns: '*.apk'
--------------------------------------------
Package type: alpine
Package type: apk
datasource_id: alpine_apkbuild
documentation URL: https://wiki.alpinelinux.org/wiki/APKBUILD_Reference
primary language: None
description: Alpine Linux APKBUILD package script
path_patterns: '*APKBUILD'
--------------------------------------------
Package type: alpine
Package type: apk
datasource_id: alpine_installed_db
documentation URL: None
primary language: None
description: Alpine Linux installed package database
path_patterns: '*lib/apk/db/installed'
--------------------------------------------
Package type: android
datasource_id: android_apk
documentation URL: https://en.wikipedia.org/wiki/Apk_(file_format)
primary language: Java
description: Android application package
path_patterns: '*.apk'
--------------------------------------------
Package type: android_lib
datasource_id: android_aar_library
documentation URL: https://developer.android.com/studio/projects/android-library
primary language: Java
description: Android library archive
path_patterns: '*.aar'
--------------------------------------------
Package type: autotools
datasource_id: autotools_configure
documentation URL: https://www.gnu.org/software/automake/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203694,8 +203694,8 @@
"package_data": [
{
"type": "linux-distro",
"namespace": "fedora-modular",
"name": "fedora",
"namespace": "fedora",
"name": "fedora-modular",
"version": "26",
"qualifiers": {},
"subpath": null,
Expand Down Expand Up @@ -203732,7 +203732,7 @@
"repository_download_url": null,
"api_data_url": null,
"datasource_id": "etc_os_release",
"purl": "pkg:linux-distro/fedora-modular/fedora@26"
"purl": "pkg:linux-distro/fedora/fedora-modular@26"
}
],
"for_packages": [
Expand Down

0 comments on commit 4c9e044

Please sign in to comment.