Re: [Freeipa-devel] [PATCH] 0256 Fix installutils.get_password without a TTY

2013-08-06 Thread Martin Kosek
On 07/30/2013 06:05 PM, Nathaniel McCallum wrote:
 On Tue, 2013-07-30 at 18:01 +0200, Petr Viktorin wrote:
 On 07/30/2013 05:23 PM, Ana Krivokapic wrote: On 07/30/2013 01:15 PM,  
 There's a typo in the commit message: ises instead of uses.

 Fixed.


 On 07/30/2013 05:43 PM, Nathaniel McCallum wrote:
 On Tue, 2013-07-30 at 17:36 +0200, Petr Viktorin wrote:
 On 07/30/2013 05:20 PM, Nathaniel McCallum wrote:
 On Tue, 2013-07-30 at 13:15 +0200, Petr Viktorin wrote:
 See the commit message or ticket.

 This is a nuisance when writing tests for interactive prompting.

 https://fedorahosted.org/freeipa/ticket/3824

 There appears to be a stray comma.

 The comma at the end of a print statement suppresses the trailing newline.

 Wouldn't sys.stdout.write() be clearer?

 I don't have a preference. Changed.

 The comma approach also doesn't work in py3k.

 Well, the print statement itself doesn't work in py3k :)

 The 2to3 tool handles the trailing comma without problems (and we'll 
 probably use the print fixer when porting).

 $ 2to3 --fix print /tmp/printtest.py
 RefactoringTool: Refactored /tmp/printtest.py
 --- /tmp/printtest.py   (original)
 +++ /tmp/printtest.py   (refactored)
 @@ -1 +1 @@
 -print 'foo',
 +print('foo', end=' ')
 RefactoringTool: Files that need to be modified:
 RefactoringTool: /tmp/printtest.py

 
 +1

ACK for Petr's patch. Pushed to master.

Martin

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


[Freeipa-devel] [PATCH] 0256 Fix installutils.get_password without a TTY

2013-07-30 Thread Petr Viktorin

See the commit message or ticket.

This is a nuisance when writing tests for interactive prompting.

https://fedorahosted.org/freeipa/ticket/3824


--
Petr³
Look! Look! A nice round patch number!
From 56fa81005fb872788ca9659236aaf687b34ef90e Mon Sep 17 00:00:00 2001
From: Petr Viktorin pvikt...@redhat.com
Date: Tue, 30 Jul 2013 13:07:18 +0200
Subject: [PATCH] Fix installutils.get_password without a TTY

If stdin is a TTY, ipaserver.install.installutils ises getpass and all
is well. Without a TTY, though, there were two problems:

* The prompt was not printed
* On end of file, an empty string was returned, which caused read_password
  to enter an infinite loop.

Fix both problems.

https://fedorahosted.org/freeipa/ticket/3824
---
 ipaserver/install/installutils.py | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
index 6a6841a110b531be0c8445eaa6f861d627340d30..97f4c684955a36228c0863a859c239b36e13ad6f 100644
--- a/ipaserver/install/installutils.py
+++ b/ipaserver/install/installutils.py
@@ -256,7 +256,12 @@ def get_password(prompt):
 if os.isatty(sys.stdin.fileno()):
 return getpass.getpass(prompt)
 else:
-return sys.stdin.readline().rstrip()
+print prompt,
+sys.stdout.flush()
+line = sys.stdin.readline()
+if not line:
+raise EOFError()
+return line.rstrip()
 
 def _read_password_default_validator(password):
 if len(password)  8:
-- 
1.8.3.1

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Re: [Freeipa-devel] [PATCH] 0256 Fix installutils.get_password without a TTY

2013-07-30 Thread Nathaniel McCallum
On Tue, 2013-07-30 at 13:15 +0200, Petr Viktorin wrote:
 See the commit message or ticket.
 
 This is a nuisance when writing tests for interactive prompting.
 
 https://fedorahosted.org/freeipa/ticket/3824

There appears to be a stray comma.

Also, why aren't we using the getpass or cmd modules?

Nathaniel

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


Re: [Freeipa-devel] [PATCH] 0256 Fix installutils.get_password without a TTY

2013-07-30 Thread Ana Krivokapic
On 07/30/2013 01:15 PM, Petr Viktorin wrote:
 See the commit message or ticket.

 This is a nuisance when writing tests for interactive prompting.

 https://fedorahosted.org/freeipa/ticket/3824




 ___
 Freeipa-devel mailing list
 Freeipa-devel@redhat.com
 https://www.redhat.com/mailman/listinfo/freeipa-devel

There's a typo in the commit message: ises instead of uses.

