def run(self, command, application): """Open application's history buffer in an editor. :type command: list :param command: The dot command as a list split on whitespace, e.g ``['.foo', 'arg1', 'arg2']`` :type application: AWSShell :param application: The application object. """ all_commands = '\n'.join([ 'aws ' + h for h in list(application.history) if not h.startswith(('.', '!')) ]) with temporary_file('w') as f: f.write(all_commands) f.flush() editor = self._get_editor_command() try: p = self._popen_cls([editor, f.name]) p.communicate() except OSError: self._err.write( "Unable to launch editor: %s\n" "You can configure which editor to use by " "exporting the EDITOR environment variable.\n" % editor)
def run(self, command, application): """Open application's history buffer in an editor. :type command: list :param command: The dot command as a list split on whitespace, e.g ``['.foo', 'arg1', 'arg2']`` :type application: AWSShell :param application: The application object. """ all_commands = '\n'.join( ['aws ' + h for h in list(application.history) if not h.startswith(('.', '!'))]) with temporary_file('w') as f: f.write(all_commands) f.flush() editor = self._get_editor_command() try: p = self._popen_cls([editor, f.name]) p.communicate() except OSError: self._err.write("Unable to launch editor: %s\n" "You can configure which editor to use by " "exporting the EDITOR environment variable.\n" % editor)
def test_can_open_in_read(self): with temporary_file('r') as f: filename = f.name assert f.read() == '' # Verify we can open the file again # in another file descriptor. with open(filename, 'w') as f2: f2.write("foobar") f.seek(0) assert f.read() == "foobar" self.assertFalse(os.path.isfile(filename))
def run(self, command, application): """Open application's history buffer in an editor. :type command: list :param command: The dot command as a list split on whitespace, e.g ``['.foo', 'arg1', 'arg2']`` :type application: AWSShell :param application: The application object. """ all_commands = "\n".join(["aws " + h for h in list(application.history) if not h.startswith((".", "!"))]) with temporary_file("w") as f: f.write(all_commands) f.flush() editor = self._get_editor_command() p = self._popen_cls([editor, f.name]) p.communicate()
def run(self, command, application): """Open application's history buffer in an editor. :type command: list :param command: The dot command as a list split on whitespace, e.g ``['.foo', 'arg1', 'arg2']`` :type application: AWSShell :param application: The application object. """ all_commands = '\n'.join( ['aws ' + h for h in list(application.history) if not h.startswith(('.', '!'))]) with temporary_file('w') as f: f.write(all_commands) f.flush() editor = self._get_editor_command() p = self._popen_cls([editor, f.name]) p.communicate()
def test_is_removed_after_exiting_context(self): with temporary_file('w') as f: filename = f.name f.write("foobar") f.flush() self.assertFalse(os.path.isfile(filename))
def test_can_use_as_context_manager(self): with temporary_file('w') as f: filename = f.name f.write("foobar") f.flush() self.assertEqual(open(filename).read(), "foobar")