MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / get_apkindex_licenses

Function get_apkindex_licenses

src/packagedcode/alpine.py:1759–1798  ·  view source on GitHub ↗
(locin, locout)

Source from the content-addressed store, hash-verified

1757 import sys
1758
1759 def get_apkindex_licenses(locin, locout):
1760 from collections import defaultdict
1761 from commoncode.fileutils import resource_iter
1762
1763 def collect_licenses_from_index(location):
1764 """
1765 Return packages_by_licenses with all licenses from apkindex found in the location tree
1766 """
1767 packages_by_licenses = defaultdict(list)
1768 for apkindex_loc in resource_iter(location, with_dirs=False):
1769 if not apkindex_loc.endswith('APKINDEX'):
1770 continue
1771 """
1772 >>> a='/home/pombreda/tmp/alpine-indexes/apkindex-archive-master/alpine/v3.12/community/aarch64/APKINDEX'
1773 >>> '-'.join(a.split('/')[-4:])
1774 'v3.12-community-aarch64-APKINDEX'
1775 >>> '-'.join(a.split('/')[-4:-1])
1776 'v3.12-community-aarch64'
1777 """
1778 apkidx_id = '-'.join(apkindex_loc.split('/')[-4:-1])
1779 print(f'Processing: {apkindex_loc}')
1780 for package in parse_alpine_installed_db(apkindex_loc):
1781 if not package:
1782 continue
1783 purl = package.purl
1784 declared = ' '.join(package.declared_license.lower().split())
1785 packages_by_licenses[declared].append((apkidx_id, purl,))
1786 return packages_by_licenses
1787
1788 with open(locout, 'w') as output:
1789 line = '\t'.join(['declared_license', 'purl', 'distro', 'unique']) + '\n'
1790 output.write(line)
1791 for declared, packages in sorted(collect_licenses_from_index(locin).items()):
1792 if len(packages) == 1:
1793 unique = 'yes'
1794 else:
1795 unique = 'no'
1796 pidx, purl = packages[0]
1797 line = '\t'.join([declared, purl, pidx, unique]) + '\n'
1798 output.write(line)
1799
1800 def get_apkbuild_licenses(locin, locout):
1801 from collections import defaultdict

Callers

nothing calls this directly

Calls 3

joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected