Commit 6d501411 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c4174b99
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2022 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
"""Program bom generates bill of material for a software-release or slapos node
Usage: bom software XXX
bom node <slapos deploy-script>
"""
def main():
if __name__ == '__main__':
main()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2022 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
"""Program bom generates bill of material for a software-release or slapos node
Usage: bom software <.installed.cfg>
bom node <slapos deploy-script>
"""
from __future__ import print_function
import sys, configparser, re
from os.path import basename
# bom_software retrieves BOM from .installed.cfg generated by buildout along the build.
def bom_software(installed_cfg): # -> set of 'name-version'
bom = set()
inst = configparser.ConfigParser()
inst.read(installed_cfg)
for s in inst.sections():
if s == 'buildout':
continue # [buildout] is used internally
print(s)
part = inst[s]
recipe = part['recipe']
if recipe == 'slapos.recipe.cmmi':
name, ver = namever(part['url'])
elif recipe == 'slapos.recipe.build':
# slapos.recipe.build is often used in creative ways to actually
# run python code during the build. Let's detect this via lack of
# `url`, but be careful and explicitly list name of such sections
# not to miss a normal part.
url = part.get('url', None)
if url is None:
if s == 'gcc': # [gcc] is generic section to either use system gcc, or install one via slapos
continue # the one installed via slapos will come in its own section
if s == 'python': # [python] is similar - it picks up either python2 or python3
continue
raise NotImplementedError('%s uses %s without url' % (s, recipe))
else:
name, ver = namever(url)
elif recipe == 'zc.recipe.egg:custom':
eggpath = part['__buildout_installed__']
assert len(eggpath.split()) == 1, eggpath # no spaces inside - just one item
name, ver = namever(eggpath) # XXX strip egg and py2.7-linux-x86_64
elif recipe == 'zc.recipe.egg':
# XXX
else:
raise NotImplementedError('TODO: add support for recipe %s' % recipe)
# XXX patches
print('(%s)\t%s-%s' % (s, name, ver))
def bom_node(XXX):
1/0
# namever extracts item name and version from an url/path.
# examples:
#
# http://www.python.org/ftp/python/2.7.18/Python-2.7.18.tar.xz -> ('Python', '2.7.18')
# https://git.savannah.gnu.org/gitweb/?p=config.git;a=snapshot;h=5e531d39;sf=tgz -> ('config', '5e531d39')
_gitweb_re = re.compile(r'/gitweb/\?p=(?P<name>\w+)\.git;a=snapshot;h=(?P<rev>\w+)')
def namever(url): # -> (name, ver)
m = _gitweb_re.search(url)
if m is not None:
return m.group('name'), m.group('rev')
filename = basename(url)
name, ver = filename.split('-', 1)
for tail in ('tgz', 'tar.gz', 'tbz', 'tar.bz2', 'tar.xz', 'tar.lz'):
if ver.endswith('.'+tail):
ver = ver.removesuffix('.'+tail)
return name, ver
# ----------------------------------------
def main():
if len(sys.argv) != 3 or sys.argv[1] not in ('software', 'node'):
print(__doc__, file=sys.stderr)
sys.exit(2)
kind, arg = sys.argv[1:]
if kind == 'software':
bom_software(arg)
elif kind == 'node':
bom_node(arg)
if __name__ == '__main__':
main()
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
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