sdbus++: handle error names in Python code

Simplify and de-duplicate the code to turn an error identifier into
a class name by moving it from Mako templates into Python.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I8d4e011dfef3508e85b79fd7af8b33e07e3761a1
diff --git a/tools/sdbusplus/interface.py b/tools/sdbusplus/interface.py
index 461b987..e766a86 100644
--- a/tools/sdbusplus/interface.py
+++ b/tools/sdbusplus/interface.py
@@ -44,6 +44,10 @@
             includes.append(f"{n}/error.hpp")
         return sorted(set(includes))
 
+    def errorNamespacedClass(self, error):
+        error = error.replace("self.", self.name + ".")
+        return "sdbusplus::" + "::".join(error.split("."))
+
     def enum_includes(self, inc_list):
         includes = []
         for e in inc_list:
diff --git a/tools/sdbusplus/templates/method.prototype.hpp.mako b/tools/sdbusplus/templates/method.prototype.hpp.mako
index ec0f3dc..6cfe02d 100644
--- a/tools/sdbusplus/templates/method.prototype.hpp.mako
+++ b/tools/sdbusplus/templates/method.prototype.hpp.mako
@@ -1,14 +1,3 @@
-<%
-    def error_namespace(e):
-        n = e.split('.');
-        n.pop(); # Remove error name.
-
-        n = map((lambda x: interface.name if x == "self" else x), n);
-        return '::'.join('.'.join(n).split('.'));
-
-    def error_name(e):
-        return e.split('.').pop();
-%>
 ###
 ### Emit 'header'
 ###
@@ -80,7 +69,7 @@
                 ));
     }
     % for e in method.errors:
-    catch(const sdbusplus::${error_namespace(e)}::${error_name(e)}& e)
+    catch(const ${interface.errorNamespacedClass(e)}& e)
     {
         return o->get_bus().getInterface()->sd_bus_error_set(error, e.name(), e.description());
     }
diff --git a/tools/sdbusplus/templates/property.prototype.hpp.mako b/tools/sdbusplus/templates/property.prototype.hpp.mako
index f8da663..ec54869 100644
--- a/tools/sdbusplus/templates/property.prototype.hpp.mako
+++ b/tools/sdbusplus/templates/property.prototype.hpp.mako
@@ -1,14 +1,3 @@
-<%
-    def error_namespace(e):
-        n = e.split('.');
-        n.pop(); # Remove error name.
-
-        n = map((lambda x: interface.name if x == "self" else x), n);
-        return '::'.join('.'.join(n).split('.'));
-
-    def error_name(e):
-        return e.split('.').pop();
-%>
 % if ptype == 'callback-cpp':
 auto ${interface.classname}::${property.camelCase}() const ->
         ${property.cppTypeParam(interface.name)}
@@ -35,7 +24,7 @@
                 ));
     }
     % for e in property.errors:
-    catch(const sdbusplus::${error_namespace(e)}::${error_name(e)}& e)
+    catch(const ${interface.errorNamespacedClass(e)}& e)
     {
         return o->get_bus().getInterface()->sd_bus_error_set(error, e.name(), e.description());
     }
@@ -89,7 +78,7 @@
                 ));
     }
     % for e in property.errors:
-    catch(const sdbusplus::${error_namespace(e)}::${error_name(e)}& e)
+    catch(const ${interface.errorNamespacedClass(e)}& e)
     {
         return o->get_bus().getInterface()->sd_bus_error_set(error, e.name(), e.description());
     }