mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-04-25 10:25:55 +02:00
stree.serdes: Support glob patterns for includes
Allow -include /some/dir/app.d/*.conf style includes. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
bdb7127d27
commit
1347a34481
1 changed files with 13 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import os, glob
|
||||
|
||||
from jwutils.stree.StringTree import *
|
||||
from jwutils.log import *
|
||||
|
|
@ -70,7 +70,7 @@ def parse(s: str, allow_full_lines: bool=True, root_content: str='root') -> Stri
|
|||
root.add(sec + '.' + cleanup_string(lhs), cleanup_string(rhs), split=split)
|
||||
return root
|
||||
|
||||
def _read_lines(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))
|
||||
|
|
@ -102,7 +102,17 @@ def _read_lines(path: str, throw=True, level=0, log_prio=INFO, paths_buf=None):
|
|||
slog(DEBUG, msg)
|
||||
return 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)
|
||||
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(path, log_prio=log_prio, paths_buf=paths_buf)
|
||||
lines = _read_lines_from_one_path(path, log_prio=log_prio, paths_buf=paths_buf)
|
||||
s = ''.join(lines)
|
||||
return parse(s, root_content=root_content)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue