fix bug #244 by printing an error when some non-unique directory names are
used in the custom_services_dir setting (Boeing r1841)
This commit is contained in:
parent
422ecab341
commit
1ab6be9625
2 changed files with 13 additions and 3 deletions
|
@ -46,6 +46,9 @@ class CoreServices(ConfigurableManager):
|
||||||
'''
|
'''
|
||||||
_name = "services"
|
_name = "services"
|
||||||
_type = coreapi.CORE_TLV_REG_UTILITY
|
_type = coreapi.CORE_TLV_REG_UTILITY
|
||||||
|
|
||||||
|
_invalid_custom_names = ('core', 'addons', 'api', 'bsd', 'emane', 'misc',
|
||||||
|
'netns', 'phys', 'services', 'xen')
|
||||||
|
|
||||||
def __init__(self, session):
|
def __init__(self, session):
|
||||||
ConfigurableManager.__init__(self, session)
|
ConfigurableManager.__init__(self, session)
|
||||||
|
@ -72,10 +75,11 @@ class CoreServices(ConfigurableManager):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
parentdir, childdir = os.path.split(path)
|
parentdir, childdir = os.path.split(path)
|
||||||
if childdir == "services":
|
if childdir in self._invalid_custom_names:
|
||||||
raise ValueError, "use a unique custom services dir name, " \
|
raise ValueError, "use a unique custom services dir name, " \
|
||||||
"not 'services'"
|
"not '%s'" % childdir
|
||||||
sys.path.append(parentdir)
|
if not parentdir in sys.path:
|
||||||
|
sys.path.append(parentdir)
|
||||||
exec("from %s import *" % childdir)
|
exec("from %s import *" % childdir)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.session.warn("error importing custom services from " \
|
self.session.warn("error importing custom services from " \
|
||||||
|
|
|
@ -1640,6 +1640,12 @@ defines the service; then the `custom_services_dir` entry must be set
|
||||||
in the :file:`/etc/core/core.conf` configuration file. A sample is provided in
|
in the :file:`/etc/core/core.conf` configuration file. A sample is provided in
|
||||||
the :file:`myservices/` directory.
|
the :file:`myservices/` directory.
|
||||||
|
|
||||||
|
.. NOTE::
|
||||||
|
The directory name used in `custom_services_dir` should be unique and
|
||||||
|
should not correspond to
|
||||||
|
any existing Python module name. For example, don't use the name `subprocess`
|
||||||
|
or `services`.
|
||||||
|
|
||||||
If you have created a new service type that may be useful to others, please
|
If you have created a new service type that may be useful to others, please
|
||||||
consider contributing it to the CORE project.
|
consider contributing it to the CORE project.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue