Commits vergleichen
Keine gemeinsamen Commits. "8dbb67faf82d7f85dd1d79e44b381f3dc487835b" und "768713aadca5b20b5293d8dc05a683e6f548d1ad" haben vollständig unterschiedliche Historien.
8dbb67faf8
...
768713aadc
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
namespace: sebastian
|
||||
name: base
|
||||
version: 0.3.0
|
||||
version: 0.2.0
|
||||
|
||||
readme: README.md
|
||||
|
||||
|
|
|
@ -19,90 +19,36 @@ SYSTEMD_SERVICE_CONFIG = SYSTEMD_CONFIG_ROOT / "system"
|
|||
AnsibleParameter = Dict[str, Any]
|
||||
|
||||
|
||||
def wrap_func(func, **updates):
|
||||
def wrapper(*args, **kwargs):
|
||||
return func(*args, **kwargs)
|
||||
|
||||
attrs = frozenset(
|
||||
('__module__', '__name__', '__qualname__', '__doc__', '__annotations__', '__type_params__')
|
||||
) - frozenset(updates.keys())
|
||||
for attr in attrs:
|
||||
try:
|
||||
value = getattr(func, attr)
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
print(f"changing:\n {value}\n {getattr(wrapper, attr)}")
|
||||
setattr(wrapper, attr, value)
|
||||
for attr, value in updates.items():
|
||||
setattr(wrapper, attr, value)
|
||||
wrapper.__dict__.update(func.__dict__)
|
||||
setattr(wrapper, "__wrapped__", func)
|
||||
return wrapper
|
||||
|
||||
|
||||
GENERIC_DOC = """Returns an dictionary for the Ansible {type} type."""
|
||||
|
||||
|
||||
def default(name: str):
|
||||
def wrapped(
|
||||
required: bool = False,
|
||||
help: Optional[str] = None,
|
||||
choices: Optional[Sequence] = None,
|
||||
default: Optional[Any] = None,
|
||||
) -> AnsibleParameter:
|
||||
option: AnsibleParameter = dict(type=name, required=required)
|
||||
if choices is not None:
|
||||
option["choices"] = choices
|
||||
if default is not None:
|
||||
option["default"] = default
|
||||
if help is not None:
|
||||
option["description"] = help.split("\n")
|
||||
return option
|
||||
|
||||
return wrapped
|
||||
|
||||
|
||||
class meta(type):
|
||||
def __new__(cls, clsname, bases, attrs):
|
||||
types = frozenset(
|
||||
(
|
||||
"str",
|
||||
"bool",
|
||||
"int",
|
||||
"float",
|
||||
"path",
|
||||
"raw",
|
||||
"jsonarg",
|
||||
"json",
|
||||
"bytes",
|
||||
"dict",
|
||||
"list",
|
||||
"bits",
|
||||
)
|
||||
class _Type:
|
||||
def __dir__(self) -> tuple: # pragma: nocover
|
||||
return (
|
||||
"str",
|
||||
"bool",
|
||||
"int",
|
||||
"float",
|
||||
"path",
|
||||
"raw",
|
||||
"jsonarg",
|
||||
"json",
|
||||
"bytes",
|
||||
"dict",
|
||||
"list",
|
||||
"bits",
|
||||
"__doc__",
|
||||
)
|
||||
for attr in types - set(attrs.keys()):
|
||||
print(f"adding {attr} function")
|
||||
attrs[attr] = wrap_func(
|
||||
default(attr), __doc__=GENERIC_DOC.format(type=attr), __name__=attr, __qualname__=f"{clsname}.{attr}"
|
||||
)
|
||||
attrs["__slots__"] = ()
|
||||
return super().__new__(cls, clsname, bases, attrs)
|
||||
|
||||
def __repr__(self) -> str: # pragma: nocover
|
||||
return "Types()"
|
||||
|
||||
def __call__(self) -> "_Type": # pragma: nocover
|
||||
return self
|
||||
|
||||
class Types(metaclass=meta):
|
||||
def list(
|
||||
self,
|
||||
elements: Union[Type[object], str, AnsibleParameter],
|
||||
required: bool = False,
|
||||
help: Optional[str] = None,
|
||||
) -> AnsibleParameter:
|
||||
"""Wrapper for the Ansible list type
|
||||
|
||||
Args:
|
||||
elements: The type of the elements
|
||||
required: if the item is absolutly required
|
||||
help: an helptext for the ansible-doc
|
||||
"""
|
||||
option: AnsibleParameter = dict(type="list", required=required)
|
||||
if not isinstance(elements, (str, dict)):
|
||||
option["elements"] = elements.__name__
|
||||
|
@ -121,20 +67,37 @@ class Types(metaclass=meta):
|
|||
option["description"] = help.split("\n")
|
||||
return option
|
||||
|
||||
def dict(required: bool = False, help: Optional[str] = None, **options: AnsibleParameter) -> AnsibleParameter:
|
||||
"""Wrapper for the Ansible dict type
|
||||
|
||||
Args:
|
||||
required: if the item is absolutly required
|
||||
help: an helptext for the ansible-doc
|
||||
options: The individual options that this parameter has
|
||||
"""
|
||||
def dict(self, required: bool = False, help: Optional[str] = None, **options: dict) -> AnsibleParameter:
|
||||
option: AnsibleParameter = dict(type="dict", required=required)
|
||||
option["option"] = options
|
||||
if help is not None:
|
||||
option["description"] = help.split("\n")
|
||||
return option
|
||||
|
||||
def __getattr__(self, name: str):
|
||||
def argument(
|
||||
required: bool = False,
|
||||
help: Optional[str] = None,
|
||||
choices: Optional[Sequence] = None,
|
||||
default: Optional[Any] = None,
|
||||
) -> AnsibleParameter:
|
||||
option: AnsibleParameter = dict(type=name, required=required)
|
||||
if choices is not None:
|
||||
option["choices"] = choices
|
||||
if default is not None:
|
||||
option["default"] = default
|
||||
if help is not None:
|
||||
option["description"] = help.split("\n")
|
||||
return option
|
||||
|
||||
argument.__name__ = name
|
||||
argument.__qualname__ = f"Types.{name}"
|
||||
argument.__doc__ = f"Simple wrapper for Ansible {name} argument dict"
|
||||
return argument
|
||||
|
||||
|
||||
Types = _Type()
|
||||
|
||||
|
||||
def systemdbool(b: Union[bool, str]) -> str:
|
||||
"""Converts values into things systemd can parse"""
|
||||
|
|
|
@ -1 +1 @@
|
|||
__version__ = "0.3.0"
|
||||
__version__ = "0.2.0"
|
||||
|
|
|
@ -8,8 +8,6 @@ upload(){
|
|||
printf "uploading: %s as %s\n" "$1" "$name"
|
||||
curl -u sebastian --upload-file "$1" "https://gitea.sebastian-tobie.de/api/packages/ansible/generic/${package}/${version}/$name"
|
||||
}
|
||||
for file in dist/sebastian* ; do
|
||||
for file in dist/* ; do
|
||||
upload "$file"
|
||||
done
|
||||
rm -f dist/sebastian*
|
||||
hatch publish -r ansible
|
||||
|
|
Laden…
In neuem Issue referenzieren