Bug#901484: targetcli aborts with the error message "NameError: name 'readline' is not defined" when running in interactive shell mode

2018-06-13 Thread Ritesh Raj Sarraf
Control: tag -1 +confirmed, pending


Oh! I looked at the newer unreleased sources in our repository. This
fix is included in the latest import that Christophe has prepared,
currently pending an upload to the repository.

python-configshell-fb (1.1.24-1) UNRELEASED; urgency=medium

  * New upstream version.

 -- Christophe Vu-Brugier   Sun, 28 Jan 2018 18:03:36 
+0100


On Thu, 2018-06-14 at 10:21 +0545, Ritesh Raj Sarraf wrote:
> Control: tag -1 +moreinfo
> 
> On Wed, 2018-06-13 at 17:06 -0400, Matt Coleman wrote:
> > Error Output:
> > 
> > Traceback (most recent call last):
> >   File "/usr/lib/python3/dist-packages/configshell_fb/shell.py",
> > line
> > 893, in run_interactive
> > old_completer = readline.get_completer()
> > NameError: name 'readline' is not defined
> > 
> > During handling of the above exception, another exception occurred:
> > 
> > Traceback (most recent call last):
> >   File "/usr/bin/targetcli", line 121, in 
> > main()
> >   File "/usr/bin/targetcli", line 111, in main
> > shell.run_interactive()
> >   File "/usr/lib/python3/dist-packages/configshell_fb/shell.py",
> > line
> > 899, in run_interactive
> > readline.set_completer(old_completer)
> > NameError: name 'readline' is not defined
> >  in /home/matt/reproduce/vendor/symfony/ in
> > /home/matt/reproduce/vendor/symfony/symfony/src/Symfony/Component/P
> > ro
> > cess/Process.php on line 239
> 
> I think there may be something non-standard in your setup.
> 
> Because:
> 
> if sys.stdout.isatty():
> import readline
> tty=True
> else:
> tty=False
> 
> # remember the original setting
> oldTerm = os.environ.get('TERM')
> os.environ['TERM'] = ''
> 
> import readline
> 
> # restore the orignal TERM setting
> if oldTerm != None:
> os.environ['TERM'] = oldTerm
> del oldTerm
> 
> In either case, readline needs to be imported.
> 
> readline supported is provided through package libpython2.7-
> stdlib:amd64 for Python2.
> 
> @Matt:
> 
> Are you able to import the readline module on the standard python
> interpreter ?
> 
> Here, on my setup, I can:
> 
> $ ipython
> Python 2.7.15 (default, May  1 2018, 05:55:50) 
> Type "copyright", "credits" or "license" for more information.
> 
> IPython 5.5.0 -- An enhanced Interactive Python.
> ? -> Introduction and overview of IPython's features.
> %quickref -> Quick reference.
> help  -> Python's own help system.
> object?   -> Details about 'object', use 'object??' for extra
> details.
> [TerminalIPythonApp] WARNING | File not found: '/home/rrs/.pythonrc'
> 
> In [1]: import readline
> 
> In [2]: help(readline)
> 
> 
> In
> [3]: 
>
> Do you really want to exit ([y]/n)? 
> 10:17 ♒♒♒   ☺ 😄
> 
> 
-- 
Ritesh Raj Sarraf | http://people.debian.org/~rrs
Debian - The Universal Operating System

signature.asc
Description: This is a digitally signed message part


Bug#901484: targetcli aborts with the error message "NameError: name 'readline' is not defined" when running in interactive shell mode

2018-06-13 Thread Ritesh Raj Sarraf
Control: tag -1 +moreinfo

