mirror of
https://github.com/containers/podman.git
synced 2025-06-17 23:20:59 +08:00

- Added alias 'container()' to image model for CreateContainer() - Fixed return in containers_create.go to wrap error in varlink exception - Added a wait time to container.kill(), number of seconds to wait for the container to change state - Refactored cached_property() to use system libraries - Refactored tests to speed up performance Signed-off-by: Jhon Honce <jhonce@redhat.com> Closes: #821 Approved by: rhatdan
55 lines
1.3 KiB
Python
55 lines
1.3 KiB
Python
"""Support files for podman API implementation."""
|
|
import datetime
|
|
import functools
|
|
|
|
from dateutil.parser import parse as dateutil_parse
|
|
|
|
__all__ = [
|
|
'cached_property',
|
|
'datetime_parse',
|
|
'datetime_format',
|
|
]
|
|
|
|
|
|
def cached_property(fn):
|
|
"""Cache return to save future expense."""
|
|
return property(functools.lru_cache(maxsize=8)(fn))
|
|
|
|
|
|
# Cannot subclass collections.UserDict, breaks varlink
|
|
class Config(dict):
|
|
"""Silently ignore None values, only take key once."""
|
|
|
|
def __init__(self, **kwargs):
|
|
"""Construct dictionary."""
|
|
super(Config, self).__init__(kwargs)
|
|
|
|
def __setitem__(self, key, value):
|
|
"""Store unique, not None values."""
|
|
if value is None:
|
|
return
|
|
|
|
if super().__contains__(key):
|
|
return
|
|
|
|
super().__setitem__(key, value)
|
|
|
|
|
|
def datetime_parse(string):
|
|
"""Convert timestamps to datetime.
|
|
|
|
tzinfo aware, if provided.
|
|
"""
|
|
return dateutil_parse(string.upper(), fuzzy=True)
|
|
|
|
|
|
def datetime_format(dt):
|
|
"""Format datetime in consistent style."""
|
|
if isinstance(dt, str):
|
|
return datetime_parse(dt).isoformat()
|
|
elif isinstance(dt, datetime.datetime):
|
|
return dt.isoformat()
|
|
else:
|
|
raise ValueError('Unable to format {}. Type {} not supported.'.format(
|
|
dt, type(dt)))
|