Commit a14348e6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 56539a3b
......@@ -30,13 +30,15 @@ An example of generated bill of material is provided in example/ors-bom.txt .
from __future__ import print_function
import sys, configparser, re, codecs
from os.path import basename, isdir
import sys, os, configparser, re, codecs
from os.path import basename, isdir, exists
from glob import glob
from collections import namedtuple
from urllib.parse import unquote
from urllib.request import urlretrieve
import email.parser
import zipfile
import shutil
# PkgInfo represents information about a package
......@@ -69,6 +71,7 @@ def bom_software(installed_software_path): # -> {} (name,kind) -> PkgInfo
ver = removeprefix(ver, name+'-') # wendelin.core-2.0.alpha3-0-g6315384 -> 2.0.alpha3-0-g6315384
if '//' in urlpath:
url = urlpath
license = license_of(url)
else:
if kind == 'egg':
# XXX not strictly correct -> better retrieve the actual URL, but buildout does not save it in installed.cfg
......@@ -542,6 +545,41 @@ def spdx_license_canon(license_name):
return spdx
# license_of returns license of package at url.
def license_of(url):
assert '//' in url, url
_, xpath = url.split('//', 1) # https://tukaani.org/xz/xz-5.2.5.tar.bz2 -> tukaani.org/xz/xz-5.2.5.tar.bz
assert '//' not in xpath, xpath
assert '..' not in xpath, xpath
xpath = '.CACHE/src/'+xpath
if not exists(xpath):
# download + unpack -> xpath
print('DL %s ...' % url, file=sys.stderr)
mkdir_p('.CACHE/pkg')
pkgfile = '.CACHE/pkg/' + basename(xpath)
urlretrieve(url, pkgfile)
shutil.unpack_archive(pkgfile, xpath)
# XXX
return None
# XXX temp hack: disable ipv6
# https://stackoverflow.com/a/6319043/9456786
import socket
origGetAddrInfo = socket.getaddrinfo
def getAddrInfoWrapper(host, port, family=0, socktype=0, proto=0, flags=0):
return origGetAddrInfo(host, port, socket.AF_INET, socktype, proto, flags)
# replace the original socket.getaddrinfo by our version
socket.getaddrinfo = getAddrInfoWrapper
def mkdir_p(path):
os.makedirs(path, exist_ok=True)
# ----------------------------------------
# fmt_bom formats BOM into text.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment