Simpler acquire_input()

Might work with Python 2.5 as a side-effect of not using delete.
This commit is contained in:
Laurent Bachelier 2012-10-21 17:59:26 +02:00
commit 571db865ab

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import with_statement
from copy import copy
import getpass
@ -438,18 +439,16 @@ class ConsoleApplication(BaseApplication):
return v.get()
def acquire_input(self, content=None):
editor = os.environ.get('EDITOR')
editor = os.getenv('EDITOR', 'vi')
if sys.stdin.isatty() and editor:
f = NamedTemporaryFile(delete=False)
filename = f.name
if content is not None:
f.write(content)
f.close()
os.system("%s %s" % (editor, filename))
f = open(filename, 'r')
text = f.read()
f.close()
os.unlink(filename)
with NamedTemporaryFile() as f:
filename = f.name
if content is not None:
f.write(content)
f.flush()
os.system("%s %s" % (editor, filename))
f.seek(0)
text = f.read()
else:
if sys.stdin.isatty():
print 'Reading content from stdin... Type ctrl-D ' \