(locin, locout)
| 1798 | output.write(line) |
| 1799 | |
| 1800 | def get_apkbuild_licenses(locin, locout): |
| 1801 | from collections import defaultdict |
| 1802 | from commoncode.fileutils import resource_iter |
| 1803 | |
| 1804 | def collect_licenses_from_apkbuilds(location): |
| 1805 | """ |
| 1806 | Return packages_by_licenses with all licenses from apkbuild found in |
| 1807 | the location tree |
| 1808 | """ |
| 1809 | packages_by_licenses = defaultdict(list) |
| 1810 | for apkbuild_loc in resource_iter(location, with_dirs=False): |
| 1811 | """ |
| 1812 | >>> a='/home/pombreda/tmp/alpine-indexes/apkindex-archive-master/alpine/v3.12/community/aarch64/APKINDEX' |
| 1813 | >>> '-'.join(a.split('/')[-4:]) |
| 1814 | 'v3.12-community-aarch64-APKINDEX' |
| 1815 | >>> '-'.join(a.split('/')[-4:-1]) |
| 1816 | 'v3.12-community-aarch64' |
| 1817 | """ |
| 1818 | apkidx_id = '-'.join(apkbuild_loc.split('/')[-4:-1]) |
| 1819 | print(f'Processing: {apkbuild_loc}') |
| 1820 | package = parse_apkbuild(apkbuild_loc) |
| 1821 | if not package: |
| 1822 | continue |
| 1823 | purl = package.purl |
| 1824 | declic = ' '.join(package.declared_license.split()) |
| 1825 | packages_by_licenses[declic].append((apkidx_id, purl,)) |
| 1826 | return packages_by_licenses |
| 1827 | |
| 1828 | with open(locout, 'w') as output: |
| 1829 | line = '\t'.join(['declared', 'purl', 'distro', 'unique']) + '\n' |
| 1830 | output.write(line) |
| 1831 | for declared, packages in sorted(collect_licenses_from_apkbuilds(locin).items()): |
| 1832 | if len(packages) == 1: |
| 1833 | unique = 'yes' |
| 1834 | else: |
| 1835 | unique = 'no' |
| 1836 | pidx, purl = packages[0] |
| 1837 | line = '\t'.join([declared, purl, pidx, unique]) + '\n' |
| 1838 | output.write(line) |
| 1839 | |
| 1840 | def detect_licenses(locin, locout): |
| 1841 | """ |
no test coverage detected