예제 #1
0
 def get_marks_in_region_in_category(self, start, end_iter, category=None):
     """ return marks_list regardless of which version of sugar we have. """
     mark_list = []
     start_iter = start.copy()
     if self._activity.sugar_minor < 82:
         mark_list = self.text_buffer.get_markers_in_region(
             start_iter, end_iter)
         if not category:
             return mark_list
         new_list = []
         for m in mark_list:
             _logger.debug('marker name:%s' % (m.get_name(), ))
             if m.get_name().startswith(category):
                 new_list.append(m)
         mark_list = new_list
     else:
         mark_list += self.text_buffer.get_source_marks_at_iter(
             start_iter, category)
         while self.text_buffer.forward_iter_to_source_mark(
                 start_iter, category):
             if start_iter.get_offset() > end_iter.get_offset():
                 break
             marks = self.text_buffer.get_source_marks_at_iter(
                 start_iter, category)
             mark_list += marks
     _logger.debug('number of marks found in buffer in region:%s' %
                   (len(mark_list), ))
     return mark_list
예제 #2
0
 def _findnext_cb(self, button=None):
     ftext = self._search_entry.props.text
     _logger.debug('find next %s' % ftext)
     if ftext:
         if self.find_next(ftext, self.s_opts):
             self._replace_button.set_sensitive(True)
         self.set_focus()
def command_line(cmd):
    _logger.debug('command_line cmd:%s'%cmd)
    p1 = Popen(cmd,stdout=PIPE, shell=True)
    output = p1.communicate()
    if p1.returncode != 0:
        return None
    return output[0]
예제 #4
0
    def show_find(self, button):
        """find_window is defined in project.glade"""
        if not self.find_window:
            self._find_width = 400
            self._find_height = 300
            self.find_window = self.wTree.get_widget("find")
            self.find_window.connect('destroy', self.close_find_window)
            self.find_window.connect('delete_event', self.close_find_window)
            self.find_connect()
            self.find_window.set_title(_('FIND OR REPLACE'))
            self.find_window.set_size_request(self._find_width,
                                              self._find_height)
            self.find_window.set_decorated(False)
            self.find_window.set_resizable(False)
            self.find_window.set_modal(False)
            self.find_window.connect('size_request', self._size_request_cb)
            self.find_window.set_transient_for(
                self._activity.window.get_toplevel())

        #if there is any selected text, put it in the find entry field, and grab focus
        selected = self.get_selected()
        _logger.debug('selected text is %s' % selected)
        self._search_entry.props.text = selected
        self._search_entry.grab_focus()
        self.find_window.show()
예제 #5
0
    def read_file(self, file_path):
        """
        If the ds_object passed to PyDebug is the last one saved, then just assume that the playpen is valid.
        If the ds_object is not the most recent one,  try to load the playpen with the contents referenced by the git_id
        (reading the wiki, I discover we cannot count on metadata -- so cancel the git_id scheme)
        """
        #keep our own copy of the metadata
        if self.metadata:
            for key in self.metadata.keys():  #merge in journal information
                self.activity_dict[key] = self.metadata[key]

        log_dict(self.activity_dict, "read_file merged")
        if not self.debug_dict:
            self.get_config()

        if self.activity_dict.get('uid', 'XxXxXx') == self.debug_dict.get(
                'jobject_id', 'YyYyY'):
            _logger.debug('pick up where we left off')
            #OLPC bug reports suggest not all keys are preserved, so restore what we really need
            self.activity_dict['child_path'] = self.debug_dict.get(
                'child_path', '')
            if os.path.isdir(self.activity_dict.get('child_path')):
                self.child_path = self.activity_dict['child_path']
                #self.setup_new_activity()

        #update the journal display - required when the journal is used to delete an item
        if self.journal_class:
            self.journal_class.new_directory()
예제 #6
0
    def get_home_model(self):
        """Use shell model to return home_model
           --the home_model code changed between .82 and .84 sugar
           --so do the lookup differently depending on sugar version
        """
        global home_model
        (major, minor, micro, release) = self.sugar_version()
        _logger.debug('sugar version %s' % minor)

        if minor and minor >= 84:
            _logger.debug('using jarabe')
            from jarabe.model import shell
            home_model = shell.get_model()
        else:
            if not '/usr/share/sugar/shell/' in sys.path:
                sys.path.append('/usr/share/sugar/shell/')
            import view.Shell
            instance = view.Shell.get_instance()
            home_model = instance.get_model().get_home()
        if home_model:
            return home_model
        else:
            _logger.error('failed to retrieve home model')
            return None

        return home_model
    def start_debugging(
            self
    ):  #check for a start up script in bundle root or bundle_root/bin
        command = self.activity_dict.get('command', '')
        if command == '':
            self._activity.util.alert('No Activity Loaded')
            return
        _logger.debug("Command to execute:%s." % command)
        self.save_all()

        #try to restore a clean debugging environment
        #self.feed_virtual_terminal(0,'quit()\r\n\r\n')

        self._activity.set_visible_canvas(self.panes['TERMINAL'])
        #change the menus
        message = _(
            '\n\n Use the HELP in the Ipython interpreter to learn to DEBUG your program.\n'
        )
        self._activity.message_terminal(0, message)

        #get the ipython shell object
        """ this works but is not needed now
        ip = ipapi.get()
        arg_str = 'run -d -b %s %s'%(self.pydebug_path,self.child_path)
        ip.user_ns['go'] = arg_str
        _logger.debug('about to use "%s" to start ipython debugger\n'%(arg_str))
        """
        go_cmd = _('go')
        self.feed_virtual_terminal(0, '%s\n' % (go_cmd, ))
        pass
예제 #8
0
    def continue_save(self, alert, response=None):
        if response != Gtk.ResponseType.OK:
            return

        _logger.debug('saving %s' % os.path.basename(self.fullPath))
        text = self.get_text()
        _file = file(self.fullPath, 'w')

        try:
            _file.write(text)
            _file.close()
            self.save_hash()
            self.label.set_text(os.path.basename(self.fullPath))
            self.text_buffer.set_modified(False)
            msg = "File saved: %s md5sumn:%s" % (os.path.basename(
                self.fullPath), self.md5sum)
            _logger.debug(msg)

        except IOError:
            msg = _("I/O error ") + str(IOError[1])
            self._activity.alert(msg)

        except:
            msg = "Unexpected error:", sys.exc_info()[1]
            self._activity.alert(msg)

        if _file:
            _file.close()
예제 #9
0
 def make_paths(self):
     self.pydebug_path = os.environ['SUGAR_BUNDLE_PATH']
     p_path = os.environ['SUGAR_BUNDLE_PATH']
     if os.environ.get("PYTHONPATH", '') == '':
         os.environ['PYTHONPATH'] = self.pydebug_path
     else:
         p_path_list = os.environ['PYTHONPATH'].split(':')
         if not self.pydebug_path in p_path_list:
             os.environ[
                 'PYTHONPATH'] = self.pydebug_path + ':' + os.environ.get(
                     "PYTHONPATH", '')
     _logger.debug('sugar_bundle_path:%s\nsugar_activity_root:%s' %
                   (os.environ['SUGAR_BUNDLE_PATH'],
                    os.environ['SUGAR_ACTIVITY_ROOT']))
     self.debugger_home = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'],
                                       'data')
     self.child_path = None
     os.environ["HOME"] = self.debugger_home
     path_list = os.environ['PATH'].split(':')
     new_path = os.path.join(self.pydebug_path, 'bin:')
     if not new_path in path_list:
         os.environ['PATH'] = new_path + os.environ['PATH']
     self.storage = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'],
                                 'data/pydebug')
     self.sugar_bundle_path = os.environ['SUGAR_BUNDLE_PATH']
     self.activity_playpen = os.path.join(self.storage, 'playpen')
     if not os.path.isdir(self.activity_playpen):
         os.makedirs(self.activity_playpen)
     self.hide = os.path.join(self.storage, '.hide')
     if not os.path.isdir(self.hide):
         os.makedirs(self.hide)
     _logger.debug('Set IPYTHONDIR to %s' % self.debugger_home)
     os.environ['IPYTHONDIR'] = self.debugger_home
예제 #10
0
 def make_insertion(self, current_state, line_start, line_end):
     if current_state == None:
         insertion = TRACE_INSERT
         tag_name = TRACE_CAT
     elif current_state == TRACE_CAT:
         file_nickname = os.path.basename(self.fullPath)
         line_no = line_start.get_line() + 1
         shell_at = '%s:%s' % (
             file_nickname,
             line_no,
         )
         insertion = SHELL_INSERT % (shell_at, )
         tag_name = SHELL_CAT
     elif current_state == SHELL_CAT:
         #previous insertion is deleted, no insertion to do
         return
     mark = self.create_mark_universal(tag_name, line_start)
     line_no = line_start.get_line()
     prev_line_iter = self.text_buffer.get_iter_at_line(line_no - 1)
     prev_content = self.text_buffer.get_text(prev_line_iter, line_start)
     if prev_content.find('PyDebugTemp') == -1:
         current_line = self.text_buffer.get_text(line_start, line_end)
         _logger.debug('make insertion line:%s' % (current_line, ))
         padding = self.get_indent(current_line)
         indent = self.pad(padding)
         self.text_buffer.insert(line_start, indent + insertion)
         self.embeds[line_no] = tag_name
         line_start = self.text_buffer.get_iter_at_mark(mark)
         line_end = line_start.copy()
         line_end.forward_line()
         self.text_buffer.move_mark(mark, line_end)
         _logger.debug('inserted line %s' % (tag_name, ))
     else:
         line_start = prev_line_iter
     self.text_buffer.apply_tag_by_name(tag_name, line_start, line_end)
예제 #11
0
 def delete_current_insertion(self, line_start, line_end):
     """receives iters for start, end of inserted line, returns current_state"""
     current_line = self.text_buffer.get_text(line_start, line_end)
     line_no = line_start.get_line()
     if line_no in self.embeds:
         del self.embeds[line_no]
     _logger.debug('about to delete: %s' % (current_line, ))
     self.text_buffer.delete(line_start, line_end)
     if self.current_line.find(TRACE_INSERT) > -1:
         current_state = TRACE_CAT
     elif self.current_line.find(SHELL_TOKEN) > -1:
         current_state = SHELL_CAT
     else:
         current_state = None
     line_start = self.text_buffer.get_iter_at_line(self.clicked_line_num)
     if line_start:
         line_end = line_start.copy()
         line_end.forward_line()
         self.text_buffer.remove_tag_by_name(current_state, line_start,
                                             line_end)
         marker_list = self.get_marks_in_region_in_category(
             line_start, line_end)
         for m in marker_list:
             if self._activity.sugar_minor < 82:
                 self.text_buffer.delete_marker(m)
             else:
                 self.text_buffer.delete_mark(m)
     else:
         _logger.debug(
             'failed to find mark %s during click on inserted line' %
             (current_cat, ))
     return current_state
예제 #12
0
 def right_button_click_on_code_line(self, line_start, line_end):
     #if we specify None for marks_category, we get all of them
     current_line_marks_list = self.get_marks_in_region_in_category(
         line_start, line_end, None)
     current_state = None
     if len(current_line_marks_list) > 0:
         for m in current_line_marks_list:
             if m.get_name().startswith(TRACE_CAT):
                 current_state = TRACE_CAT
                 self.text_buffer.remove_tag_by_name(
                     TRACE_CAT, line_start, line_end)
             if m.get_name().startswith(SHELL_CAT):
                 current_state = SHELL_CAT
                 self.text_buffer.remove_tag_by_name(
                     SHELL_CAT, line_start, line_end)
             #delete the marker
             if self._activity.sugar_minor < 82 and current_state:
                 self.text_buffer.delete_marker(m)
             else:
                 self.text_buffer.delete_mark(m)
         #now delete the embed code in the line preceedng the marker line
         debug_start = line_start.copy()
         debug_start.backward_line()
         delete_candidate = self.text_buffer.get_text(
             debug_start, line_start)
         _logger.debug('delete candidate line:%s' % (delete_candidate, ))
         if delete_candidate.find('PyDebugTemp') > -1:
             self.text_buffer.delete(debug_start, line_start)
     else:
         #no marks on this non-inserted line
         _logger.debug('no marks on this line')
         current_state = None
     return current_state
예제 #13
0
 def activate_xid(self, xid):
     """ use the shell model to look up the window from xid, activat window"""
     window = self.get_wnck_window_from_xid(xid)
     if window:
         window.activate(gtk.get_current_event_time())
     else:
         _logger.debug('failed to get window from xid:%s' % (xid, ))
예제 #14
0
 def remember_line_no(self, fullPath, line):
     activity_name = self.glean_file_id_from_fullpath(fullPath)
     if activity_name:
         self.debug_dict[activity_name] = line
     _logger.debug('remembering id:%s at line:%s' % (
         activity_name,
         line,
     ))
예제 #15
0
 def _replace_cb(self, button=None):
     ftext = self._search_entry.props.text
     rtext = self._replace_entry.props.text
     _logger.debug('replace %s with %s usiing options %r' %
                   (ftext, rtext, self.s_opts))
     replaced, found = self.replace(ftext, rtext, self.s_opts)
     if found:
         self._replace_button.set_sensitive(True)
예제 #16
0
 def get_xid(self):
     """return the X11 window id of the main window"""
     screen = gtk.gdk.screen_get_default()
     root = screen.get_root_window()
     if root:
         return root.xid
     else:
         _logger.debug('failed to get xid')
         return None
예제 #17
0
 def project_run_cb(self, button):
     _logger.debug('entered project_run_cb')
     """
     start_script = ['python','import sys','from Rpyc import *','from Rpyc.Utils import remote_interpreter',
                     'c = SocketConnection("localhost")','remote_interpreter(c)']
     for l in start_script:
         self.feed_virtual_terminal(0,l+'\r\n')
     """
     self.start_debugging()
예제 #18
0
 def get_current_line(self):
     line_start = self.text_buffer.get_iter_at_line(self.clicked_line_num)
     line_end = line_start.copy()
     if not line_end.forward_line():
         #couldn't advance to next line, so just return
         return None
     current_line = self.text_buffer.get_text(line_start, line_end)
     _logger.debug('current line:%s' % (current_line))
     return current_line
예제 #19
0
 def get_wnck_window_from_xid(self, xid):
     """select shell activity, get window, via xid"""
     if not self.home_model:
         self.home_model = self.get_home_model()
     if self.home_model:
         return self.home_model._get_activity_by_xid(xid).get_window()
     else:
         _logger.debug('failed to get window associated with xid:%s' %
                       (xid, ))
         return None
예제 #20
0
 def get_wnck_window_from_activity_id(self, activity_id):
     """use sugar home_model to get X11 window specified by activity_id"""
     _logger.debug('entered get_wnck_window_from_activity_id. id:%s' %
                   activity_id)
     activity = self.get_activity_from_activity_id()
     if activity:
         return activity.get_window()
     else:
         _logger.debug('wnck_window was none')
         return None
예제 #21
0
 def position_to(self, fullpath):
     self.iter = None
     self.ft_model.foreach(self.fn_compare, fullpath)
     if self.iter != None:
         self.path = self.ft_model.get_path(self.iter)
         self.treeview.scroll_to_cell(self.path,
                                      use_align=True,
                                      row_align=0.2)
     else:
         _logger.debug('position to not found:%s' % fullpath)
def edit_glue(self,filename,linenumber=0):
    _logger.debug('position to editor file:%s. Line:%d'%(filename,linenumber))
    if filename.find('<console') > -1:
        _logger.debug('rejected positioning to console')
        return
    if filename.endswith('.pyc') or filename.endswith('.pyo'):
        filename = filename[:-1]
    if linenumber > 0:
        linenumber -= 1
    db.position_to(filename,linenumber)
예제 #23
0
 def glean_file_id_from_fullpath(self, fullPath):
     """use folder name of activity as namespace for filename"""
     folder_list = fullPath.split('/')
     activity_name = ''
     for folder in folder_list:
         if folder.find('.activity') > -1:
             activity_name = folder
     i = folder_list.index(activity_name)
     ret = '/'.join(folder_list[i:])
     _logger.debug('file_id:%s' % ret)
     return ret
예제 #24
0
    def _pd_button_press_cb(self, widget, event):
        """respond to left and right clicks on the number column
        left-click toggles breakpoint on and off at current line (red)
        right-click cycles through:
            off->embeded_trace(green)->embeded-shell(blue)->off . . .
        right-click on the inserted line is same as right click on line following it
        left click during embeded shell or trace is ignored
        """

        if event.window == self.text_view.get_window(Gtk.TextWindowType.LEFT):
            #click  was in left gutter:
            x_buf, y_buf = self.text_view.window_to_buffer_coords(
                Gtk.TextWindowType.LEFT, int(event.x), int(event.y))
            #get contents of the line

            line_start = self.text_view.get_line_at_y(y_buf)[0]
            self.clicked_line_num = line_start.get_line()
            self.current_line = self.get_current_line()
            if not self.current_line:
                return

            line_end = line_start.copy()
            line_end.forward_line()

            if self.current_line.find('PyDebugTemp') == -1:
                if event.button == 1:
                    self.left_button_click_on_code_line(line_start, line_end)
                    return

                else:
                    current_state = self.right_button_click_on_code_line(
                        line_start, line_end)

            else:
                #click_on_inserted_line
                if event.button == 1:
                    #do nothing for left click on inserted line
                    return

                current_state = self.delete_current_insertion(
                    line_start, line_end)

            #previously inserted lines, marks are deleted, now do next_state
            _logger.debug('ready for insertion, current state:%s' %
                          current_state)
            line_start = self.text_buffer.get_iter_at_line(
                self.clicked_line_num)
            line_end = line_start.copy()
            line_end.forward_line()
            self.make_insertion(current_state, line_start, line_end)

        return False
예제 #25
0
 def put_config(self):
     if self.child_path:
         #self.debug_dict['tree_md5'] = self.util.md5sum_tree(self.child_path)
         self.debug_dict['child_path'] = self.child_path
     try:
         fd = open(os.path.join(self.debugger_home, 'pickl'), 'wb')
         local = self.debug_dict.copy()
         pickle.dump(local, fd, pickle.HIGHEST_PROTOCOL)
     except IOError:
         _logger.debug('put_config routine Error writing pickle file %s' %
                       os.path.join(self.debugger_home, 'pickl'))
         return
     finally:
         fd.close()
예제 #26
0
 def get_wnck_window_from_bundle_id(self, bundle_id):
     """get the window associated with bundle_id or None"""
     if not self.home_model:
         self.home_model = self.get_home_model()
     if self.home_model:
         activity_list = self.home_model._get_activities_with_window()
         _logger.debug('length of activity_list:%s' %
                       (len(activity_list, )))
         if activity_list:
             for activity in activity_list:
                 if activity.get_type == bundle_id:
                     return activity.get_window()
         _logger.debug("failed to find %s" % (bundle_id, ))
         return None
예제 #27
0
 def help_selected(self):
     """
     if help is not created in a gtk.mainwindow then create it
     else just switch to that viewport
     """
     if not self.help_x11:
         screen = gtk.gdk.screen_get_default()
         self.pdb_window = screen.get_root_window()
         _logger.debug('xid for pydebug:%s' % self.pdb_window.xid)
         #self.window_instance = self.window.window
         self.help_x11 = self.help.realize_help()
         #self.x11_window = self.get_x11()os.geteuid()
     else:
         self.help.activate_help()
예제 #28
0
 def set_ipython_traceback(self):
     tb = self.debug_dict['traceback']
     _logger.debug('set traceback:%s' % tb)
     """
     ip = IPython.ipapi.get()
     if ip:
         ip.ipmagic('xmode %s'%tb)
     else:
         _logger.error('did not get ip from IPython.ipapi')
     #ipmagic = ip.user_ns['ipmagic']
     #ip.magic_xmode(tb)
     """
     self.feed_virtual_terminal(0, "%%xmode %s\n" % tb)
     gobject.idle_add(self.set_terminal_focus)
예제 #29
0
 def find_import(self, fn):
     _logger.debug('find_import in file %s' % fn)
     try_fn = os.path.join(self.child_path, fn)
     if not os.path.isfile(try_fn):
         try_fn += '.py'
         if not os.path.isfile(try_fn):
             _logger.debug('in find_import, failed to find file %s' %
                           try_fn)
             return
         line_no = 0
         for line in open(try_fn, 'r'):
             if line.startswith('import'):
                 return line_no, try_fn
             line_no += 1
         return -1, None
예제 #30
0
 def save_editor_status(self):
     if self.edit_notebook.get_n_pages() == 0: return
     current_page = self.edit_notebook.get_current_page()
     edit_files = []
     for i in range(self.edit_notebook.get_n_pages()):
         page = self.edit_notebook.get_nth_page(i)
         if isinstance(page, GtkSourceview2Page):
             i = page.fullPath.find('playpen')
             if i > -1:
                 fname = page.fullPath[i + 8:]
             else:
                 fname = page.fullPath
             _logger.debug('updating debug_dict with %s' % fname)
             edit_files.append([fname, page.get_iter().get_line()])
     self.debug_dict[os.path.basename(self.child_path)] = edit_files
     self.debug_dict[os.path.basename(self.child_path) +
                     '-page'] = current_page