Exemplo n.º 1
0
    def tag_search(self, pattern):
        if not self.have_database() or pattern is None:
            return

        self._view.clear_items()
        if pattern == '':
            return

        if self._task:
            self._task.stop()

        def _line(line):
            match = re.search('([^\ ]*)[\ ]+([0-9]+) ([^\ ]+) (.*)', line)
            if match is None:
                return
            data = match.groups()
            self._view.add_item(
                GtagsItem(file=data[2],
                          line=data[1],
                          dataline=data[3],
                          symbol=data[0],
                          search=pattern))
            if len(self._view._list) > 200:
                self._task.stop()

        #FIXME this is not portable
        cmd = 'for foo in `global -c %s`; do global -x -e $foo; done' % pattern
        self._task = GeneratorSubprocessTask(_line)
        self._task.start(cmd, cwd=self._project.source_directory, shell=True)
Exemplo n.º 2
0
class Man(Service):
    """Show manpage of command"""

    actions_config = ManActions

    def start(self):
        self._view = ManView(self)
        self._has_loaded = False
        self.task = None

    def show_man(self):
        self.boss.cmd('window', 'add_view', paned='Terminal', view=self._view)
        if not self._has_loaded:
            self._has_loaded = True

    def hide_man(self):
        self.boss.cmd('window', 'remove_view', view=self._view)

    def cmd_find(self, options, pattern):

        # stop and clear task
        if self.task:
            self.task.stop()
        self._view.clear_items()

        # don't make empty search
        if len(pattern) <= 0:
            return

        # prepare command
        cmd = '/usr/bin/env man %s "%s"' % (options, pattern)
        reman = re.compile('[(]([\d]+)[)]')

        # match and add each line
        def _line(result):
            list = reman.findall(result)
            if not len(list):
                return
            name = result.split('(')[0].strip()
            res = result.split('- ',1)

            # avoid too much result
            if self._view._count > 100:
                self.task.stop()

            # add in list
            self._view.add_item(ManItem(name, list[0], res[1], pattern))

        # launch man subprocess
        self.task = GeneratorSubprocessTask(_line)
        self.task.start(cmd, shell=True)

    def stop(self):
        if self.task:
            self.task.stop()
        if self.get_action('show_man').get_active():
            self.hide_man()
Exemplo n.º 3
0
    def cmd_find(self, options, pattern):

        # stop and clear task
        if self.task:
            self.task.stop()
        self._view.clear_items()

        # don't make empty search
        if len(pattern) <= 0:
            return

        # prepare command
        cmd = '/usr/bin/env man %s "%s"' % (options, pattern)
        reman = re.compile('[(]([\d]+)[)]')

        # match and add each line
        def _line(result):
            list = reman.findall(result)
            if not len(list):
                return
            name = result.split('(')[0].strip()
            res = result.split('- ',1)

            # avoid too much result
            if self._view._count > 100:
                self.task.stop()

            # add in list
            self._view.add_item(ManItem(name, list[0], res[1], pattern))

        # launch man subprocess
        self.task = GeneratorSubprocessTask(_line)
        self.task.start(cmd, shell=True)
Exemplo n.º 4
0
    def cmd_find(self, options, pattern):

        # stop and clear task
        if self.task:
            self.task.stop()
        self._view.clear_items()

        # don't make empty search
        if not pattern:
            return

        # prepare command
        cmd = '/usr/bin/env man %s "%s"' % (options, pattern)
        #XXX: unittest
        reman = re.compile(
            r'''
            (?P<name>\w+)
            \s*(\[\])\s* #whitespace and gentoo brackets
            \((?P<group>[\w\d]+)\)
            \s*-\s*
            (?P<desc>.*)
            ''', re.VERBOSE)

        # match and add each line
        def _line(result):
            # avoid too many results
            if len(self._view.list) > 100:
                self.task.stop()

            match = reman.match(result)
            if not match:
                return
            name = match.group('name')
            group = match.group('group')
            desc = match.group('desc')

            # add in list
            self._view.add_item(ManItem(name, int(group), desc, pattern))

        # launch man subprocess
        self.task = GeneratorSubprocessTask(_line)
        self.task.start(cmd, shell=True)
Exemplo n.º 5
0
class Man(Service):
    """Show manpage of command"""

    actions_config = ManActions
    features_config = ManFeaturesConfig

    def start(self):
        self._view = ManView(self)
        self._has_loaded = False
        self.task = None

    def show_man(self):
        self.boss.cmd('window', 'add_view', paned='Terminal', view=self._view)
        if not self._has_loaded:
            self._has_loaded = True

    def hide_man(self):
        self.boss.cmd('window', 'remove_view', view=self._view)

    def cmd_find(self, options, pattern):

        # stop and clear task
        if self.task:
            self.task.stop()
        self._view.clear_items()

        # don't make empty search
        if not pattern:
            return

        # prepare command
        cmd = '/usr/bin/env man %s "%s"' % (options, pattern)
        #XXX: unittest
        reman = re.compile(
            r'''
            (?P<name>\w+)
            \s*(\[\])\s* #whitespace and gentoo brackets
            \((?P<group>[\w\d]+)\)
            \s*-\s*
            (?P<desc>.*)
            ''', re.VERBOSE)

        # match and add each line
        def _line(result):
            # avoid too many results
            if len(self._view.list) > 100:
                self.task.stop()

            match = reman.match(result)
            if not match:
                return
            name = match.group('name')
            group = match.group('group')
            desc = match.group('desc')

            # add in list
            self._view.add_item(ManItem(name, int(group), desc, pattern))

        # launch man subprocess
        self.task = GeneratorSubprocessTask(_line)
        self.task.start(cmd, shell=True)

    def stop(self):
        if self.task:
            self.task.stop()
        if self.get_action('show_man').get_active():
            self.hide_man()
Exemplo n.º 6
0
class Gtags(LanguageService):
    """Fetch gtags list and show an gtags"""

    language_name = ('C', 'Cpp', 'Java', 'Php', 'Yacc', 'Assembly')

    actions_config = GtagsActions
    events_config = GtagsEvents
    features_config = GtagsFeaturesConfig
    options_config = GtagsOptionsConfig
    completer_factory = GtagsCompleter

    def start(self):
        self._view = GtagsView(self)
        self._has_loaded = False
        self._project = None
        self.on_project_switched(
            self.boss.cmd('project', 'get_current_project'))
        self._ticket = 0
        self._bg_threads = {}
        self._bd_do_updates = False
        self.task = self._task = None

    def show_gtags(self):
        self.boss.cmd('window', 'add_view', paned='Terminal', view=self._view)
        if not self._has_loaded:
            self._has_loaded = True

    def hide_gtags(self):
        self.boss.cmd('window', 'remove_view', view=self._view)

    def have_database(self, project=None):
        if project is None:
            project = self._project

        if project is None:
            return False

        return os.path.exists(
            os.path.join(self._project.source_directory, 'GTAGS'))

    def build_args(self, clean=False, quiet=False, project=None):
        """
        Generates the command and cwd the should be run to update database
        """
        if project is None:
            project = self._project

        if not project:
            return None, None

        commandargs = ['gtags', '-v']
        if self.have_database(project) and not clean:
            commandargs.append('-i')

        if quiet:
            commandargs.append('-q')

        aconf = project.get_meta_dir('gtags', filename="gtags.conf")
        if os.path.exists(aconf):
            commandargs.extend(['--gtagsconf', aconf])
        afiles = project.get_meta_dir('gtags', filename="files")
        if os.path.exists(afiles):
            commandargs.extend(['-f', afiles])

        return commandargs, project.source_directory

    def build_db(self, clean=False):
        """
        Build/Update the gtags database.
        """
        if self._project is None:
            return False

        commandargs, cwd = self.build_args(clean=clean)

        self._view._refresh_button.set_sensitive(False)
        self.boss.cmd('commander',
                      'execute',
                      commandargs=commandargs,
                      cwd=cwd,
                      title=_('Gtags build...'),
                      eof_handler=self.build_db_finished)

    def build_db_finished(self, term, *args):
        self._view.activate(self.have_database())
        self._view._refresh_button.set_sensitive(True)
        self.boss.cmd('notify',
                      'notify',
                      title=_('Gtags'),
                      data=_('Database build complete'))
        term.on_exited(*args)

    def on_project_switched(self, project):
        if project != self._project and project:
            self._project = project
            self._view.activate(self.have_database())
            self._bgupdate = os.path.exists(
                self._project.get_meta_dir('gtags', filename="autoupdate"))
        elif not project:
            self._project = None
            self._bgupdate = False

    def on_document_saved(self, document):
        if not document.doctype or \
           document.doctype.internal not in self.language_name:
            # we only run updates if a document with doctypes we
            # handle are saved
            return
        pro = self._project
        if not pro:
            return

        if pro in self._bg_threads and \
           self._bg_threads[pro].is_alive():
            # mark that daemon should run again
            self._bg_threads[pro].run_again = True
        else:
            self._bg_threads[pro] = GtagsUpdateThread(self, pro)
            self._bg_threads[pro].start()

    def project_refresh(self, project, callback):
        """Runs the gtags update on project refresh"""
        if not self.have_database(project=project):
            callback()
            return

        if project in self._bg_threads and self._bg_threads[project].is_alive(
        ):
            # mark that daemon should run again
            self._bg_threads[project].run_again = True
            self._bg_threads[project].callbacks.append(callback)
            self._bg_threads[project].clean = True
        else:
            self._bg_threads[project] = GtagsUpdateThread(self, project)
            self._bg_threads[project].callbacks.append(callback)
            self._bg_threads[project].clean = True
            self._bg_threads[project].start()

    def tag_search_current_word(self):
        self.boss.editor.cmd('call_with_current_word',
                             callback=self.tag_search_cw)

    def tag_search_cw(self, word):
        self.get_action('show_gtags').set_active(True)
        self._view._list.grab_focus()
        self._view._search.set_text(word)

    def tag_search(self, pattern):
        if not self.have_database() or pattern is None:
            return

        self._view.clear_items()
        if pattern == '':
            return

        if self._task:
            self._task.stop()

        def _line(line):
            match = re.search('([^\ ]*)[\ ]+([0-9]+) ([^\ ]+) (.*)', line)
            if match is None:
                return
            data = match.groups()
            self._view.add_item(
                GtagsItem(file=data[2],
                          line=data[1],
                          dataline=data[3],
                          symbol=data[0],
                          search=pattern))
            if len(self._view._list) > 200:
                self._task.stop()

        #FIXME this is not portable
        cmd = 'for foo in `global -c %s`; do global -x -e $foo; done' % pattern
        self._task = GeneratorSubprocessTask(_line)
        self._task.start(cmd, cwd=self._project.source_directory, shell=True)

    def stop(self):
        if self._task:
            self._task.stop()
        if self.get_action('show_gtags').get_active():
            self.hide_gtags()