Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nxd-bom
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
nxd-bom
Commits
351a58d2
Commit
351a58d2
authored
Jun 12, 2023
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
d0540ad3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
15 deletions
+27
-15
nxdbom/__init__.py
nxdbom/__init__.py
+27
-15
No files found.
nxdbom/__init__.py
View file @
351a58d2
...
...
@@ -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
]
==
xegg
file
,
(
xeggs
[
xegg
],
xeggfile
)
assert
xeggs
[
xegg
]
==
xegg
path
,
(
xeggs
[
xegg
],
xeggpath
)
else
:
xeggs
[
xegg
]
=
xegg
file
addbom
(
xegg
file
,
'egg'
)
xeggs
[
xegg
]
=
xegg
path
addbom
(
xegg
path
,
'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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment