Ticket #4131: 0001-Get-back-a-working-activity-history-SL-4131.patch

File 0001-Get-back-a-working-activity-history-SL-4131.patch, 4.8 KB (added by erikos, 11 years ago)

Get back a working activity history

  • terminal.py

    From 891b0b129df66b8db66ec9a45bd51d1300cf0529 Mon Sep 17 00:00:00 2001
    From: Simon Schampijer <simon@laptop.org>
    Date: Sat, 3 Nov 2012 15:17:09 +0100
    Subject: [PATCH] Get back a working activity history, SL #4131
    
    Because of the get_text* methods to not be introspectable
    the functionality to store the activity session data was
    disabled (no tabs and respective terminal history). The
    upstream bug [1] will be fixed so this patch does do
    the following:
    
    - uncomment the riginal code
    - vte_terminal_fork_command_full will return a boolean indicating
      success and the pid
    - vte_terminal_get_text will return a tuple and only the first
      argument is the scrollback_text
    
    [1] https://bugzilla.gnome.org/show_bug.cgi?id=676999
    [2] http://git.gnome.org/browse/vte/tree/src/vte.c#n3820
    
    Signed-off-by: Simon Schampijer <simon@laptop.org>
    ---
     terminal.py | 83 +++++++++++++++++++++++++++++--------------------------------
     1 file changed, 39 insertions(+), 44 deletions(-)
    
    diff --git a/terminal.py b/terminal.py
    index 6a3cfef..14cacc5 100644
    a b class TerminalActivity(activity.Activity): 
    341341            for l in tab_state['scrollback']:
    342342                vt.feed(l + '\r\n')
    343343
    344         box.pid = vt.fork_command_full(Vte.PtyFlags.DEFAULT,
    345                                        os.environ["HOME"],
    346                                        ["/bin/bash"],
    347                                        [],
    348                                        GLib.SpawnFlags.DO_NOT_REAP_CHILD,
    349                                        None,
    350                                        None)
     344        sucess_, box.pid = vt.fork_command_full(Vte.PtyFlags.DEFAULT,
     345                                            os.environ["HOME"],
     346                                            ["/bin/bash"],
     347                                            [],
     348                                            GLib.SpawnFlags.DO_NOT_REAP_CHILD,
     349                                            None,
     350                                            None)
    351351        self._notebook.props.page = index
    352352        vt.grab_focus()
    353353
    class TerminalActivity(activity.Activity): 
    413413            self._next_tab_button.props.sensitive = True
    414414
    415415    def write_file(self, file_path):
    416         return
    417 # FIXME Bellow lines are commented in order to have journal access,
    418 # but we are facing an upstream bug with Vte.Terminal.get_text,
    419 # info on SL#3645, upstream gnome Bug #676999
    420 #
    421 #        if not self.metadata['mime_type']:
    422 #            self.metadata['mime_type'] = 'text/plain'
    423 #
    424 #        data = {}
    425 #        data['current-tab'] = self._notebook.get_current_page()
    426 #        data['tabs'] = []
    427 #
    428 #        for i in range(self._notebook.get_n_pages()):
    429 #            page = self._notebook.get_nth_page(i)
    430 #
    431 #            def selected_cb(terminal, c, row, cb_data):
    432 #                return 1
    433 #            scrollback_text = page.vt.get_text(selected_cb, False)
    434 #
    435 #            scrollback_lines = scrollback_text.split('\n')
    436 #
    437 #            # Note- this currently gets the child's initial environment
    438 #            # rather than the current environment, making it not very useful.
    439 #            environment = open('/proc/%d/environ' %
    440 #                               page.pid, 'r').read().split('\0')
    441 #
    442 #            cwd = os.readlink('/proc/%d/cwd' % page.pid)
    443 #
    444 #            tab_state = {'env': environment, 'cwd': cwd,
    445 #                         'scrollback': scrollback_lines}
    446 #
    447 #            data['tabs'].append(tab_state)
    448 #
    449 #        fd = open(file_path, 'w')
    450 #        text = simplejson.dumps(data)
    451 #        fd.write(text)
    452 #        fd.close()
     416        if not self.metadata['mime_type']:
     417            self.metadata['mime_type'] = 'text/plain'
     418
     419        data = {}
     420        data['current-tab'] = self._notebook.get_current_page()
     421        data['tabs'] = []
     422
     423        for i in range(self._notebook.get_n_pages()):
     424            page = self._notebook.get_nth_page(i)
     425
     426            def selected_cb(terminal, c, row, cb_data):
     427                return 1
     428            scrollback_text = page.vt.get_text(selected_cb, False)
     429
     430            scrollback_lines = scrollback_text[0].split('\n')
     431
     432            # Note- this currently gets the child's initial environment
     433            # rather than the current environment, making it not very useful.
     434            environment = open('/proc/%d/environ' %
     435                               page.pid, 'r').read().split('\0')
     436
     437            cwd = os.readlink('/proc/%d/cwd' % page.pid)
     438
     439            tab_state = {'env': environment, 'cwd': cwd,
     440                         'scrollback': scrollback_lines}
     441
     442            data['tabs'].append(tab_state)
     443
     444        fd = open(file_path, 'w')
     445        text = simplejson.dumps(data)
     446        fd.write(text)
     447        fd.close()
    453448
    454449    def _get_conf(self, conf, var, default):
    455450        if conf.has_option('terminal', var):