projects.py: Add command modules

projects.py modules shows either all modules, or modules which have one of the
key-value pairs requested for filtering via the -F option.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2024-04-30 08:00:39 +00:00
commit 3f5a3d004a

View file

@ -10,6 +10,7 @@ import sys
import argparse import argparse
import pwd import pwd
import time import time
import pathlib
from os.path import isfile from os.path import isfile
from os.path import isdir from os.path import isdir
from os.path import expanduser from os.path import expanduser
@ -483,6 +484,38 @@ class Projects(object):
def cmd_commands(self, args_): def cmd_commands(self, args_):
print(self.commands()) print(self.commands())
def cmd_modules(self, args_):
proj_root = self.projs_root
self.debug("proj_root = " + proj_root)
path = pathlib.Path(self.projs_root)
parser = argparse.ArgumentParser(description='Query existing janware packages')
parser.add_argument('-F', '--filter', nargs='?', default=None, help='Key-value pairs, seperated by commas, to be searched for in project.conf')
args = parser.parse_args(args_)
modules = [p.parents[1].name for p in path.glob('*/make/project.conf')]
self.debug("modules = ", modules)
out = []
filters = None if args.filter is None else [re.split("=", f) for f in re.split(",", args.filter)]
for m in modules:
if filters:
for f in filters:
path = f[0].rsplit('.')
if len(path) > 1:
sec = path[0]
key = path[1]
else:
sec = None
key = path[0]
val = self.get_value(m, sec, key)
self.debug('Checking in {} if {}="{}", is "{}"'.format(m, f[0], f[1], val))
if val and val == f[1]:
out.append(m)
break
else:
out.append(m)
print(' '.join(out))
def cmd_build(self, args_): def cmd_build(self, args_):
def read_deps(cur, prereq_type): def read_deps(cur, prereq_type):