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 . ...@@ -31,7 +31,7 @@ An example of generated bill of material is provided in example/ors-bom.txt .
from __future__ import print_function from __future__ import print_function
import sys, configparser, re, codecs import sys, configparser, re, codecs
from os.path import basename from os.path import basename, isdir
from glob import glob from glob import glob
from collections import namedtuple from collections import namedtuple
from urllib.parse import unquote from urllib.parse import unquote
...@@ -53,6 +53,7 @@ PkgInfo = namedtuple('PkgInfo', [ ...@@ -53,6 +53,7 @@ PkgInfo = namedtuple('PkgInfo', [
def bom_software(installed_software_path): # -> {} (name,kind) -> PkgInfo def bom_software(installed_software_path): # -> {} (name,kind) -> PkgInfo
bom = {} bom = {}
def addbom(urlpath, kind, version=None): def addbom(urlpath, kind, version=None):
#print('addbom', urlpath)
license = None # XXX temp license = None # XXX temp
name, ver = namever(urlpath) name, ver = namever(urlpath)
if version is not None: if version is not None:
...@@ -84,15 +85,27 @@ def bom_software(installed_software_path): # -> {} (name,kind) -> PkgInfo ...@@ -84,15 +85,27 @@ def bom_software(installed_software_path): # -> {} (name,kind) -> PkgInfo
else: else:
url = 'https://pypi.org/project/%s/%s/' % (name, v) url = 'https://pypi.org/project/%s/%s/' % (name, v)
with open('%s/EGG-INFO/PKG-INFO' % urlpath) as f: if isdir(urlpath):
p = email.parser.Parser() with open('%s/EGG-INFO/PKG-INFO' % urlpath) as f:
meta = p.parse(f, headersonly=True) p = email.parser.Parser()
license = meta['license'] meta = p.parse(f, headersonly=True)
license = meta['license']
else:
# TODO unzip (e.g. setuptools)
pass
else: else:
raise NotImplementedError('TODO url for kind %r (urlpath: %r)' % (kind, urlpath)) raise NotImplementedError('TODO url for kind %r (urlpath: %r)' % (kind, urlpath))
if license is None: # XXX temp 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) info = PkgInfo(name, ver, kind, url, license)
bkey = (name, kind) bkey = (name, kind)
if bkey in bom: if bkey in bom:
...@@ -208,19 +221,18 @@ def bom_software(installed_software_path): # -> {} (name,kind) -> PkgInfo ...@@ -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. # when no scripts are installed at all, but is better than nothing.
# An alternative is to fix zc.recipe.egg itself to emit information # An alternative is to fix zc.recipe.egg itself to emit information
# about all eggs it installs: # 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() installedv = part['__buildout_installed__'].split()
for f in installedv: for f in installedv:
for xeggpath in eggscript_imports(f): for xeggpath in eggscript_imports(f):
if not xeggpath.endswith('.egg'): if not xeggpath.endswith('.egg'):
continue # e.g. neoppod-repository, *.egg-link continue # e.g. neoppod-repository, *.egg-link
xeggfile = basename(xeggpath) xegg, _ = namever(xeggpath)
xegg, _ = namever(xeggfile)
if xegg in xeggs: if xegg in xeggs:
assert xeggs[xegg] == xeggfile, (xeggs[xegg], xeggfile) assert xeggs[xegg] == xeggpath, (xeggs[xegg], xeggpath)
else: else:
xeggs[xegg] = xeggfile xeggs[xegg] = xeggpath
addbom(xeggfile, 'egg') addbom(xeggpath, 'egg')
# now go through explicitly listed eggs and also add them # 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, # 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 ...@@ -244,9 +256,9 @@ def bom_software(installed_software_path): # -> {} (name,kind) -> PkgInfo
if glob('%s/%s.egg-link' % (eggdev, eggname)): 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 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) + installed_eggs = glob('%s/*.egg' % eggdir) + \
glob('%s/*.egg' % eggdev))] glob('%s/*.egg' % eggdev)
eggv = [_ for _ in installed_eggs if _.lower().startswith('%s-' % eggname)] eggv = [_ for _ in installed_eggs if basename(_).lower().startswith('%s-' % eggname)]
if len(eggv) == 0: if len(eggv) == 0:
raise ValueError('egg %s not found' % eggname) raise ValueError('egg %s not found' % eggname)
if len(eggv) > 1: 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