Commit 351a58d2 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent d0540ad3
......@@ -31,7 +31,7 @@ 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
from os.path import basename, isdir
from glob import glob
from collections import namedtuple
from urllib.parse import unquote
......@@ -53,6 +53,7 @@ PkgInfo = namedtuple('PkgInfo', [
def bom_software(installed_software_path): # -> {} (name,kind) -> PkgInfo
bom = {}
def addbom(urlpath, kind, version=None):
#print('addbom', urlpath)
license = None # XXX temp
name, ver = namever(urlpath)
if version is not None:
......@@ -84,15 +85,27 @@ def bom_software(installed_software_path): # -> {} (name,kind) -> PkgInfo
else:
url = 'https://pypi.org/project/%s/%s/' % (name, v)
with open('%s/EGG-INFO/PKG-INFO' % urlpath) as f:
p = email.parser.Parser()
meta = p.parse(f, headersonly=True)
license = meta['license']
if isdir(urlpath):
with open('%s/EGG-INFO/PKG-INFO' % urlpath) as f:
p = email.parser.Parser()
meta = p.parse(f, headersonly=True)
license = meta['license']
else:
# TODO unzip (e.g. setuptools)
pass
else:
raise NotImplementedError('TODO url for kind %r (urlpath: %r)' % (kind, urlpath))
if license is None: # XXX temp
license = '?'
license = 'xxx'
# XXX "UNKNOWN" not ok
#license = spdx_license_canon(license)
# XXX Eclipse Public License -> EPL (SPDX)
# 3-clause BSD -> BSD-3 ? (SPDX)
# Apache License, Version 2.0
# GPLv3+ with wide exception for FOSS -> GPL3+-with-nxdexcept ?
# BSD-like ? (Chameleon)
info = PkgInfo(name, ver, kind, url, license)
bkey = (name, kind)
if bkey in bom:
......@@ -208,19 +221,18 @@ def bom_software(installed_software_path): # -> {} (name,kind) -> PkgInfo
# when no scripts are installed at all, but is better than nothing.
# An alternative is to fix zc.recipe.egg itself to emit information
# about all eggs it installs:
xeggs = {} # xeggname -> xeggname-ver-....egg on the filesystem
xeggs = {} # xeggname -> /path/to/xeggname-ver-....egg on the filesystem
installedv = part['__buildout_installed__'].split()
for f in installedv:
for xeggpath in eggscript_imports(f):
if not xeggpath.endswith('.egg'):
continue # e.g. neoppod-repository, *.egg-link
xeggfile = basename(xeggpath)
xegg, _ = namever(xeggfile)
xegg, _ = namever(xeggpath)
if xegg in xeggs:
assert xeggs[xegg] == xeggfile, (xeggs[xegg], xeggfile)
assert xeggs[xegg] == xeggpath, (xeggs[xegg], xeggpath)
else:
xeggs[xegg] = xeggfile
addbom(xeggfile, 'egg')
xeggs[xegg] = xeggpath
addbom(xeggpath, 'egg')
# now go through explicitly listed eggs and also add them
# XXX sadly zc.recipe.egg neither saves in .installed.cfg information about where the eggs are installed,
......@@ -244,9 +256,9 @@ def bom_software(installed_software_path): # -> {} (name,kind) -> PkgInfo
if glob('%s/%s.egg-link' % (eggdev, eggname)):
continue # e.g. wendelin.core.egg-link points to wendelin.core cloned via git and already reported as git
installed_eggs = [basename(_) for _ in (glob('%s/*.egg' % eggdir) +
glob('%s/*.egg' % eggdev))]
eggv = [_ for _ in installed_eggs if _.lower().startswith('%s-' % eggname)]
installed_eggs = glob('%s/*.egg' % eggdir) + \
glob('%s/*.egg' % eggdev)
eggv = [_ for _ in installed_eggs if basename(_).lower().startswith('%s-' % eggname)]
if len(eggv) == 0:
raise ValueError('egg %s not found' % eggname)
if len(eggv) > 1:
......
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