From 95fa2f0d06caeb00ce8c181b895082616a60a27e Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sun, 25 Jan 2026 15:18:27 +0100 Subject: [PATCH] jw.pkg.App: Remove .debug() and friends Replace the jw.pkg.App.debug(), .warn() and .err() methods by the global log() function. There's no obvious benefit in having App know what's logged. Signed-off-by: Jan Lindemann --- src/python/jw/pkg/App.py | 33 +++++++------------ .../pkg/cmds/projects/BaseCmdPkgRelations.py | 7 ++-- src/python/jw/pkg/cmds/projects/CmdBuild.py | 15 +++++---- src/python/jw/pkg/cmds/projects/CmdCheck.py | 5 +-- .../jw/pkg/cmds/projects/CmdGetAuthInfo.py | 5 +-- src/python/jw/pkg/cmds/projects/CmdModules.py | 7 ++-- src/python/jw/pkg/cmds/projects/CmdProjDir.py | 3 +- .../jw/pkg/cmds/projects/CmdRequiredOsPkg.py | 5 +-- 8 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/python/jw/pkg/App.py b/src/python/jw/pkg/App.py index f759ee3a..07170d3a 100644 --- a/src/python/jw/pkg/App.py +++ b/src/python/jw/pkg/App.py @@ -31,7 +31,7 @@ class ResultCache(object): else: k = str(k) depth += 1 - #self.projects.debug('depth = ', depth, 'key = ', k, 'd = ', str(d)) + #log(DEBUG, 'depth = ', depth, 'key = ', k, 'd = ', str(d)) if k in d: if l == depth: return d[k] @@ -160,15 +160,6 @@ class App(Base): def find_dir(self, name: str, search_subdirs: list[str]=[], search_absdirs: list[str]=[], pretty: bool=True): return self.__find_dir(name, search_subdirs, search_absdirs, pretty) - def debug(self, *objs): - log(DEBUG, *objs) - - def warn(self, *objs): - log(WARNING, *objs) - - def err(self, *objs): - log(ERR, *objs) - def re_section(self, name): return re.compile('[' + name + ']' '.*?' @@ -191,7 +182,7 @@ class App(Base): p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) (out, rr) = p.communicate() if rr: - self.err("failed to run ", cmd) + log(ERR, "failed to run ", cmd) continue out = re.sub('\n', '', out.decode('utf-8')) return out @@ -270,7 +261,7 @@ class App(Base): lines.append(cont_line) cont_line = '' for line in lines: - #self.debug(" looking for >%s< in line=>%s<" % (key, line)) + #log(DEBUG, " looking for >%s< in line=>%s<" % (key, line)) rr = re.findall('^ *' + key + ' *= *(.*)', line) if len(rr) > 0: return rr[0] @@ -278,11 +269,11 @@ class App(Base): def scan_section_debug(f, key): rr = scan_section(f, key) - #self.debug(" returning", rr) + #log(DEBUG, " returning", rr) return rr try: - #self.debug("looking for {}::[{}].{}".format(path, section, key)) + #log(DEBUG, "looking for {}::[{}].{}".format(path, section, key)) with open(path, 'r') as f: if not len(section): rr = scan_section(f, key) @@ -292,19 +283,19 @@ class App(Base): return scan_section(f, key) return None except: - self.debug(path, "not found") + log(DEBUG, path, "not found") # TODO: handle this special case cleaner somewhere up the stack if section == 'build' and key == 'libname': return 'none' return None def get_value(self, name, section, key): - self.debug("getting value [%s].%s for project %s (%s)" %(section, key, name, self.top_name)) + log(DEBUG, "getting value [%s].%s for project %s (%s)" %(section, key, name, self.top_name)) if self.top_name and name == self.top_name: proj_root = self.topdir else: proj_root = self.projs_root + '/' + name - self.debug("proj_root = " + proj_root) + log(DEBUG, "proj_root = " + proj_root) if section == 'version': proj_version_dirs = [ proj_root ] @@ -318,7 +309,7 @@ class App(Base): fd.close() return r except EnvironmentError: - self.debug("ignoring unreadable file " + version_path) + log(DEBUG, "ignoring unreadable file " + version_path) continue raise Exception("No version file found for project \"" + name + "\"") @@ -356,7 +347,7 @@ class App(Base): return visited.add(spec) deps = self.get_value(name, section, key) - self.debug("name = ", name, "section = ", section, "key = ", key, "deps = ", deps, "scope = ", scope, "visited = ", visited) + log(DEBUG, "name = ", name, "section = ", section, "key = ", key, "deps = ", deps, "scope = ", scope, "visited = ", visited) if deps and scope > 0: if scope == 1: subscope = 0 @@ -402,7 +393,7 @@ class App(Base): return ' '.join(reversed(vals)) def is_excluded_from_build(self, module): - self.debug("checking if module " + module + " is excluded from build") + log(DEBUG, "checking if module " + module + " is excluded from build") exclude = self.get_modules_from_project_txt([ module ], ['build'], 'exclude', scope = 1, add_self=False, names_only=True) cascade = self.os_cascade() + [ 'all' ] @@ -443,7 +434,7 @@ class App(Base): def check_circular_deps(self, module, section, graph, unvisited, temp, path): if module in temp: - self.debug('found circular dependency at module', module) + log(DEBUG, 'found circular dependency at module', module) return module if not module in unvisited: return None diff --git a/src/python/jw/pkg/cmds/projects/BaseCmdPkgRelations.py b/src/python/jw/pkg/cmds/projects/BaseCmdPkgRelations.py index 6aa861ff..bdd166b1 100644 --- a/src/python/jw/pkg/cmds/projects/BaseCmdPkgRelations.py +++ b/src/python/jw/pkg/cmds/projects/BaseCmdPkgRelations.py @@ -3,6 +3,7 @@ import re from argparse import Namespace, ArgumentParser +from ...lib.log import * from ..Cmd import Cmd class BaseCmdPkgRelations(Cmd): @@ -14,9 +15,9 @@ class BaseCmdPkgRelations(Cmd): subsecs.append('jw') else: subsecs = args.subsections.split(',') - self.app.debug('flavour = ', args.flavour, ', subsecs = ', ' '.join(subsecs)) + log(DEBUG, 'flavour = ', args.flavour, ', subsecs = ', ' '.join(subsecs)) ignore = args.ignore.split(',') - self.app.debug("ignore = ", ignore) + log(DEBUG, "ignore = ", ignore) r = [] flavours = args.flavour.split(',') @@ -68,7 +69,7 @@ class BaseCmdPkgRelations(Cmd): raise Exception("Unknown version specifier in " + spec) cleaned_dep = ' '.join(dep) if not cleaned_dep in r: - self.app.debug("appending", cleaned_dep) + log(DEBUG, "appending", cleaned_dep) r.append(cleaned_dep) return args.delimiter.join(r) diff --git a/src/python/jw/pkg/cmds/projects/CmdBuild.py b/src/python/jw/pkg/cmds/projects/CmdBuild.py index 2771235a..2c13785e 100644 --- a/src/python/jw/pkg/cmds/projects/CmdBuild.py +++ b/src/python/jw/pkg/cmds/projects/CmdBuild.py @@ -3,6 +3,7 @@ import os, re, sys, subprocess, datetime, time from argparse import Namespace, ArgumentParser +from ...lib.log import * from ..Cmd import Cmd class CmdBuild(Cmd): # export @@ -34,10 +35,10 @@ class CmdBuild(Cmd): # export r = self.app.get_modules_from_project_txt([ cur ], ['pkg.requires.jw'], prereq_type, scope = 2, add_self=False, names_only=True) - self.app.debug('prerequisites = ' + ' '.join(r)) + log(DEBUG, 'prerequisites = ' + ' '.join(r)) if cur in r: r.remove(cur) - self.app.debug('inserting', prereq_type, "prerequisites of", cur, ":", ' '.join(r)) + log(DEBUG, 'inserting', prereq_type, "prerequisites of", cur, ":", ' '.join(r)) self.app.dep_cache[prereq_type][cur] = r return r @@ -45,14 +46,14 @@ class CmdBuild(Cmd): # export return self.app.res_cache.run(read_deps, [ cur, prereq_type ]) def add_dep_tree(cur, prereq_types, tree, all_deps): - self.app.debug("adding prerequisites " + ' '.join(prereq_types) + " of module " + cur) + log(DEBUG, "adding prerequisites " + ' '.join(prereq_types) + " of module " + cur) if cur in all_deps: - self.app.debug('already handled module ' + cur) + log(DEBUG, 'already handled module ' + cur) return 0 deps = set() all_deps.add(cur) for t in prereq_types: - self.app.debug("checking prereqisites of type " + t) + log(DEBUG, "checking prereqisites of type " + t) deps.update(read_deps_cached(cur, t)) for d in deps: add_dep_tree(d, prereq_types, tree, all_deps) @@ -63,7 +64,7 @@ class CmdBuild(Cmd): # export all_deps = set() dep_tree = {} for m in modules: - self.app.debug("--- adding dependency tree of module " + m) + log(DEBUG, "--- adding dependency tree of module " + m) add_dep_tree(m, prereq_types, dep_tree, all_deps) while len(all_deps): # Find any leaf @@ -128,7 +129,7 @@ class CmdBuild(Cmd): # export def run(args): - self.app.debug("----------------------------------------- running ", ' '.join(sys.argv)) + log(DEBUG, "----------------------------------------- running ", ' '.join(sys.argv)) modules = args.modules exclude = args.exclude.split() diff --git a/src/python/jw/pkg/cmds/projects/CmdCheck.py b/src/python/jw/pkg/cmds/projects/CmdCheck.py index a5d45b49..c9082aa1 100644 --- a/src/python/jw/pkg/cmds/projects/CmdCheck.py +++ b/src/python/jw/pkg/cmds/projects/CmdCheck.py @@ -2,6 +2,7 @@ from argparse import Namespace, ArgumentParser +from ...lib.log import * from ..Cmd import Cmd class CmdCheck(Cmd): # export @@ -22,10 +23,10 @@ class CmdCheck(Cmd): # export temp = set() while len(unvisited) != 0: m = unvisited[0] - self.app.debug('Checking circular dependency of', m) + log(DEBUG, 'Checking circular dependency of', m) last = self.app.check_circular_deps(m, args.flavour, self.app.flip_graph(graph), unvisited, temp, path) if last is not None: - self.app.debug('Found circular dependency below', m, ', last is', last) + log(DEBUG, 'Found circular dependency below', m, ', last is', last) print('Found circular dependency in flavour', args.flavour, ':', ' -> '.join(path)) exit(1) print('No circular dependency found for flavour', args.flavour, ' in modules:', diff --git a/src/python/jw/pkg/cmds/projects/CmdGetAuthInfo.py b/src/python/jw/pkg/cmds/projects/CmdGetAuthInfo.py index ab78af3a..cc96b59a 100644 --- a/src/python/jw/pkg/cmds/projects/CmdGetAuthInfo.py +++ b/src/python/jw/pkg/cmds/projects/CmdGetAuthInfo.py @@ -4,8 +4,9 @@ import re, os from argparse import Namespace, ArgumentParser from urllib.parse import urlparse -from ..Cmd import Cmd +from ...lib.log import * from ...lib.util import run_cmd +from ..Cmd import Cmd class CmdGetAuthInfo(Cmd): # export @@ -25,7 +26,7 @@ class CmdGetAuthInfo(Cmd): # export # --- Milk jw-pkg repo jw_pkg_dir = self.app.find_dir('jw-pkg', pretty=False) if not os.path.isdir(jw_pkg_dir + '/.git'): - self.app.debug(f'jw-pkg directory is not a Git repo: {jw_pkg_dir}') + log(DEBUG, f'jw-pkg directory is not a Git repo: {jw_pkg_dir}') return remotes = run_cmd(['git', '-C', jw_pkg_dir, 'remote', '-v']) result: dict[str, str] = {} diff --git a/src/python/jw/pkg/cmds/projects/CmdModules.py b/src/python/jw/pkg/cmds/projects/CmdModules.py index 309dc314..e701a6cf 100644 --- a/src/python/jw/pkg/cmds/projects/CmdModules.py +++ b/src/python/jw/pkg/cmds/projects/CmdModules.py @@ -2,6 +2,7 @@ from argparse import Namespace, ArgumentParser +from ...lib.log import * from ..Cmd import Cmd class CmdModules(Cmd): # export @@ -16,10 +17,10 @@ class CmdModules(Cmd): # export def _run(self, args: Namespace) -> None: import pathlib proj_root = self.app.projs_root - self.app.debug("proj_root = " + proj_root) + log(DEBUG, "proj_root = " + proj_root) path = pathlib.Path(self.app.projs_root) modules = [p.parents[1].name for p in path.glob('*/make/project.conf')] - self.app.debug("modules = ", modules) + log(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: @@ -33,7 +34,7 @@ class CmdModules(Cmd): # export sec = None key = path[0] val = self.app.get_value(m, sec, key) - self.app.debug('Checking in {} if {}="{}", is "{}"'.format(m, f[0], f[1], val)) + log(DEBUG, 'Checking in {} if {}="{}", is "{}"'.format(m, f[0], f[1], val)) if val and val == f[1]: out.append(m) break diff --git a/src/python/jw/pkg/cmds/projects/CmdProjDir.py b/src/python/jw/pkg/cmds/projects/CmdProjDir.py index 97c488fd..11a30f6e 100644 --- a/src/python/jw/pkg/cmds/projects/CmdProjDir.py +++ b/src/python/jw/pkg/cmds/projects/CmdProjDir.py @@ -2,6 +2,7 @@ from argparse import Namespace, ArgumentParser +from ...lib.log import * from ..Cmd import Cmd class CmdProjDir(Cmd): # export @@ -18,7 +19,7 @@ class CmdProjDir(Cmd): # export for m in args.module: path = self.app.find_dir(m) if path is None: - self.app.warn(f'No project directory for module "{m}: {e}') + log(WARNING, f'No project directory for module "{m}: {e}') continue out.append(path) if out: diff --git a/src/python/jw/pkg/cmds/projects/CmdRequiredOsPkg.py b/src/python/jw/pkg/cmds/projects/CmdRequiredOsPkg.py index 9e0fc019..37cfc36c 100644 --- a/src/python/jw/pkg/cmds/projects/CmdRequiredOsPkg.py +++ b/src/python/jw/pkg/cmds/projects/CmdRequiredOsPkg.py @@ -2,6 +2,7 @@ from argparse import Namespace, ArgumentParser +from ...lib.log import * from ..Cmd import Cmd # TODO: seems at least partly redundant to CmdPkgRequires / print_pkg_relations @@ -23,7 +24,7 @@ class CmdRequiredOsPkg(Cmd): # export if 'build' in flavours and not 'run' in flavours: # TODO: This adds too much. Only the run dependencies of the build dependencies would be needed. flavours.append('run') - self.app.debug("flavours = " + args.flavours) + log(DEBUG, "flavours = " + args.flavours) deps = self.app.get_modules_from_project_txt(modules, ['pkg.requires.jw'], flavours, scope = 2, add_self=True, names_only=True) if args.skip_excluded: @@ -31,7 +32,7 @@ class CmdRequiredOsPkg(Cmd): # export if self.app.is_excluded_from_build(d) is not None: deps.remove(d) subsecs = self.app.os_cascade() - self.app.debug("subsecs = ", subsecs) + log(DEBUG, "subsecs = ", subsecs) requires = [] for s in subsecs: for f in flavours: