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
|
||||
# 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 ' \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue