Refactor ome-python code.

1. use ipython if ipython is available.
2. refactor code to a single function.