Change in vdsm[master]: Adding dynamic_package_load util module for reuseability

ybronhei at redhat.com ybronhei at redhat.com
Mon Feb 8 08:18:17 UTC 2016


Yaniv Bronhaim has posted comments on this change.

Change subject: Adding dynamic_package_load util module for reuseability
......................................................................


Patch Set 4:

(3 comments)

https://gerrit.ovirt.org/#/c/53016/4/lib/vdsm/dynamic_package_load.py
File lib/vdsm/dynamic_package_load.py:

Line 34:     return frozenset(
Line 35:         os.path.splitext(name)[0]
Line 36:         for name in os.listdir(path)
Line 37:         if is_type(name)
Line 38:     )
this one returns file under any path with any suffix for files - easy and small useful func
Line 39: 
Line 40: 
Line 41: def pkg_modules(pkg):
Line 42:     modules = {}


Line 43:     for module in _listfiles(pkg.__path__[0], 'py*'):
Line 44:         modules[module] = _import_module(pkg, module)
Line 45:         if not hasattr(modules[module], 'name'):
Line 46:             setattr(modules[module], 'name', module)
Line 47:     return modules
this one maybe similar to pkgutil but returns a list instead of iterator and set the name attribute if exist, which useful for our implementation
Line 48: 
Line 49: 
Line 50: def pkg_api_funcs(pkg, prefix):
Line 51:     funcs = {}


Line 52:     for module in pkg_modules(pkg).itervalues():
Line 53:         for func in dir(module):
Line 54:             if func.startswith(prefix):
Line 55:                 funcs[func[4:]] = getattr(module, func)
Line 56:     return funcs
and this one returns only func names that start with prefix. even if I'll use pkgutil I'll need to iterate through the output and take only funcs that starts with this prefix.. 
I don't see benefits with using pkgutil . its just not what I look for

for example
 for m in pkgutil.iter_modules(path='./supervdsm_api',  prefix='api_'):
     print m

outputs:
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_API', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_a', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_alignmentScan', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_blkid', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_caps', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_clientIF', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_dumpStorageTable', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_gluster', True)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_hooking', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_hostdev', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_kaxmlrpclib', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_logUtils', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_mkimage', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_momIF', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_numaUtils', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_parted_utils', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_protocoldetector', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_rpc', True)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_sitecustomize', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_storage', True)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_supervdsm_api', True)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_v2v', False)
(<pkgutil.ImpImporter instance at 0x7f61af34fab8>, 'api_virt', True)


-- 
To view, visit https://gerrit.ovirt.org/53016
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ie87a63cfabb32c15376fbb1a06bbb20f3941f220
Gerrit-PatchSet: 4
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Yaniv Bronhaim <ybronhei at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Edward Haas <edwardh at redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Yaniv Bronhaim <ybronhei at redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation at ovirt.org>
Gerrit-HasComments: Yes


More information about the vdsm-patches mailing list