Otherwise ACK.

-- 
Regards,

Ana Krivokapic
Associate Software Engineer
FreeIPA team
Red Hat Inc.

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Re: [Freeipa-devel] [PATCH] 0256 Fix installutils.get_password without a TTY

2013-07-30 Thread Petr Viktorin

On 07/30/2013 05:20 PM, Nathaniel McCallum wrote:

On Tue, 2013-07-30 at 13:15 +0200, Petr Viktorin wrote:

See the commit message or ticket.

This is a nuisance when writing tests for interactive prompting.

https://fedorahosted.org/freeipa/ticket/3824


There appears to be a stray comma.


The comma at the end of a print statement suppresses the trailing newline.


Also, why aren't we using the getpass or cmd modules?


We are using getpass, if stdin is a tty. See the patch context.


Nathaniel




--
Petr³

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Re: [Freeipa-devel] [PATCH] 0256 Fix installutils.get_password without a TTY

2013-07-30 Thread Nathaniel McCallum
On Tue, 2013-07-30 at 17:36 +0200, Petr Viktorin wrote:
 On 07/30/2013 05:20 PM, Nathaniel McCallum wrote:
  On Tue, 2013-07-30 at 13:15 +0200, Petr Viktorin wrote:
  See the commit message or ticket.
 
  This is a nuisance when writing tests for interactive prompting.
 
  https://fedorahosted.org/freeipa/ticket/3824
 
  There appears to be a stray comma.
 
 The comma at the end of a print statement suppresses the trailing newline.

Wouldn't sys.stdout.write() be clearer? The comma approach also doesn't
work in py3k.

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


Re: [Freeipa-devel] [PATCH] 0256 Fix installutils.get_password without a TTY

2013-07-30 Thread Petr Viktorin
On 07/30/2013 05:23 PM, Ana Krivokapic wrote: On 07/30/2013 01:15 PM,  
There's a typo in the commit message: ises instead of uses.


Fixed.


On 07/30/2013 05:43 PM, Nathaniel McCallum wrote:

On Tue, 2013-07-30 at 17:36 +0200, Petr Viktorin wrote:

On 07/30/2013 05:20 PM, Nathaniel McCallum wrote:

On Tue, 2013-07-30 at 13:15 +0200, Petr Viktorin wrote:

See the commit message or ticket.

This is a nuisance when writing tests for interactive prompting.

https://fedorahosted.org/freeipa/ticket/3824


There appears to be a stray comma.


The comma at the end of a print statement suppresses the trailing newline.


Wouldn't sys.stdout.write() be clearer?


I don't have a preference. Changed.


The comma approach also doesn't work in py3k.


Well, the print statement itself doesn't work in py3k :)

The 2to3 tool handles the trailing comma without problems (and we'll 
probably use the print fixer when porting).


$ 2to3 --fix print /tmp/printtest.py
RefactoringTool: Refactored /tmp/printtest.py
--- /tmp/printtest.py   (original)
+++ /tmp/printtest.py   (refactored)
@@ -1 +1 @@
-print 'foo',
+print('foo', end=' ')
RefactoringTool: Files that need to be modified:
RefactoringTool: /tmp/printtest.py

--
Petr³
From 2a7de8b2ea9eda5a8e8669f306f193cd331acd64 Mon Sep 17 00:00:00 2001
From: Petr Viktorin pvikt...@redhat.com
Date: Tue, 30 Jul 2013 13:07:18 +0200
Subject: [PATCH] Fix installutils.get_password without a TTY

If stdin is a TTY, ipaserver.install.installutils uses getpass and all
is well. Without a TTY, though, there were two problems:

* The prompt was not printed
* On end of file, an empty string was returned, which caused read_password
  to enter an infinite loop.

Fix both problems.

https://fedorahosted.org/freeipa/ticket/3824
---
 ipaserver/install/installutils.py | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
index 6a6841a110b531be0c8445eaa6f861d627340d30..d17d53d1d05a87e02ee5cf0953ddce53a79a4582 100644
--- a/ipaserver/install/installutils.py
+++ b/ipaserver/install/installutils.py
@@ -256,7 +256,13 @@ def get_password(prompt):
 if os.isatty(sys.stdin.fileno()):
 return getpass.getpass(prompt)
 else:
-return sys.stdin.readline().rstrip()
+sys.stdout.write(prompt)
+sys.stdout.flush()
+line = sys.stdin.readline()
+if not line:
+raise EOFError()
+return line.rstrip()
+
 
 def _read_password_default_validator(password):
 if len(password)  8:
-- 
1.8.3.1

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel