I followed the tutorial for CORBA development in Python available in the: omniORBpy User’s Guide
After I have generated the Python files from given IDL file, I noticed that init.py
from packages Example and Example__POA is trying to import file echo_example_idl.py
, which is placed one level below. Directory tree looks as follows:
---Example (module)
|
|------ init.py
|
---Example__POA (module)
|
|------ init.py
|
---echo_example_idl.py
---echo_example.idl
---example_execution.py
Content of init.py from Example module:
# DO NOT EDIT THIS FILE!
#
# Python module Example generated by omniidl
import omniORB
omniORB.updateModule("Example")
# ** 1. Stub files contributing to this module
import echo_example_idl
# ** 2. Sub-modules
# ** 3. End
Content of example_execution.py:
#!/usr/bin/env python
import sys
from omniORB import CORBA, PortableServer
import Example, Example__POA
class Echo_i (Example__POA.Echo):
def echoString(self, mesg):
print "echoString() called with message:", mesg
return mesg
orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
poa = orb.resolve_initial_references("RootPOA")
ei = Echo_i()
eo = ei._this()
poaManager = poa._get_the_POAManager()
poaManager.activate()
message = "Hello"
result = eo.echoString(message)
print "I said '%s'. The object said '%s'." % (message,result)
I can launch the program with success.
How come the import statement inside init.py for both modules works properly? Is it because I run the example_execution.py inside the same directory as source files generated via omniidl?
How should I proceed if I want to have execution file outside the directory with source files (for example in one directory I want to have all CORBA sources and in another I want to keep example_execution.py file). If I do this I will get an ImportError for echo_example_idl.py
I was able to solve this issue. The solution is to generate the CORBA stubs and client/server modules inside a Python module. This can be done via passing proper flags to omniidl program. In my case it was:
omniidl -bpython -Wbpackage=example example_echo.idl
Thanks to that my directory tree looks as follows (including files for execution and IDL file itself):
---example (Python module)
|
|------Example (CORBA client module)
|------Example__POA (CORBA server module)
|------echo_example.idl.py
|
---echo_example.idl
---example_execution.py
If I want to use the CORBA functionality I just need to add import example
at the top of file.