mirror of
ssh://devgit.janware.com/janware/proj/jw-python
synced 2026-06-18 02:26:39 +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,11 +1,13 @@
|
|||
import re
|
||||
import json
|
||||
from collections import OrderedDict
|
||||
from .log import *
|
||||
import re
|
||||
import shlex
|
||||
import traceback
|
||||
|
||||
class Options: # export
|
||||
from collections import OrderedDict
|
||||
|
||||
from .log import ERR, get_caller_pos, slog, slog_m
|
||||
|
||||
class Options: # export
|
||||
|
||||
class OrderedData:
|
||||
|
||||
|
|
@ -30,8 +32,8 @@ class Options: # export
|
|||
if spec[0] != '{':
|
||||
spec = '{' + spec + '}'
|
||||
try:
|
||||
return json.loads(spec, object_pairs_hook=cls)
|
||||
except:
|
||||
return json.loads(spec, object_pairs_hook = cls)
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
|
|
@ -42,7 +44,7 @@ class Options: # export
|
|||
r = cls()
|
||||
try:
|
||||
opt_strs = shlex.split(opts_str)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
slog_m(ERR, traceback.format_exc())
|
||||
slog(ERR, 'Failed to split options string >{}<'.format(opts_str))
|
||||
raise
|
||||
|
|
@ -52,7 +54,7 @@ class Options: # export
|
|||
lhs = sides[0].strip()
|
||||
if not len(lhs):
|
||||
continue
|
||||
if self.__allowed_keys and not lhs in self.__allowed_keys:
|
||||
if self.__allowed_keys and lhs not in self.__allowed_keys:
|
||||
raise Exception('Field "{}" not supported'.format(lhs))
|
||||
rhs = ' '.join(sides[1:]).strip() if len(sides) > 1 else self.__true_val
|
||||
if cls == OrderedDict:
|
||||
|
|
@ -82,7 +84,7 @@ class Options: # export
|
|||
self.__str = self.__str__()
|
||||
|
||||
def __getitem__(self, key):
|
||||
if not key in self.__dict.keys():
|
||||
if key not in self.__dict.keys():
|
||||
return None
|
||||
return self.__dict[key]
|
||||
|
||||
|
|
@ -99,35 +101,38 @@ class Options: # export
|
|||
return len(self.__data.pairs)
|
||||
|
||||
def __contains__(self, keys):
|
||||
if not type(keys) in [list, set]:
|
||||
if type(keys) not in [list, set]:
|
||||
return keys in self.__dict.keys()
|
||||
for key in keys:
|
||||
if not key in self.__dict.keys():
|
||||
if key not in self.__dict.keys():
|
||||
return False
|
||||
return True
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.__list)
|
||||
|
||||
def __next__(self):
|
||||
return next(self.__list)
|
||||
#def __next__(self):
|
||||
# return next(self.__list)
|
||||
|
||||
def __init__(self, spec=None, delimiter=',', allowed_keys=None, true_val=True):
|
||||
def __init__(
|
||||
self, spec = None, delimiter = ',', allowed_keys = None, true_val = True
|
||||
):
|
||||
self.__true_val = true_val
|
||||
self.__allowed_keys = None
|
||||
self.__delimiter = delimiter
|
||||
self.__data = self.OrderedData() if spec is None else self.__parse(spec, self.OrderedData)
|
||||
self.__data = self.OrderedData(
|
||||
) if spec is None else self.__parse(spec, self.OrderedData)
|
||||
self.__dict = {}
|
||||
#self.__dict = OrderedDict() if spec is None else self.__parse(spec, OrderedDict)
|
||||
#self.__dict = OrderedDict() if spec is None else self.__parse(spec,OrderedDict)
|
||||
self.__list = []
|
||||
self.__str = None
|
||||
self.__recache()
|
||||
|
||||
def dump(self, prio, caller=None):
|
||||
def dump(self, prio, caller = None):
|
||||
if caller is None:
|
||||
caller = get_caller_pos()
|
||||
for key, val in self.__data.pairs:
|
||||
slog(prio, "{}=\"{}\"".format(key, val), caller=caller)
|
||||
slog(prio, "{}=\"{}\"".format(key, val), caller = caller)
|
||||
|
||||
def keys(self):
|
||||
return self.__dict.keys()
|
||||
|
|
@ -136,22 +141,28 @@ class Options: # export
|
|||
#return self.__dict.items()
|
||||
return self.__data.pairs
|
||||
|
||||
def get(self, key, default=None, by_index=False):
|
||||
def get(self, key, default = None, by_index = False):
|
||||
if by_index:
|
||||
if type(key) != int:
|
||||
raise KeyError('Tried to get value from options string with ' +
|
||||
'index {} of type "{}": {}'.format(key, type(key), str(self)))
|
||||
if isinstance(key, int):
|
||||
raise KeyError(
|
||||
'Tried to get value from options string with ' +
|
||||
'index {} of type "{}": {}'.format(key, type(key), str(self))
|
||||
)
|
||||
if key >= len(self.__data.pairs):
|
||||
if default is not None:
|
||||
return default
|
||||
raise KeyError('Tried to get value from options string with ' +
|
||||
'index {} of {}: {}'.format(key, len(self.__data.pairs), str(self)))
|
||||
raise KeyError(
|
||||
'Tried to get value from options string with ' +
|
||||
'index {} of {}: {}'.format(key, len(self.__data.pairs), str(self))
|
||||
)
|
||||
return self.__list[key]
|
||||
if key in self.__dict.keys():
|
||||
return self.__dict[key]
|
||||
if default is not None:
|
||||
return default
|
||||
raise KeyError('Key "{}" is not present in options string: {}'.format(key, str(self)))
|
||||
raise KeyError(
|
||||
'Key "{}" is not present in options string: {}'.format(key, str(self))
|
||||
)
|
||||
|
||||
def update(self, rhs):
|
||||
if hasattr(rhs, 'items'):
|
||||
|
|
@ -159,9 +170,13 @@ class Options: # export
|
|||
self.__dict[key] = val
|
||||
return
|
||||
if isinstance(rhs, str):
|
||||
self.update(self.__parse(rhs))
|
||||
self.update(self.__parse(rhs, self.OrderedData))
|
||||
return
|
||||
raise Exception('Tried to update options with object of incompatible type {}'.format(type(rhs)))
|
||||
raise Exception(
|
||||
'Tried to update options with object of incompatible type {}'.format(
|
||||
type(rhs)
|
||||
)
|
||||
)
|
||||
|
||||
def append_to(self, obj):
|
||||
for opt in self.__list:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue