Remove devel PATH setting from kolab cli
Needs ReviewPublic

Authored by fjl on Sep 17 2018, 11:13 AM.

Details

Reviewers
vanmeeuwen
Group Reviewers
PyKolab Developers
Summary

/usr/sbin/kolab prepends a dot to the system path. According to an inline comment, this seems to be done for development purposes. We stumbled across this when the plugins mechanism in plugins/__init__.py is importing the pdb debugger (is there really a need for this?) and pdb in turn imports a python module named cmd. If you happen to have a different module by this name in the current directory, the kolab command fails badly:

Traceback (most recent call last):
  File "/usr/sbin/kolab", line 29, in <module>
    from pykolab.cli import Cli
  File "/usr/lib/python2.7/dist-packages/pykolab/cli/__init__.py", line 33, in <module>
    import pykolab.plugins
  File "/usr/lib/python2.7/dist-packages/pykolab/plugins/__init__.py", line 22, in <module>
    import pdb
  File "/usr/lib/python2.7/pdb.py", line 59, in <module>
    class Pdb(bdb.Bdb, cmd.Cmd):
AttributeError: 'module' object has no attribute 'Cmd'

This patch simply comments the path manipulation.

Diff Detail

Repository
rP pykolab
Lint
Lint Skipped
Unit
Unit Tests Skipped
fjl created this revision.Sep 17 2018, 11:13 AM
fjl updated this revision to Diff 1568.Sep 17 2018, 11:19 AM
vanmeeuwen requested changes to this revision.Sep 17 2018, 11:20 AM
vanmeeuwen added a subscriber: vanmeeuwen.

The better solution may be to try/except the import of pdb, preserving the existing functionality while avoiding this error.

Could you tell me more about the version of python and the operating system under which this error is generated? It seems to me there's a faulty use of cmd inside of the pdb python module, separately from its use by the kolab plugins module.

This revision now requires changes to proceed.Sep 17 2018, 11:20 AM
fjl added a comment.Sep 17 2018, 11:34 AM

This is on CoreBiz 7, which is based on Ubuntu 16.04, running Python 2.7. We have a python-based "CoreBiz Management Daemon" which resides in /usr/lib/python2.7/dist-packages/lisag/cmd/. Usually, there is no conflict with pdb etc., only if the working directory happens to be /usr/lib/python2.7/dist-packages/lisag/cmd/ which is the case for our Daemon, and it then calls the kolab tool. This makes python load the wrong cmd module. I don't think there is a faulty use of cmd inside of the pdb python module.

This error was basically to showcase that prepending a dot makes the tool fail in certain situations. Perhaps you could add some kind of development option to the kolab cli that prepends the dot if it is required.

fjl requested review of this revision.Sep 17 2018, 9:00 PM
In D686#7436, @fjl wrote:

Perhaps you could add some kind of development option to the kolab cli that prepends the dot if it is required.

Much simpler: change the path in the shell before calling the kolab tool. This comes without side effects for other users;-)

So I'd suggest to apply the patch as it is.