From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QZ0Fz-00050E-Ju for garchives@archives.gentoo.org; Tue, 21 Jun 2011 12:40:39 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id AC2601C028; Tue, 21 Jun 2011 12:40:31 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 645241C028 for ; Tue, 21 Jun 2011 12:40:31 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id A3ED61B4025 for ; Tue, 21 Jun 2011 12:40:30 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id F211D8003C for ; Tue, 21 Jun 2011 12:40:29 +0000 (UTC) From: "Wiktor W Brodlo" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Wiktor W Brodlo" Message-ID: Subject: [gentoo-commits] proj/anaconda:master commit in: iw/ X-VCS-Repository: proj/anaconda X-VCS-Files: iw/VirtualTerminal.py X-VCS-Directories: iw/ X-VCS-Committer: wiktor X-VCS-Committer-Name: Wiktor W Brodlo X-VCS-Revision: f5ea92b95725945fb72f72908c7a216acfdfe343 Date: Tue, 21 Jun 2011 12:40:29 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 6cb467563a23a72f5c2c342a3438e5d8 commit: f5ea92b95725945fb72f72908c7a216acfdfe343 Author: wiktor w brodlo brodlo net> AuthorDate: Tue Jun 21 12:40:12 2011 +0000 Commit: Wiktor W Brodlo brodlo net> CommitDate: Tue Jun 21 12:40:12 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/anaconda.git;= a=3Dcommit;h=3Df5ea92b9 Moved VirtualTerminal.py --- iw/VirtualTerminal.py | 182 -------------------------------------------= ------ 1 files changed, 0 insertions(+), 182 deletions(-) diff --git a/iw/VirtualTerminal.py b/iw/VirtualTerminal.py deleted file mode 100644 index cec8888..0000000 --- a/iw/VirtualTerminal.py +++ /dev/null @@ -1,182 +0,0 @@ -#!/usr/bin/env python -# -# VirtualTerminal.py -# -# Copyright 2007 Edward Andrew Robinson -# -# This program is free software; you can redistribute it and/or mod= ify -# it under the terms of the GNU General Public License as published= by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 021= 10-1301, USA. -# - -# Imports -import os -import vte -import gtk -import time - -class VirtualTerminal(vte.Terminal): - def __init__(self, log_file =3D None, history_length =3D 5, prompt_w= atch =3D {}, prompt_auto_reply =3D True, icon =3D None): - # Set up terminal - vte.Terminal.__init__(self) - - self.history =3D [] - self.history_length =3D history_length - self.icon =3D icon - self.last_row_logged =3D 0 - self.log_file =3D log_file - self.prompt_auto_reply =3D prompt_auto_reply - self.prompt_watch =3D prompt_watch - - self.connect('eof', self.run_command_done_callback) - self.connect('child-exited', self.run_command_done_callback) - self.connect('cursor-moved', self.contents_changed_callback) - - if False: - self.connect('char-size-changed', self.activate_action, 'cha= r-size-changed') - #self.connect('child-exited', self.activate_action, 'child-e= xited') - self.connect('commit', self.activate_action, 'commit') - self.connect('contents-changed', self.activate_action, 'cont= ents-changed') - #self.connect('cursor-moved', self.activate_action, 'cursor-= moved') - self.connect('decrease-font-size', self.activate_action, 'de= crease-font-size') - self.connect('deiconify-window', self.activate_action, 'deic= onify-window') - self.connect('emulation-changed', self.activate_action, 'emu= lation-changed') - self.connect('encoding-changed', self.activate_action, 'enco= ding-changed') - #self.connect('eof', self.activate_action, 'eof') - self.connect('icon-title-changed', self.activate_action, 'ic= on-title-changed') - self.connect('iconify-window', self.activate_action, 'iconif= y-window') - self.connect('increase-font-size', self.activate_action, 'in= crease-font-size') - self.connect('lower-window', self.activate_action, 'lower-wi= ndow') - self.connect('maximize-window', self.activate_action, 'maxim= ize-window') - self.connect('move-window', self.activate_action, 'move-wind= ow') - self.connect('raise-window', self.activate_action, 'raise-wi= ndow') - self.connect('refresh-window', self.activate_action, 'refres= h-window') - self.connect('resize-window', self.activate_action, 'resize-= window') - self.connect('restore-window', self.activate_action, 'restor= e-window') - self.connect('selection-changed', self.activate_action, 'sel= ection-changed') - self.connect('status-line-changed', self.activate_action, 's= tatus-line-changed') - self.connect('text-deleted', self.activate_action, 'text-del= eted') - self.connect('text-inserted', self.activate_action, 'text-in= serted') - self.connect('text-modified', self.activate_action, 'text-mo= dified') - self.connect('text-scrolled', self.activate_action, 'text-sc= rolled') - self.connect('window-title-changed', self.activate_action, '= window-title-changed') - - def activate_action(self, action, string): - print 'Action ' + action.get_name() + ' activated ' + str(string= ) - - def capture_text(self,text,text2,text3,text4): - return True - - def contents_changed_callback(self, terminal): - '''Gets the last line printed to the terminal, it will log - this line using self.log() (if the logger is on, and it will - also prompt this line using self.prompt() if the line needs - prompting''' - column,row =3D self.get_cursor_position() - if self.last_row_logged !=3D row: - off =3D row-self.last_row_logged - text =3D self.get_text_range(row-off,0,row-1,-1,self.capture= _text) - self.last_row_logged=3Drow - text =3D text.strip() - - # Log - self.log(text) - - # Prompter - self.prompter() - - def get_last_line(self): - terminal_text =3D self.get_text(self.capture_text) - terminal_text =3D terminal_text.split('\\\\n') - ii =3D len(terminal_text) - 1 - while terminal_text[ii] =3D=3D '': - ii =3D ii - 1 - terminal_text =3D terminal_text[ii] - - return terminal_text - - def log(self, text): - '''if self.log_file is not None the the line will be logged to - self.log_file. This function also stors the info in self.histoy - if self.history_lenght > 0''' - if self.log_file !=3D None: - date_string =3D time.strftime('[%d %b %Y %H:%M:%S] ', time.l= ocaltime()) - file =3D open(self.log_file, 'a') - file.write(date_string + text + '\\\\n') - file.close - - # Append to internal history - if self.history_length !=3D 0: - if len(self.history) >=3D self.history_length: - self.history.pop(0) - self.history.append(text) - - def prompter(self): - last_line =3D self.get_last_line() - if last_line in self.prompt_watch: - if self.prompt_auto_reply =3D=3D False: - message =3D '' - for ii in self.prompt_watch[last_line]: - message =3D message + self.history[self.history_leng= th - 1 - ii] - if self.yes_no_question(message): - self.feed_child('Yes\\\\n') - # TODO not sure why this is needed twice - self.feed_child('Yes\\\\n') - else: - self.feed_child('No\\\\n') - else: - self.feed_child('Yes\\\\n') - - def run_command(self, command_string): - '''run_command runs the command_string in the terminal. This - function will only return when self.thred_running is set to - True, this is done by run_command_done_callback''' - self.thread_running =3D True - spaces =3D '' - for ii in range(80 - len(command_string) - 2): - spaces =3D spaces + ' ' - self.feed('$ ' + str(command_string) + spaces) - self.log('$ ' + str(command_string) + spaces) - - command =3D command_string.split(' ') - pid =3D self.fork_command(command=3Dcommand[0], argv=3Dcommand,= directory=3Dos.getcwd()) - - while self.thread_running: - #time.sleep(.01) - gtk.main_iteration() - - def run_command_done_callback(self, terminal): - '''When called this function sets the thread as done allowing - the run_command function to exit''' - #print 'child done' - self.thread_running =3D False - - def yes_no_question(self, message): - message =3D message.replace('\\\\n\\\\n', '[NEWLINE][NEWLINE]').= replace('\\\\n', '').replace('[NEWLINE]', '\\\\n') - - if message.find('?') =3D=3D -1: - message =3D message + '\\\\n\\\\nDo you want to continue?' - - type=3Dgtk.MESSAGE_QUESTION - if message.lower().find('warning') !=3D -1: - type=3Dgtk.MESSAGE_WARNING - - dialog =3D gtk.MessageDialog(parent=3DNone, flags=3D0, type=3Dty= pe, buttons=3Dgtk.BUTTONS_YES_NO, message_format=3Dmessage) - dialog.set_icon(self.icon) - dialog.show_all() - responce =3D dialog.run() - dialog.destroy() - - # Responce =3D=3D yes - return responce =3D=3D -8 -