On Wed, 2018-06-13 at 17:06 -0400, Matt Coleman wrote:
> Error Output:
> 
> Traceback (most recent call last):
>   File "/usr/lib/python3/dist-packages/configshell_fb/shell.py", line
> 893, in run_interactive
> old_completer = readline.get_completer()
> NameError: name 'readline' is not defined
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "/usr/bin/targetcli", line 121, in 
> main()
>   File "/usr/bin/targetcli", line 111, in main
> shell.run_interactive()
>   File "/usr/lib/python3/dist-packages/configshell_fb/shell.py", line
> 899, in run_interactive
> readline.set_completer(old_completer)
> NameError: name 'readline' is not defined
>  in /home/matt/reproduce/vendor/symfony/ in
> /home/matt/reproduce/vendor/symfony/symfony/src/Symfony/Component/Pro
> cess/Process.php on line 239

I think there may be something non-standard in your setup.

Because:

if sys.stdout.isatty():
import readline
tty=True
else:
tty=False

# remember the original setting
oldTerm = os.environ.get('TERM')
os.environ['TERM'] = ''

import readline

# restore the orignal TERM setting
if oldTerm != None:
os.environ['TERM'] = oldTerm
del oldTerm

In either case, readline needs to be imported.

readline supported is provided through package libpython2.7-stdlib:amd64 for 
Python2.

@Matt:

Are you able to import the readline module on the standard python interpreter ?

Here, on my setup, I can:

$ ipython
Python 2.7.15 (default, May  1 2018, 05:55:50) 
Type "copyright", "credits" or "license" for more information.

IPython 5.5.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help  -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
[TerminalIPythonApp] WARNING | File not found: '/home/rrs/.pythonrc'

In [1]: import readline

In [2]: help(readline)


In [3]: 
   
Do you really want to exit ([y]/n)? 
10:17 ♒♒♒   ☺ 😄


-- 
Ritesh Raj Sarraf | http://people.debian.org/~rrs
Debian - The Universal Operating System

signature.asc
Description: This is a digitally signed message part


Bug#901484: targetcli aborts with the error message "NameError: name 'readline' is not defined" when running in interactive shell mode

2018-06-13 Thread Matt Coleman
Package: python3-configshell-fb
Version: 1.1.20-1

Reproduced with python3-configshell-fb 1.1.20-1 on fully-updated Ubuntu Server 
18.04 by attempting to run targetcli via PHP using Symfony Process:

Test script (in a directory with Symfony 3.4.1 pulled in via Composer)

setInput('ls');

$process->mustRun();

var_dump($process->getOutput());



Actual output

PHP Fatal error: Uncaught 
Symfony\Component\Process\Exception\ProcessFailedException: The command 
"targetcli" failed.

Exit Code: 1(General error)

Working directory: /home/matt/reproduce

Output:

targetcli shell version 2.1.fb43
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

Error Output:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/configshell_fb/shell.py", line 893, in 
run_interactive
old_completer = readline.get_completer()
NameError: name 'readline' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/targetcli", line 121, in 
main()
  File "/usr/bin/targetcli", line 111, in main
shell.run_interactive()
  File "/usr/lib/python3/dist-packages/configshell_fb/shell.py", line 899, in 
run_interactive
readline.set_completer(old_completer)
NameError: name 'readline' is not defined
 in /home/matt/reproduce/vendor/symfony/ in 
/home/matt/reproduce/vendor/symfony/symfony/src/Symfony/Component/Process/Process.php
 on line 239



Expected output

string(1324) "targetcli shell version 2.1.fb43
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> o- / 
.
 [...]
  o- backstores 
..
 [...]
  | o- block 
..
 [Storage Objects: 0]
  | o- fileio 
.
 [Storage Objects: 0]
  | o- pscsi 
..
 [Storage Objects: 0]
  | o- ramdisk 

 [Storage Objects: 0]
  o- iscsi 

 [Targets: 0]
  o- loopback 
.
 [Targets: 0]
  o- vhost 

 [Targets: 0]
/> exit
"


I assume the package version 1.1.20 correpsonds to the project's 1.1fb20 tag on 
GitHub.

This bug was fixed in this commit and released in 1.1fb23: 
https://github.com/open-iscsi/configshell-fb/commit/82f79eb2f967ecd820d531488d0b64d6015b1aaf

I suggest updating the package to contain the most recent tagged version from 
the GitHub repository (currently 1.1fb24).