Skip to content

Commit 0db6803

Browse files
committed
Add new handler for etc/os-release files
* Add new dependency on container-inspector * Also cleanup and sync setup files Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 2cd448c commit 0db6803

File tree

3 files changed

+73
-7
lines changed

3 files changed

+73
-7
lines changed

setup-mini.cfg

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ install_requires =
6969
chardet >= 3.0.0
7070
click >= 6.7, !=7.0
7171
colorama >= 0.3.9
72-
commoncode >= 30.0.0
72+
commoncode >= 30.1.1
73+
container-inspector >= 30.0.0
7374
debian-inspector >= 30.0.0
7475
dparse2 >= 0.6.0
7576
fasteners
@@ -175,14 +176,13 @@ scancode_scan =
175176
# module for details and doc.
176177
scancode_post_scan =
177178
summary = summarycode.summarizer:ScanSummary
178-
summary2 = summarycode.summarizer2:ScanSummary
179-
summary-keeping-details = summarycode.summarizer:ScanSummaryWithDetails
180-
summary-key-files = summarycode.summarizer:ScanKeyFilesSummary
181-
summary-by-facet = summarycode.summarizer:ScanByFacetSummary
179+
tallies = summarycode.tallies:Tallies
180+
tallies-with-details = summarycode.tallies:TalliesWithDetails
181+
tallies-key-files = summarycode.tallies:KeyFilesTallies
182+
tallies-by-facet = summarycode.tallies:FacetTallies
182183
license-clarity-score = summarycode.score:LicenseClarityScore
183184
license-policy = licensedcode.plugin_license_policy:LicensePolicy
184185
mark-source = scancode.plugin_mark_source:MarkSource
185-
classify-package = summarycode.classify:PackageTopAndKeyFilesTagger
186186
is-license-text = licensedcode.plugin_license_text:IsLicenseText
187187
filter-clues = cluecode.plugin_filter_clues:RedundantCluesFilter
188188
consolidate = summarycode.plugin_consolidate:Consolidator

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ install_requires =
7070
click >= 6.7, !=7.0
7171
colorama >= 0.3.9
7272
commoncode >= 30.1.1
73+
container-inspector >= 30.0.0
7374
debian-inspector >= 30.0.0
7475
dparse2 >= 0.6.0
7576
fasteners
@@ -184,7 +185,6 @@ scancode_post_scan =
184185
license-clarity-score = summarycode.score:LicenseClarityScore
185186
license-policy = licensedcode.plugin_license_policy:LicensePolicy
186187
mark-source = scancode.plugin_mark_source:MarkSource
187-
classify-package = summarycode.classify:PackageTopAndKeyFilesTagger
188188
is-license-text = licensedcode.plugin_license_text:IsLicenseText
189189
filter-clues = cluecode.plugin_filter_clues:RedundantCluesFilter
190190
consolidate = summarycode.plugin_consolidate:Consolidator

src/packagedcode/distro.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# ScanCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/nexB/scancode-toolkit for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
10+
from container_inspector.distro import Distro
11+
12+
from packagedcode import models
13+
from packagedcode import utils
14+
15+
"""
16+
Check for files to determine the Linux distro or operating system of a codebase.
17+
"""
18+
19+
20+
class EtcOsReleaseHandler(models.NonAssemblableDatafileHandler):
21+
datasource_id = 'etc_os_release'
22+
default_package_type = 'linux-distro'
23+
path_patterns = ('*etc/os-release', '*usr/lib/os-release',)
24+
description = 'Linux OS release metadata file'
25+
documentation_url = 'https://www.freedesktop.org/software/systemd/man/os-release.html'
26+
27+
@classmethod
28+
def parse(cls, location):
29+
distro = Distro.from_os_release_file(location)
30+
distro_identifier = distro.identifier
31+
pretty_name = distro.pretty_name and distro.pretty_name.lower() or ''
32+
33+
if distro_identifier == 'debian':
34+
namespace = 'debian'
35+
36+
if 'distroless' in pretty_name:
37+
name = 'distroless'
38+
elif pretty_name.startswith('debian'):
39+
name = 'distroless'
40+
41+
elif distro_identifier == 'ubuntu' and distro.id_like == 'debian':
42+
namespace = 'debian'
43+
name = 'ubuntu'
44+
else:
45+
namespace = distro_identifier
46+
name = 'ubuntu'
47+
48+
version = distro.version_id
49+
50+
yield models.PackageData(
51+
datasource_id=cls.datasource_id,
52+
type=cls.default_package_type,
53+
namespace=namespace,
54+
name=name,
55+
version=version,
56+
)
57+
58+
@classmethod
59+
def find_linux_rootfs_root_resource(cls, resource, codebase):
60+
"""
61+
Given a ``codebase`` ``resource`` for an "os-release" file, return the
62+
resource for the root directory of this filesystem or None.
63+
"""
64+
paths = ('etc/os-release', 'usr/lib/os-release',)
65+
return utils.find_root_from_paths(paths, resource, codebase)
66+

0 commit comments

Comments
 (0)