Review: a few fixes
[pyi2ncommon] / src / cnfvar / store.py
index 9872c16..0bfeb26 100644 (file)
 # 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
 """
@@ -89,7 +90,7 @@ class CnfStore:
         :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()
@@ -241,7 +242,7 @@ class 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
@@ -272,7 +273,7 @@ class BinaryCnfStore(CnfStore):
         """
         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
@@ -289,7 +290,7 @@ class BinaryCnfStore(CnfStore):
         :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()
@@ -301,7 +302,7 @@ class BinaryCnfStore(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)
 
@@ -330,7 +331,7 @@ class BinaryCnfStore(CnfStore):
         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)
 
@@ -353,6 +354,18 @@ class BinaryCnfStore(CnfStore):
         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."""
 
@@ -364,13 +377,5 @@ class CommitException(Exception):
         :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)