Page MenuHomePhorge

Remove devel PATH setting from kolab cli
Needs RevisionPublic

Authored by fjl on Sep 17 2018, 11:13 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 8, 9:12 AM
Unknown Object (File)
Mon, Apr 1, 2:32 PM
Unknown Object (File)
Fri, Mar 29, 11:11 PM
Unknown Object (File)
Fri, Mar 29, 2:07 PM
Unknown Object (File)
Thu, Mar 28, 11:59 AM
Unknown Object (File)
Mar 8 2024, 5:42 PM
Unknown Object (File)
Jan 31 2024, 11:08 PM
Unknown Object (File)
Jan 30 2024, 1:40 AM
Subscribers

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
Tests Skipped

Event Timeline

vanmeeuwen subscribed.

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

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.

To not void running from source directly, I'd insert an:

import os

if os.path.isdir(os.path.join(os.path.dirname(__file__), '.git')):
    sys.path = [ '.' ] + sys.path
This revision now requires changes to proceed.May 17 2019, 10:02 AM