Commits vergleichen

..

Keine gemeinsamen Commits. "8dbb67faf82d7f85dd1d79e44b381f3dc487835b" und "768713aadca5b20b5293d8dc05a683e6f548d1ad" haben vollständig unterschiedliche Historien.

4 geänderte Dateien mit 50 neuen und 89 gelöschten Zeilen

Datei anzeigen

@ -1,7 +1,7 @@
--- ---
namespace: sebastian namespace: sebastian
name: base name: base
version: 0.3.0 version: 0.2.0
readme: README.md readme: README.md

Datei anzeigen

@ -19,90 +19,36 @@ SYSTEMD_SERVICE_CONFIG = SYSTEMD_CONFIG_ROOT / "system"
AnsibleParameter = Dict[str, Any] AnsibleParameter = Dict[str, Any]
def wrap_func(func, **updates): class _Type:
def wrapper(*args, **kwargs): def __dir__(self) -> tuple: # pragma: nocover
return func(*args, **kwargs) return (
"str",
attrs = frozenset( "bool",
('__module__', '__name__', '__qualname__', '__doc__', '__annotations__', '__type_params__') "int",
) - frozenset(updates.keys()) "float",
for attr in attrs: "path",
try: "raw",
value = getattr(func, attr) "jsonarg",
except AttributeError: "json",
pass "bytes",
else: "dict",
print(f"changing:\n {value}\n {getattr(wrapper, attr)}") "list",
setattr(wrapper, attr, value) "bits",
for attr, value in updates.items(): "__doc__",
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",
)
) )
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( def list(
self,
elements: Union[Type[object], str, AnsibleParameter], elements: Union[Type[object], str, AnsibleParameter],
required: bool = False, required: bool = False,
help: Optional[str] = None, help: Optional[str] = None,
) -> AnsibleParameter: ) -> 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) option: AnsibleParameter = dict(type="list", required=required)
if not isinstance(elements, (str, dict)): if not isinstance(elements, (str, dict)):
option["elements"] = elements.__name__ option["elements"] = elements.__name__
@ -121,20 +67,37 @@ class Types(metaclass=meta):
option["description"] = help.split("\n") option["description"] = help.split("\n")
return option return option
def dict(required: bool = False, help: Optional[str] = None, **options: AnsibleParameter) -> AnsibleParameter: def dict(self, required: bool = False, help: Optional[str] = None, **options: dict) -> 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
"""
option: AnsibleParameter = dict(type="dict", required=required) option: AnsibleParameter = dict(type="dict", required=required)
option["option"] = options option["option"] = options
if help is not None: if help is not None:
option["description"] = help.split("\n") option["description"] = help.split("\n")
return option 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: def systemdbool(b: Union[bool, str]) -> str:
"""Converts values into things systemd can parse""" """Converts values into things systemd can parse"""

Datei anzeigen

@ -1 +1 @@
__version__ = "0.3.0" __version__ = "0.2.0"

Datei anzeigen

@ -8,8 +8,6 @@ upload(){
printf "uploading: %s as %s\n" "$1" "$name" 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" 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" upload "$file"
done done
rm -f dist/sebastian*
hatch publish -r ansible