mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-25 17:45:55 +02:00
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 <jan@janware.com>
This commit is contained in:
parent
aefe983920
commit
95fa2f0d06
8 changed files with 39 additions and 41 deletions
|
|
@ -31,7 +31,7 @@ class ResultCache(object):
|
||||||
else:
|
else:
|
||||||
k = str(k)
|
k = str(k)
|
||||||
depth += 1
|
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 k in d:
|
||||||
if l == depth:
|
if l == depth:
|
||||||
return d[k]
|
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):
|
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)
|
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):
|
def re_section(self, name):
|
||||||
return re.compile('[' + name + ']'
|
return re.compile('[' + name + ']'
|
||||||
'.*?'
|
'.*?'
|
||||||
|
|
@ -191,7 +182,7 @@ class App(Base):
|
||||||
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
|
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
|
||||||
(out, rr) = p.communicate()
|
(out, rr) = p.communicate()
|
||||||
if rr:
|
if rr:
|
||||||
self.err("failed to run ", cmd)
|
log(ERR, "failed to run ", cmd)
|
||||||
continue
|
continue
|
||||||
out = re.sub('\n', '', out.decode('utf-8'))
|
out = re.sub('\n', '', out.decode('utf-8'))
|
||||||
return out
|
return out
|
||||||
|
|
@ -270,7 +261,7 @@ class App(Base):
|
||||||
lines.append(cont_line)
|
lines.append(cont_line)
|
||||||
cont_line = ''
|
cont_line = ''
|
||||||
for line in lines:
|
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)
|
rr = re.findall('^ *' + key + ' *= *(.*)', line)
|
||||||
if len(rr) > 0:
|
if len(rr) > 0:
|
||||||
return rr[0]
|
return rr[0]
|
||||||
|
|
@ -278,11 +269,11 @@ class App(Base):
|
||||||
|
|
||||||
def scan_section_debug(f, key):
|
def scan_section_debug(f, key):
|
||||||
rr = scan_section(f, key)
|
rr = scan_section(f, key)
|
||||||
#self.debug(" returning", rr)
|
#log(DEBUG, " returning", rr)
|
||||||
return rr
|
return rr
|
||||||
|
|
||||||
try:
|
try:
|
||||||
#self.debug("looking for {}::[{}].{}".format(path, section, key))
|
#log(DEBUG, "looking for {}::[{}].{}".format(path, section, key))
|
||||||
with open(path, 'r') as f:
|
with open(path, 'r') as f:
|
||||||
if not len(section):
|
if not len(section):
|
||||||
rr = scan_section(f, key)
|
rr = scan_section(f, key)
|
||||||
|
|
@ -292,19 +283,19 @@ class App(Base):
|
||||||
return scan_section(f, key)
|
return scan_section(f, key)
|
||||||
return None
|
return None
|
||||||
except:
|
except:
|
||||||
self.debug(path, "not found")
|
log(DEBUG, path, "not found")
|
||||||
# TODO: handle this special case cleaner somewhere up the stack
|
# TODO: handle this special case cleaner somewhere up the stack
|
||||||
if section == 'build' and key == 'libname':
|
if section == 'build' and key == 'libname':
|
||||||
return 'none'
|
return 'none'
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_value(self, name, section, key):
|
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:
|
if self.top_name and name == self.top_name:
|
||||||
proj_root = self.topdir
|
proj_root = self.topdir
|
||||||
else:
|
else:
|
||||||
proj_root = self.projs_root + '/' + name
|
proj_root = self.projs_root + '/' + name
|
||||||
self.debug("proj_root = " + proj_root)
|
log(DEBUG, "proj_root = " + proj_root)
|
||||||
|
|
||||||
if section == 'version':
|
if section == 'version':
|
||||||
proj_version_dirs = [ proj_root ]
|
proj_version_dirs = [ proj_root ]
|
||||||
|
|
@ -318,7 +309,7 @@ class App(Base):
|
||||||
fd.close()
|
fd.close()
|
||||||
return r
|
return r
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
self.debug("ignoring unreadable file " + version_path)
|
log(DEBUG, "ignoring unreadable file " + version_path)
|
||||||
continue
|
continue
|
||||||
raise Exception("No version file found for project \"" + name + "\"")
|
raise Exception("No version file found for project \"" + name + "\"")
|
||||||
|
|
||||||
|
|
@ -356,7 +347,7 @@ class App(Base):
|
||||||
return
|
return
|
||||||
visited.add(spec)
|
visited.add(spec)
|
||||||
deps = self.get_value(name, section, key)
|
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 deps and scope > 0:
|
||||||
if scope == 1:
|
if scope == 1:
|
||||||
subscope = 0
|
subscope = 0
|
||||||
|
|
@ -402,7 +393,7 @@ class App(Base):
|
||||||
return ' '.join(reversed(vals))
|
return ' '.join(reversed(vals))
|
||||||
|
|
||||||
def is_excluded_from_build(self, module):
|
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',
|
exclude = self.get_modules_from_project_txt([ module ], ['build'], 'exclude',
|
||||||
scope = 1, add_self=False, names_only=True)
|
scope = 1, add_self=False, names_only=True)
|
||||||
cascade = self.os_cascade() + [ 'all' ]
|
cascade = self.os_cascade() + [ 'all' ]
|
||||||
|
|
@ -443,7 +434,7 @@ class App(Base):
|
||||||
|
|
||||||
def check_circular_deps(self, module, section, graph, unvisited, temp, path):
|
def check_circular_deps(self, module, section, graph, unvisited, temp, path):
|
||||||
if module in temp:
|
if module in temp:
|
||||||
self.debug('found circular dependency at module', module)
|
log(DEBUG, 'found circular dependency at module', module)
|
||||||
return module
|
return module
|
||||||
if not module in unvisited:
|
if not module in unvisited:
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
import re
|
import re
|
||||||
from argparse import Namespace, ArgumentParser
|
from argparse import Namespace, ArgumentParser
|
||||||
|
|
||||||
|
from ...lib.log import *
|
||||||
from ..Cmd import Cmd
|
from ..Cmd import Cmd
|
||||||
|
|
||||||
class BaseCmdPkgRelations(Cmd):
|
class BaseCmdPkgRelations(Cmd):
|
||||||
|
|
@ -14,9 +15,9 @@ class BaseCmdPkgRelations(Cmd):
|
||||||
subsecs.append('jw')
|
subsecs.append('jw')
|
||||||
else:
|
else:
|
||||||
subsecs = args.subsections.split(',')
|
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(',')
|
ignore = args.ignore.split(',')
|
||||||
self.app.debug("ignore = ", ignore)
|
log(DEBUG, "ignore = ", ignore)
|
||||||
|
|
||||||
r = []
|
r = []
|
||||||
flavours = args.flavour.split(',')
|
flavours = args.flavour.split(',')
|
||||||
|
|
@ -68,7 +69,7 @@ class BaseCmdPkgRelations(Cmd):
|
||||||
raise Exception("Unknown version specifier in " + spec)
|
raise Exception("Unknown version specifier in " + spec)
|
||||||
cleaned_dep = ' '.join(dep)
|
cleaned_dep = ' '.join(dep)
|
||||||
if not cleaned_dep in r:
|
if not cleaned_dep in r:
|
||||||
self.app.debug("appending", cleaned_dep)
|
log(DEBUG, "appending", cleaned_dep)
|
||||||
r.append(cleaned_dep)
|
r.append(cleaned_dep)
|
||||||
return args.delimiter.join(r)
|
return args.delimiter.join(r)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
import os, re, sys, subprocess, datetime, time
|
import os, re, sys, subprocess, datetime, time
|
||||||
from argparse import Namespace, ArgumentParser
|
from argparse import Namespace, ArgumentParser
|
||||||
|
|
||||||
|
from ...lib.log import *
|
||||||
from ..Cmd import Cmd
|
from ..Cmd import Cmd
|
||||||
|
|
||||||
class CmdBuild(Cmd): # export
|
class CmdBuild(Cmd): # export
|
||||||
|
|
@ -34,10 +35,10 @@ class CmdBuild(Cmd): # export
|
||||||
|
|
||||||
r = self.app.get_modules_from_project_txt([ cur ], ['pkg.requires.jw'],
|
r = self.app.get_modules_from_project_txt([ cur ], ['pkg.requires.jw'],
|
||||||
prereq_type, scope = 2, add_self=False, names_only=True)
|
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:
|
if cur in r:
|
||||||
r.remove(cur)
|
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
|
self.app.dep_cache[prereq_type][cur] = r
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
@ -45,14 +46,14 @@ class CmdBuild(Cmd): # export
|
||||||
return self.app.res_cache.run(read_deps, [ cur, prereq_type ])
|
return self.app.res_cache.run(read_deps, [ cur, prereq_type ])
|
||||||
|
|
||||||
def add_dep_tree(cur, prereq_types, tree, all_deps):
|
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:
|
if cur in all_deps:
|
||||||
self.app.debug('already handled module ' + cur)
|
log(DEBUG, 'already handled module ' + cur)
|
||||||
return 0
|
return 0
|
||||||
deps = set()
|
deps = set()
|
||||||
all_deps.add(cur)
|
all_deps.add(cur)
|
||||||
for t in prereq_types:
|
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))
|
deps.update(read_deps_cached(cur, t))
|
||||||
for d in deps:
|
for d in deps:
|
||||||
add_dep_tree(d, prereq_types, tree, all_deps)
|
add_dep_tree(d, prereq_types, tree, all_deps)
|
||||||
|
|
@ -63,7 +64,7 @@ class CmdBuild(Cmd): # export
|
||||||
all_deps = set()
|
all_deps = set()
|
||||||
dep_tree = {}
|
dep_tree = {}
|
||||||
for m in modules:
|
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)
|
add_dep_tree(m, prereq_types, dep_tree, all_deps)
|
||||||
while len(all_deps):
|
while len(all_deps):
|
||||||
# Find any leaf
|
# Find any leaf
|
||||||
|
|
@ -128,7 +129,7 @@ class CmdBuild(Cmd): # export
|
||||||
|
|
||||||
def run(args):
|
def run(args):
|
||||||
|
|
||||||
self.app.debug("----------------------------------------- running ", ' '.join(sys.argv))
|
log(DEBUG, "----------------------------------------- running ", ' '.join(sys.argv))
|
||||||
|
|
||||||
modules = args.modules
|
modules = args.modules
|
||||||
exclude = args.exclude.split()
|
exclude = args.exclude.split()
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
from argparse import Namespace, ArgumentParser
|
from argparse import Namespace, ArgumentParser
|
||||||
|
|
||||||
|
from ...lib.log import *
|
||||||
from ..Cmd import Cmd
|
from ..Cmd import Cmd
|
||||||
|
|
||||||
class CmdCheck(Cmd): # export
|
class CmdCheck(Cmd): # export
|
||||||
|
|
@ -22,10 +23,10 @@ class CmdCheck(Cmd): # export
|
||||||
temp = set()
|
temp = set()
|
||||||
while len(unvisited) != 0:
|
while len(unvisited) != 0:
|
||||||
m = 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)
|
last = self.app.check_circular_deps(m, args.flavour, self.app.flip_graph(graph), unvisited, temp, path)
|
||||||
if last is not None:
|
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))
|
print('Found circular dependency in flavour', args.flavour, ':', ' -> '.join(path))
|
||||||
exit(1)
|
exit(1)
|
||||||
print('No circular dependency found for flavour', args.flavour, ' in modules:',
|
print('No circular dependency found for flavour', args.flavour, ' in modules:',
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,9 @@ import re, os
|
||||||
from argparse import Namespace, ArgumentParser
|
from argparse import Namespace, ArgumentParser
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from ..Cmd import Cmd
|
from ...lib.log import *
|
||||||
from ...lib.util import run_cmd
|
from ...lib.util import run_cmd
|
||||||
|
from ..Cmd import Cmd
|
||||||
|
|
||||||
class CmdGetAuthInfo(Cmd): # export
|
class CmdGetAuthInfo(Cmd): # export
|
||||||
|
|
||||||
|
|
@ -25,7 +26,7 @@ class CmdGetAuthInfo(Cmd): # export
|
||||||
# --- Milk jw-pkg repo
|
# --- Milk jw-pkg repo
|
||||||
jw_pkg_dir = self.app.find_dir('jw-pkg', pretty=False)
|
jw_pkg_dir = self.app.find_dir('jw-pkg', pretty=False)
|
||||||
if not os.path.isdir(jw_pkg_dir + '/.git'):
|
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
|
return
|
||||||
remotes = run_cmd(['git', '-C', jw_pkg_dir, 'remote', '-v'])
|
remotes = run_cmd(['git', '-C', jw_pkg_dir, 'remote', '-v'])
|
||||||
result: dict[str, str] = {}
|
result: dict[str, str] = {}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
from argparse import Namespace, ArgumentParser
|
from argparse import Namespace, ArgumentParser
|
||||||
|
|
||||||
|
from ...lib.log import *
|
||||||
from ..Cmd import Cmd
|
from ..Cmd import Cmd
|
||||||
|
|
||||||
class CmdModules(Cmd): # export
|
class CmdModules(Cmd): # export
|
||||||
|
|
@ -16,10 +17,10 @@ class CmdModules(Cmd): # export
|
||||||
def _run(self, args: Namespace) -> None:
|
def _run(self, args: Namespace) -> None:
|
||||||
import pathlib
|
import pathlib
|
||||||
proj_root = self.app.projs_root
|
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)
|
path = pathlib.Path(self.app.projs_root)
|
||||||
modules = [p.parents[1].name for p in path.glob('*/make/project.conf')]
|
modules = [p.parents[1].name for p in path.glob('*/make/project.conf')]
|
||||||
self.app.debug("modules = ", modules)
|
log(DEBUG, "modules = ", modules)
|
||||||
out = []
|
out = []
|
||||||
filters = None if args.filter is None else [re.split("=", f) for f in re.split(",", args.filter)]
|
filters = None if args.filter is None else [re.split("=", f) for f in re.split(",", args.filter)]
|
||||||
for m in modules:
|
for m in modules:
|
||||||
|
|
@ -33,7 +34,7 @@ class CmdModules(Cmd): # export
|
||||||
sec = None
|
sec = None
|
||||||
key = path[0]
|
key = path[0]
|
||||||
val = self.app.get_value(m, sec, key)
|
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]:
|
if val and val == f[1]:
|
||||||
out.append(m)
|
out.append(m)
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
from argparse import Namespace, ArgumentParser
|
from argparse import Namespace, ArgumentParser
|
||||||
|
|
||||||
|
from ...lib.log import *
|
||||||
from ..Cmd import Cmd
|
from ..Cmd import Cmd
|
||||||
|
|
||||||
class CmdProjDir(Cmd): # export
|
class CmdProjDir(Cmd): # export
|
||||||
|
|
@ -18,7 +19,7 @@ class CmdProjDir(Cmd): # export
|
||||||
for m in args.module:
|
for m in args.module:
|
||||||
path = self.app.find_dir(m)
|
path = self.app.find_dir(m)
|
||||||
if path is None:
|
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
|
continue
|
||||||
out.append(path)
|
out.append(path)
|
||||||
if out:
|
if out:
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
from argparse import Namespace, ArgumentParser
|
from argparse import Namespace, ArgumentParser
|
||||||
|
|
||||||
|
from ...lib.log import *
|
||||||
from ..Cmd import Cmd
|
from ..Cmd import Cmd
|
||||||
|
|
||||||
# TODO: seems at least partly redundant to CmdPkgRequires / print_pkg_relations
|
# 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:
|
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.
|
# TODO: This adds too much. Only the run dependencies of the build dependencies would be needed.
|
||||||
flavours.append('run')
|
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,
|
deps = self.app.get_modules_from_project_txt(modules, ['pkg.requires.jw'], flavours,
|
||||||
scope = 2, add_self=True, names_only=True)
|
scope = 2, add_self=True, names_only=True)
|
||||||
if args.skip_excluded:
|
if args.skip_excluded:
|
||||||
|
|
@ -31,7 +32,7 @@ class CmdRequiredOsPkg(Cmd): # export
|
||||||
if self.app.is_excluded_from_build(d) is not None:
|
if self.app.is_excluded_from_build(d) is not None:
|
||||||
deps.remove(d)
|
deps.remove(d)
|
||||||
subsecs = self.app.os_cascade()
|
subsecs = self.app.os_cascade()
|
||||||
self.app.debug("subsecs = ", subsecs)
|
log(DEBUG, "subsecs = ", subsecs)
|
||||||
requires = []
|
requires = []
|
||||||
for s in subsecs:
|
for s in subsecs:
|
||||||
for f in flavours:
|
for f in flavours:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue