mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 03:53:32 +01:00
build.cmds.BaseCmdPkgRelations: Add Module
For requires, provides and conflicts, isolate the bulk of the code in BaseCmdPkgRelations, then derive CmdPkgConflicts, CmdPkgProvides and CmdPkgRequires from that class. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
31537a0bd6
commit
2a67708fb1
5 changed files with 111 additions and 117 deletions
|
|
@ -306,92 +306,6 @@ class App(object):
|
||||||
r.append(m)
|
r.append(m)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def pkg_relations_add_arguments(self, parser: argparse.ArgumentParser) -> None:
|
|
||||||
parser.add_argument('-S', '--subsections', nargs='?', default=None, help='Subsections to consider, comma-separated')
|
|
||||||
parser.add_argument('-d', '--delimiter', nargs='?', default=', ', help='Output words delimiter')
|
|
||||||
parser.add_argument('flavour', help='Flavour')
|
|
||||||
parser.add_argument('module', nargs='*', help='Modules')
|
|
||||||
parser.add_argument('-p', '--no-subpackages', action='store_true',
|
|
||||||
default=False, help='Cut -run and -devel from package names')
|
|
||||||
parser.add_argument('--no-version', action='store_true',
|
|
||||||
default=False, help='Don\'t report version information')
|
|
||||||
parser.add_argument('--dont-strip-revision', action='store_true',
|
|
||||||
default=False, help='Always treat VERSION macro as VERSION-REVISION')
|
|
||||||
parser.add_argument('--recursive', action='store_true',
|
|
||||||
default=False, help='Find dependencies recursively')
|
|
||||||
parser.add_argument('--dont-expand-version-macros', action='store_true',
|
|
||||||
default=False, help='Don\'t expand VERSION and REVISION macros')
|
|
||||||
parser.add_argument('--ignore', nargs='?', default='', help='Packages that '
|
|
||||||
'should be ignored together with their dependencies')
|
|
||||||
|
|
||||||
def pkg_relations(self, rel_type, args):
|
|
||||||
version_pattern=re.compile("[0-9-.]*")
|
|
||||||
if args.subsections is None:
|
|
||||||
subsecs = self.os_cascade()
|
|
||||||
subsecs.append('jw')
|
|
||||||
else:
|
|
||||||
subsecs = args.subsections.split(',')
|
|
||||||
self.debug('flavour = ', args.flavour, ', subsecs = ', ' '.join(subsecs))
|
|
||||||
ignore = args.ignore.split(',')
|
|
||||||
self.debug("ignore = ", ignore)
|
|
||||||
|
|
||||||
r = []
|
|
||||||
flavours = args.flavour.split(',')
|
|
||||||
for flavour in flavours:
|
|
||||||
for s in subsecs:
|
|
||||||
section = 'pkg.' + rel_type + '.' + s
|
|
||||||
visited = set()
|
|
||||||
modules = args.module.copy()
|
|
||||||
while len(modules):
|
|
||||||
m = modules.pop(0)
|
|
||||||
if m in visited or m in ignore:
|
|
||||||
continue
|
|
||||||
visited.add(m)
|
|
||||||
value = self.get_value(m, section, flavour)
|
|
||||||
if not value:
|
|
||||||
continue
|
|
||||||
deps = value.split(',')
|
|
||||||
for spec in deps:
|
|
||||||
dep = re.split('([=><]+)', spec)
|
|
||||||
if args.no_version:
|
|
||||||
dep = dep[:1]
|
|
||||||
dep = list(map(str.strip, dep))
|
|
||||||
dep_name = re.sub('-dev$|-devel$|-run$', '', dep[0])
|
|
||||||
if dep_name in ignore or dep[0] in ignore:
|
|
||||||
continue
|
|
||||||
if args.no_subpackages:
|
|
||||||
dep[0] = dep_name
|
|
||||||
for i, item in enumerate(dep):
|
|
||||||
dep[i] = item.strip()
|
|
||||||
if s == 'jw':
|
|
||||||
if args.recursive and not dep_name in visited and not dep_name in modules:
|
|
||||||
modules.append(dep_name)
|
|
||||||
if len(dep) == 3:
|
|
||||||
if args.dont_expand_version_macros and dep_name in args.module:
|
|
||||||
version = dep[2]
|
|
||||||
else:
|
|
||||||
version = self.get_value(dep_name, 'version', '')
|
|
||||||
if dep[2] == 'VERSION':
|
|
||||||
if args.dont_strip_revision:
|
|
||||||
dep[2] = version
|
|
||||||
else:
|
|
||||||
dep[2] = version.split('-')[0]
|
|
||||||
elif dep[2] == 'VERSION-REVISION':
|
|
||||||
dep[2] = version
|
|
||||||
elif version_pattern.match(dep[2]):
|
|
||||||
# dep[2] = dep[2]
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise Exception("Unknown version specifier in " + spec)
|
|
||||||
cleaned_dep = ' '.join(dep)
|
|
||||||
if not cleaned_dep in r:
|
|
||||||
self.debug("appending", cleaned_dep)
|
|
||||||
r.append(cleaned_dep)
|
|
||||||
return args.delimiter.join(r)
|
|
||||||
|
|
||||||
def print_pkg_relations(self, rel_type, args_):
|
|
||||||
print(self.pkg_relations(rel_type, args_))
|
|
||||||
|
|
||||||
def get_libname(self, names):
|
def get_libname(self, names):
|
||||||
vals = self.get_modules_from_project_txt(names, ['build'], 'libname',
|
vals = self.get_modules_from_project_txt(names, ['build'], 'libname',
|
||||||
scope = 1, add_self=False, names_only=True)
|
scope = 1, add_self=False, names_only=True)
|
||||||
|
|
|
||||||
102
src/python/jw/build/cmds/BaseCmdPkgRelations.py
Normal file
102
src/python/jw/build/cmds/BaseCmdPkgRelations.py
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import re
|
||||||
|
from argparse import Namespace, ArgumentParser
|
||||||
|
|
||||||
|
from ..Cmd import Cmd
|
||||||
|
|
||||||
|
class BaseCmdPkgRelations(Cmd):
|
||||||
|
|
||||||
|
def pkg_relations(self, rel_type, args):
|
||||||
|
version_pattern=re.compile("[0-9-.]*")
|
||||||
|
if args.subsections is None:
|
||||||
|
subsecs = self.app.os_cascade()
|
||||||
|
subsecs.append('jw')
|
||||||
|
else:
|
||||||
|
subsecs = args.subsections.split(',')
|
||||||
|
self.app.debug('flavour = ', args.flavour, ', subsecs = ', ' '.join(subsecs))
|
||||||
|
ignore = args.ignore.split(',')
|
||||||
|
self.app.debug("ignore = ", ignore)
|
||||||
|
|
||||||
|
r = []
|
||||||
|
flavours = args.flavour.split(',')
|
||||||
|
for flavour in flavours:
|
||||||
|
for s in subsecs:
|
||||||
|
section = 'pkg.' + rel_type + '.' + s
|
||||||
|
visited = set()
|
||||||
|
modules = args.module.copy()
|
||||||
|
while len(modules):
|
||||||
|
m = modules.pop(0)
|
||||||
|
if m in visited or m in ignore:
|
||||||
|
continue
|
||||||
|
visited.add(m)
|
||||||
|
value = self.app.get_value(m, section, flavour)
|
||||||
|
if not value:
|
||||||
|
continue
|
||||||
|
deps = value.split(',')
|
||||||
|
for spec in deps:
|
||||||
|
dep = re.split('([=><]+)', spec)
|
||||||
|
if args.no_version:
|
||||||
|
dep = dep[:1]
|
||||||
|
dep = list(map(str.strip, dep))
|
||||||
|
dep_name = re.sub('-dev$|-devel$|-run$', '', dep[0])
|
||||||
|
if dep_name in ignore or dep[0] in ignore:
|
||||||
|
continue
|
||||||
|
if args.no_subpackages:
|
||||||
|
dep[0] = dep_name
|
||||||
|
for i, item in enumerate(dep):
|
||||||
|
dep[i] = item.strip()
|
||||||
|
if s == 'jw':
|
||||||
|
if args.recursive and not dep_name in visited and not dep_name in modules:
|
||||||
|
modules.append(dep_name)
|
||||||
|
if len(dep) == 3:
|
||||||
|
if args.dont_expand_version_macros and dep_name in args.module:
|
||||||
|
version = dep[2]
|
||||||
|
else:
|
||||||
|
version = self.app.get_value(dep_name, 'version', '')
|
||||||
|
if dep[2] == 'VERSION':
|
||||||
|
if args.dont_strip_revision:
|
||||||
|
dep[2] = version
|
||||||
|
else:
|
||||||
|
dep[2] = version.split('-')[0]
|
||||||
|
elif dep[2] == 'VERSION-REVISION':
|
||||||
|
dep[2] = version
|
||||||
|
elif version_pattern.match(dep[2]):
|
||||||
|
# dep[2] = dep[2]
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise Exception("Unknown version specifier in " + spec)
|
||||||
|
cleaned_dep = ' '.join(dep)
|
||||||
|
if not cleaned_dep in r:
|
||||||
|
self.app.debug("appending", cleaned_dep)
|
||||||
|
r.append(cleaned_dep)
|
||||||
|
return args.delimiter.join(r)
|
||||||
|
|
||||||
|
def print_pkg_relations(self, rel_type, args_):
|
||||||
|
print(self.pkg_relations(rel_type, args_))
|
||||||
|
|
||||||
|
def __init__(self, relation: str, help: str) -> None:
|
||||||
|
super().__init__('pkg-' + relation, help=help)
|
||||||
|
self.relation = relation
|
||||||
|
|
||||||
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||||
|
super().add_arguments(parser)
|
||||||
|
parser.add_argument('-S', '--subsections', nargs='?', default=None, help='Subsections to consider, comma-separated')
|
||||||
|
parser.add_argument('-d', '--delimiter', nargs='?', default=', ', help='Output words delimiter')
|
||||||
|
parser.add_argument('flavour', help='Flavour')
|
||||||
|
parser.add_argument('module', nargs='*', help='Modules')
|
||||||
|
parser.add_argument('-p', '--no-subpackages', action='store_true',
|
||||||
|
default=False, help='Cut -run and -devel from package names')
|
||||||
|
parser.add_argument('--no-version', action='store_true',
|
||||||
|
default=False, help='Don\'t report version information')
|
||||||
|
parser.add_argument('--dont-strip-revision', action='store_true',
|
||||||
|
default=False, help='Always treat VERSION macro as VERSION-REVISION')
|
||||||
|
parser.add_argument('--recursive', action='store_true',
|
||||||
|
default=False, help='Find dependencies recursively')
|
||||||
|
parser.add_argument('--dont-expand-version-macros', action='store_true',
|
||||||
|
default=False, help='Don\'t expand VERSION and REVISION macros')
|
||||||
|
parser.add_argument('--ignore', nargs='?', default='', help='Packages that '
|
||||||
|
'should be ignored together with their dependencies')
|
||||||
|
|
||||||
|
def _run(self, args: Namespace) -> None:
|
||||||
|
return self.print_pkg_relations(self.relation, args)
|
||||||
|
|
@ -2,17 +2,9 @@
|
||||||
|
|
||||||
from argparse import Namespace, ArgumentParser
|
from argparse import Namespace, ArgumentParser
|
||||||
|
|
||||||
from ..Cmd import Cmd
|
from .BaseCmdPkgRelations import BaseCmdPkgRelations as Base
|
||||||
|
|
||||||
class CmdPkgConflicts(Cmd): # export
|
class CmdPkgConflicts(Base): # export
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__('pkg-conflicts', help='Print packages conflicting with a given package')
|
super().__init__('conflicts', help='Print packages conflicting with a given package')
|
||||||
|
|
||||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
|
||||||
self.app.pkg_relations_add_arguments(parser)
|
|
||||||
super().add_arguments(parser)
|
|
||||||
|
|
||||||
|
|
||||||
def _run(self, args: Namespace) -> None:
|
|
||||||
return self.app.print_pkg_relations("conflicts", args)
|
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,9 @@
|
||||||
|
|
||||||
from argparse import Namespace, ArgumentParser
|
from argparse import Namespace, ArgumentParser
|
||||||
|
|
||||||
from ..Cmd import Cmd
|
from .BaseCmdPkgRelations import BaseCmdPkgRelations as Base
|
||||||
|
|
||||||
class CmdPkgProvides(Cmd): # export
|
class CmdPkgProvides(Base): # export
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__('pkg-provides', help='Print packages and capabilities provided a given package')
|
super().__init__('provides', help='Print packages and capabilities provided by a given package')
|
||||||
|
|
||||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
|
||||||
self.app.pkg_relations_add_arguments(parser)
|
|
||||||
super().add_arguments(parser)
|
|
||||||
|
|
||||||
def _run(self, args: Namespace) -> None:
|
|
||||||
return self.app.print_pkg_relations("provides", args)
|
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,9 @@
|
||||||
|
|
||||||
from argparse import Namespace, ArgumentParser
|
from argparse import Namespace, ArgumentParser
|
||||||
|
|
||||||
from ..Cmd import Cmd
|
from .BaseCmdPkgRelations import BaseCmdPkgRelations as Base
|
||||||
|
|
||||||
class CmdPkgRequires(Cmd): # export
|
class CmdPkgRequires(Base): # export
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__('pkg-requires', help='Print packages required for a given package')
|
super().__init__('requires', help='Print packages required for a given package')
|
||||||
|
|
||||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
|
||||||
self.app.pkg_relations_add_arguments(parser)
|
|
||||||
super().add_arguments(parser)
|
|
||||||
|
|
||||||
def _run(self, args: Namespace) -> None:
|
|
||||||
return self.app.print_pkg_relations("requires", args)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue