# Copyright (c) 2016-2022 Intra2net AG <info@intra2net.com>
"""
-store: implementations of CNF stores using varlink and *et_cnf binaries.
+store: implementations of CNF stores using varlink and `*et_cnf` binaries.
-Featuring
-- CnfStore: the main store class that is implemented using the varlink API
+Featuring:
+ - CnfStore: the main store class that is implemented using the varlink API
+ - BinaryCnfStore: alternative store class implementation using the `set_cnf`
+ and `get_cnf` binaries
-- BinaryCnfStore: alternative store class implementation using the set_ and
-get_cnf binaries
+.. seealso:: Overview Diagram linked to from doc main page
.. codeauthor:: Intra2net
"""
:param bool fix_problems: whether to automatically fix errors in the vars
.. note:: you can mix variables to insert and variables to update
- in the same list as the system should handle it nicely
+ in the same list as the system should handle it nicely
Example::
store = CnfStore()
class BinaryCnfStore(CnfStore):
- """Implementation of the CNF store that uses get_ and set_cnf."""
+ """Implementation of the CNF store that uses `get_cnf` and `set_cnf`."""
#: how much to wait for arnied to report running
ARNIED_TIMEOUT = 30
"""
log.debug("Querying BinaryCnfStore with name=%s and instance=%s",
name, instance)
- output = self._driver.get_cnf(name, instance)
+ output = self._driver.get_cnf(name, instance=instance)
if len(output) == 0:
# otherwise cnfvar raises a generic Malformed exception
:param bool fix_problems: whether to automatically fix errors in the vars
.. note:: you can mix variables to insert and variables to update
- in the same list as the system should handle it nicely
+ in the same list as the system should handle it nicely
Example::
store = CnfStore()
cnf = self._cnf_or_list(cnf, operation="commit")
self._autofix_instances(cnf)
- # set_cnf is demaning on lineno's
+ # set_cnf is demanding on lineno's
cnf.renumber()
log.debug("Committing variables via binaries:\n%s", cnf)
if any((c.parent is not None for c in cnf)):
raise RuntimeError("Calling delete is only supported on top-level CNF variables")
- # set_cnf is demaning on lineno's
+ # set_cnf is demanding on lineno's
cnf.renumber()
log.debug("Deleting variables via binaries:\n%s", cnf)
return fn(*args, **kwargs)
+#: pattern for more verbose error message for :py:class:`CommitException`
+COMMIT_EXCEPTION_MESSAGE = """\
+Error committing CNF variables!
+----------------------------
+Input:
+{cnfvars}
+----------------------------
+Error:
+{msg}
+"""
+
+
class CommitException(Exception):
"""Custom exception for commit errors."""
:type cnfvars: CnfList
:param str msg: error message
"""
- self.message = f"""\
-Error committing CNF variables!
-----------------------------
-Input:
-{cnfvars}
-----------------------------
-Error:
-{msg}
-"""
super().__init__(msg)
+ self.message = COMMIT_EXCEPTION_MESSAGE.format(cnfvars=cnfvars, msg=msg)