mirror of
ssh://devgit.janware.com/janware/proj/jw-python
synced 2026-06-17 11:36:38 +02:00
Makefile: Include py-topdir.mk
Include py-topdir.mk, which entails loads of fallout from make check. Fix it.
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
7212850b22
commit
e9845b5a1f
45 changed files with 1796 additions and 1191 deletions
|
|
@ -1,9 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
|
||||
import os, glob
|
||||
|
||||
from .StringTree import *
|
||||
from ..log import *
|
||||
from ..log import DEBUG, ERR, INFO, slog, slog_m
|
||||
from .StringTree import StringTree, cleanup_string
|
||||
|
||||
def _cleanup_line(line: str) -> str:
|
||||
line = line.strip()
|
||||
|
|
@ -15,18 +15,22 @@ def _cleanup_line(line: str) -> str:
|
|||
if c == in_quote:
|
||||
in_quote = None
|
||||
else:
|
||||
if c in [ '"', "'" ]:
|
||||
if c in ['"', "'"]:
|
||||
in_quote = c
|
||||
elif in_quote is None and c == '#':
|
||||
return r.strip()
|
||||
r += c
|
||||
if len(r) >= 2 and r[0] in [ '"', "'" ] and r[-1] == r[0]:
|
||||
if len(r) >= 2 and r[0] in ['"', "'"] and r[-1] == r[0]:
|
||||
return r[1:-1]
|
||||
return r
|
||||
|
||||
def parse(s: str, allow_full_lines: bool=True, root_content: str='root') -> StringTree: # export
|
||||
def parse( # export
|
||||
s: str,
|
||||
allow_full_lines: bool = True,
|
||||
root_content: str = 'root'
|
||||
) -> StringTree:
|
||||
slog_m(DEBUG, "--->--- parsing --->---\n" + s + "\n---<--- parsing ---<---\n")
|
||||
root = StringTree('', content=root_content)
|
||||
root = StringTree('', content = root_content)
|
||||
sec = ''
|
||||
for line in s.splitlines():
|
||||
slog(DEBUG, f'Parsing: "{line}"')
|
||||
|
|
@ -47,7 +51,7 @@ def parse(s: str, allow_full_lines: bool=True, root_content: str='root') -> Stri
|
|||
root.add(sec)
|
||||
continue
|
||||
elif line[0] == ']':
|
||||
assert(len(sec) > 0)
|
||||
assert (len(sec) > 0)
|
||||
sec = '.'.join(sec.split('.')[0:-1])
|
||||
continue
|
||||
lhs = ''
|
||||
|
|
@ -67,17 +71,19 @@ def parse(s: str, allow_full_lines: bool=True, root_content: str='root') -> Stri
|
|||
raise Exception("failed to parse assignment", line)
|
||||
rhs = 'empty'
|
||||
split = False
|
||||
root.add(sec + '.' + cleanup_string(lhs), cleanup_string(rhs), split=split)
|
||||
root.add(sec + '.' + cleanup_string(lhs), cleanup_string(rhs), split = split)
|
||||
return root
|
||||
|
||||
def _read_lines_from_one_path(path: str, throw=True, level=0, log_prio=INFO, paths_buf=None):
|
||||
def _read_lines_from_one_path(
|
||||
path: str, throw = True, level = 0, log_prio = INFO, paths_buf = None
|
||||
):
|
||||
try:
|
||||
with open(path, 'r') as infile:
|
||||
slog(log_prio, 'Reading {}"{}"'.format(' ' * level * 2, path))
|
||||
if paths_buf is not None:
|
||||
paths_buf.append(path)
|
||||
ret = []
|
||||
for line in infile: # lines are all trailed by \n
|
||||
for line in infile: # lines are all trailed by \n
|
||||
m = re.search(r'^\s*(-)*include\s+(\S+)', line)
|
||||
if m:
|
||||
optional = m.group(1) == '-'
|
||||
|
|
@ -86,7 +92,12 @@ def _read_lines_from_one_path(path: str, throw=True, level=0, log_prio=INFO, pat
|
|||
dir_name = os.path.dirname(path)
|
||||
if len(dir_name):
|
||||
include_path = dir_name + '/' + include_path
|
||||
include_lines = _read_lines(include_path, throw=(not optional), level=level+1, paths_buf=paths_buf)
|
||||
include_lines = _read_lines(
|
||||
include_path,
|
||||
throw = (not optional),
|
||||
level = level + 1,
|
||||
paths_buf = paths_buf
|
||||
)
|
||||
if include_lines is None:
|
||||
slog(DEBUG, f'{path}: Failed to process "{line}"')
|
||||
continue
|
||||
|
|
@ -100,17 +111,26 @@ def _read_lines_from_one_path(path: str, throw=True, level=0, log_prio=INFO, pat
|
|||
raise
|
||||
return None
|
||||
|
||||
def _read_lines(path: str, throw=True, level=0, log_prio=INFO, paths_buf=None):
|
||||
def _read_lines(path: str, throw = True, level = 0, log_prio = INFO, paths_buf = None):
|
||||
paths = glob.glob(path)
|
||||
ret = []
|
||||
for p in paths:
|
||||
rr = _read_lines_from_one_path(p, throw=throw, level=level, log_prio=log_prio, paths_buf=paths_buf)
|
||||
rr = _read_lines_from_one_path(
|
||||
p, throw = throw, level = level, log_prio = log_prio, paths_buf = paths_buf
|
||||
)
|
||||
if rr is None:
|
||||
return None
|
||||
ret.extend(rr)
|
||||
return ret
|
||||
|
||||
def read(path: str, root_content: str='root', log_prio=INFO, paths_buf=None) -> StringTree: # export
|
||||
lines = _read_lines_from_one_path(path, log_prio=log_prio, paths_buf=paths_buf)
|
||||
def read( # export
|
||||
path: str,
|
||||
root_content: str = 'root',
|
||||
log_prio = INFO,
|
||||
paths_buf = None
|
||||
) -> StringTree:
|
||||
lines = _read_lines_from_one_path(path, log_prio = log_prio, paths_buf = paths_buf)
|
||||
if lines is None:
|
||||
raise Exception(f'Could not read ini file from "{path}"')
|
||||
s = ''.join(lines)
|
||||
return parse(s, root_content=root_content)
|
||||
return parse(s, root_content = root_content)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue