diff options
author | Jhon Honce <jhonce@redhat.com> | 2018-07-12 19:26:14 -0700 |
---|---|---|
committer | Jhon Honce <jhonce@redhat.com> | 2018-07-13 12:50:12 -0700 |
commit | 74ccd9ce5f29a1df4ffe70b4d8bd00c29d5d9d15 (patch) | |
tree | 75ba256d70545d79aa61d7c57c20df886be1555f /contrib/python/pypodman/lib/action_base.py | |
parent | 44b523c946c88e540b50d7ba59f441b5f8e0bad0 (diff) | |
download | podman-74ccd9ce5f29a1df4ffe70b4d8bd00c29d5d9d15.tar.gz podman-74ccd9ce5f29a1df4ffe70b4d8bd00c29d5d9d15.tar.bz2 podman-74ccd9ce5f29a1df4ffe70b4d8bd00c29d5d9d15.zip |
Update python directories to better support setup.py
Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'contrib/python/pypodman/lib/action_base.py')
-rw-r--r-- | contrib/python/pypodman/lib/action_base.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/contrib/python/pypodman/lib/action_base.py b/contrib/python/pypodman/lib/action_base.py new file mode 100644 index 000000000..ff2922262 --- /dev/null +++ b/contrib/python/pypodman/lib/action_base.py @@ -0,0 +1,84 @@ +"""Base class for all actions of remote client.""" +import abc +from functools import lru_cache + +import podman + + +class AbstractActionBase(abc.ABC): + """Base class for all actions of remote client.""" + + @classmethod + @abc.abstractmethod + def subparser(cls, parser): + """Define parser for this action. Subclasses must implement. + + API: + Use set_defaults() to set attributes "class_" and "method". These will + be invoked as class_(parsed_args).method() + """ + parser.add_argument( + '--all', + action='store_true', + help=('list all items.' + ' (default: no-op, included for compatibility.)')) + parser.add_argument( + '--no-trunc', + '--notruncate', + action='store_false', + dest='truncate', + default=True, + help='Display extended information. (default: False)') + parser.add_argument( + '--noheading', + action='store_false', + dest='heading', + default=True, + help=('Omit the table headings from the output.' + ' (default: False)')) + parser.add_argument( + '--quiet', + action='store_true', + help='List only the IDs. (default: %(default)s)') + + def __init__(self, args): + """Construct class.""" + self._args = args + + @property + def remote_uri(self): + """URI for remote side of connection.""" + return self._args.remote_uri + + @property + def local_uri(self): + """URI for local side of connection.""" + return self._args.local_uri + + @property + def identity_file(self): + """Key for authenication.""" + return self._args.identity_file + + @property + @lru_cache(maxsize=1) + def client(self): + """Podman remote client for communicating.""" + if self._args.host is None: + return podman.Client( + uri=self.local_uri) + else: + return podman.Client( + uri=self.local_uri, + remote_uri=self.remote_uri, + identity_file=self.identity_file) + + def __repr__(self): + """Compute the “official” string representation of object.""" + return ("{}(local_uri='{}', remote_uri='{}'," + " identity_file='{}')").format( + self.__class__, + self.local_uri, + self.remote_uri, + self.identity_file, + ) |