Skip to content

Commit

Permalink
Collect installed packages for OpenWRT #2376
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Ombredanne <[email protected]>
  • Loading branch information
pombredanne committed Jan 27, 2021
1 parent 8e6a63c commit 0d2ac9c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/packagedcode/openwrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@

@attr.s()
class OpenwrtPackage(models.Package):
metafiles = ('*.control',)
# metafiles = ('*.control',)
# this is a tar.gz archive, unlike Debian which use ar archives
extensions = ('.ipk',)
filetypes = ('gzip compressed data',)
mimetypes = ('application/gzip',)
installed_db = ('/usr/lib/opkg/status',)
installed_dbs = ('/usr/lib/opkg/status',)
default_type = 'openwrt'

installed_files = List(
Expand All @@ -86,7 +86,7 @@ def recognize(cls, location):
def compute_normalized_license(self):
return compute_normalized_license(self.declared_license)

def to_dict(self, _detailed=False, **kwargs):
def to_dict(self, _detailed=True, **kwargs):
data = models.Package.to_dict(self, **kwargs)
if _detailed:
#################################################
Expand Down Expand Up @@ -162,7 +162,7 @@ def is_status_file(location, include_path=False):
)
if include_path:
posix_location = as_posixpath(location)
return has_name and posix_location.endwith('/usr/lib/opkg/status')
return has_name and posix_location.endswith('/usr/lib/opkg/status')
else:
return has_name

Expand All @@ -187,7 +187,7 @@ def parse(location):
opkg_dir = fileutils.parent_directory(location)
rootfs_dir = fileutils.parent_directory(fileutils.parent_directory(opkg_dir))
openwrt_version = get_openwrt_version(rootfs_dir)
for package in get_installed_packages(root_dir=opkg_dir, openwrt_version=openwrt_version, detect_licenses=False):
for package in get_installed_packages(opkg_dir=opkg_dir, openwrt_version=openwrt_version, detect_licenses=False):
yield package


Expand Down Expand Up @@ -217,17 +217,17 @@ def get_openwrt_version(rootfs_dir):
return


def get_installed_packages(root_dir, openwrt_version=None, detect_licenses=False, **kwargs):
def get_installed_packages(opkg_dir, openwrt_version=None, detect_licenses=False, **kwargs):
"""
Given a directory to a rootfs, yield a OpenwrtPackage for the optional
`openwrt_version` and a list of `installed_files` paths.
Given a directory to a /usr/lib/opkg dir, yield installed OpenwrtPackage (s) for the
optional `openwrt_version`.
"""

base_status_file_loc = os.path.join(root_dir, 'usr/lib/opkg/status')
base_status_file_loc = os.path.join(opkg_dir, 'status')
if not os.path.exists(base_status_file_loc):
return

usr_lib_opkg_info_dir = os.path.join(root_dir, 'us/lib/opkg/info/')
usr_lib_opkg_info_dir = os.path.join(opkg_dir, 'info')

for package in parse_status_file(base_status_file_loc, openwrt_version=openwrt_version):
package.populate_installed_files(usr_lib_opkg_info_dir)
Expand Down
4 changes: 2 additions & 2 deletions src/packagedcode/recognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ def recognize_packages(location):
recognized_packages.append(recognized)
return recognized_packages

# 3. try as as an installed db
# 3. try as an installed db
posix_location = as_posixpath(location)
if any(posix_location.endwith(idb) for idb in package_type.installed_dbs):
if any(posix_location.endswith(idb) for idb in package_type.installed_dbs):
for recognized in package_type.recognize(location):
if TRACE:logger_debug('recognize_packages: metafile matching: recognized:', recognized)
if recognized and not recognized.license_expression:
Expand Down

0 comments on commit 0d2ac9c

Please sign in to comment.