[sandbox 07/11] virt-sandbox-image: smarter source name computing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To compute the source class name from the URI scheme, we need to be a
bit smarter to have a nice scheme for sources like the virt-builder one.
In order to have a scheme like virt-builder:// and a class name like
VirtBuilderSource, strip the non-word characters from the scheme and
camel case the words.
---
 libvirt-sandbox/image/template.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libvirt-sandbox/image/template.py b/libvirt-sandbox/image/template.py
index 17da6c0..4713b0a 100644
--- a/libvirt-sandbox/image/template.py
+++ b/libvirt-sandbox/image/template.py
@@ -21,6 +21,7 @@
 
 import urlparse
 import importlib
+import re
 
 class Template(object):
 
@@ -56,10 +57,13 @@ class Template(object):
             self.params = {}
 
     def get_source_impl(self):
+        p = re.compile("\W")
+        sourcename = "".join([i.capitalize() for i in p.split(self.source)])
+
         mod = importlib.import_module(
             "libvirt_sandbox.image.sources." +
-            self.source.capitalize() + "Source")
-        classname = self.source.capitalize() + "Source"
+            sourcename + "Source")
+        classname = sourcename + "Source"
         classimpl = getattr(mod, classname)
         return classimpl()
 
-- 
2.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]