Simpler acquire_input()
Might work with Python 2.5 as a side-effect of not using delete.
This commit is contained in:
parent
770c0877a0
commit
571db865ab
1 changed files with 10 additions and 11 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
from copy import copy
|
from copy import copy
|
||||||
import getpass
|
import getpass
|
||||||
|
|
@ -438,18 +439,16 @@ class ConsoleApplication(BaseApplication):
|
||||||
return v.get()
|
return v.get()
|
||||||
|
|
||||||
def acquire_input(self, content=None):
|
def acquire_input(self, content=None):
|
||||||
editor = os.environ.get('EDITOR')
|
editor = os.getenv('EDITOR', 'vi')
|
||||||
if sys.stdin.isatty() and editor:
|
if sys.stdin.isatty() and editor:
|
||||||
f = NamedTemporaryFile(delete=False)
|
with NamedTemporaryFile() as f:
|
||||||
filename = f.name
|
filename = f.name
|
||||||
if content is not None:
|
if content is not None:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
f.close()
|
f.flush()
|
||||||
os.system("%s %s" % (editor, filename))
|
os.system("%s %s" % (editor, filename))
|
||||||
f = open(filename, 'r')
|
f.seek(0)
|
||||||
text = f.read()
|
text = f.read()
|
||||||
f.close()
|
|
||||||
os.unlink(filename)
|
|
||||||
else:
|
else:
|
||||||
if sys.stdin.isatty():
|
if sys.stdin.isatty():
|
||||||
print 'Reading content from stdin... Type ctrl-D ' \
|
print 'Reading content from stdin... Type ctrl-D ' \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue