예제 #1
0
파일: branchwin.py 프로젝트: jelmer/bzr-gtk
    def _branch_search_cb(self, w):
        from bzrlib.plugins.search import (
            index as _mod_index,
            errors as search_errors,
            )
        from bzrlib.plugins.gtk.search import SearchDialog

        try:
            index = _mod_index.open_index_url(self.branch.base)
        except search_errors.NoSearchIndex:
            dialog = Gtk.MessageDialog(self, type=Gtk.MessageType.QUESTION, 
                buttons=Gtk.ButtonsType.OK_CANCEL, 
                message_format="This branch has not been indexed yet. "
                               "Index now?")
            if dialog.run() == Gtk.ResponseType.OK:
                dialog.destroy()
                index = _mod_index.index_url(self.branch.base)
            else:
                dialog.destroy()
                return

        dialog = SearchDialog(index)

        if dialog.run() == Gtk.ResponseType.OK:
            revid = dialog.get_revision()
            if revid is not None:
                self.set_revision(revid)

        dialog.destroy()
예제 #2
0
    def _branch_search_cb(self, w):
        from bzrlib.plugins.search import index as _mod_index
        from bzrlib.plugins.gtk.search import SearchDialog
        from bzrlib.plugins.search import errors as search_errors

        try:
            index = _mod_index.open_index_url(self.branch.base)
        except search_errors.NoSearchIndex:
            dialog = gtk.MessageDialog(self, type=gtk.MESSAGE_QUESTION, 
                buttons=gtk.BUTTONS_OK_CANCEL, 
                message_format="This branch has not been indexed yet. "
                               "Index now?")
            if dialog.run() == gtk.RESPONSE_OK:
                dialog.destroy()
                index = _mod_index.index_url(self.branch.base)
            else:
                dialog.destroy()
                return

        dialog = SearchDialog(index)

        if dialog.run() == gtk.RESPONSE_OK:
            self.set_revision(dialog.get_revision())

        dialog.destroy()
예제 #3
0
def search(branch_location, query_list, suggest=False):
    """Search using bzr-search plugin to find revisions matching the query.
    
    param branch_location: location of the branch to search in
    param query_list: string to search
    param suggest: Optional flag to request suggestions instead of results
    return: A dict containing a list for each type of hit, i.e:
        {'file_hits':[], 'path_hits':[], 'revid_hits':[]}
    """
    if _mod_index is None:
        return None  # None indicates could-not-search
    try:
        index = _mod_index.open_index_url(branch_location)
    except errors.NoSearchIndex, e:
        sys.stderr.write(str(XMLError(e)))
        sys.stderr.flush()
        sys.stdout.flush()
        return (EXIT_ERROR, sys.stdout.getvalue(), sys.stderr.getvalue())
예제 #4
0
 def run(self, query_list=[], suggest=False, directory="."):
     trans = get_transport(directory)
     index = _mod_index.open_index_url(trans.base)
     # XXX: Have a query translator etc.
     query = [(query_item,) for query_item in query_list]
     index._branch.lock_read()
     try:
         if suggest:
             terms = index.suggest(query)
             terms = list(terms)
             terms.sort()
             self.outf.write("Suggestions: %s\n" % terms)
         else:
             seen_count = 0
             for result in index.search(query):
                 self.outf.write(result.document_name())
                 self.outf.write(" Summary: '%s'\n" % result.summary())
                 seen_count += 1
             if seen_count == 0:
                 raise errors.NoMatch(query_list)
     finally:
         index._branch.unlock()
예제 #5
0
 def run(self, query_list=[], suggest=False, directory="."):
     trans = get_transport(directory)
     index = _mod_index.open_index_url(trans.base)
     # XXX: Have a query translator etc.
     query = [(query_item, ) for query_item in query_list]
     index._branch.lock_read()
     try:
         if suggest:
             terms = index.suggest(query)
             terms = list(terms)
             terms.sort()
             self.outf.write("Suggestions: %s\n" % terms)
         else:
             seen_count = 0
             for result in index.search(query):
                 self.outf.write(result.document_name())
                 self.outf.write(" Summary: '%s'\n" % result.summary())
                 seen_count += 1
             if seen_count == 0:
                 raise errors.NoMatch(query_list)
     finally:
         index._branch.unlock()