Rev 2: Create the start of the core index logic, specifically handling in http://people.ubuntu.com/~robertc/baz2.0/plugins/search/trunk
Robert Collins
robertc at robertcollins.net
Sun Jun 8 06:58:21 BST 2008
At http://people.ubuntu.com/~robertc/baz2.0/plugins/search/trunk
------------------------------------------------------------
revno: 2
revision-id: robertc at robertcollins.net-20080608055724-c6tjpycts2476brf
parent: robertc at robertcollins.net-20080608052044-s7ktacyyyiib8zi4
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Sun 2008-06-08 15:57:24 +1000
message:
Create the start of the core index logic, specifically handling
no-search-index-present. Also add an errors module for holding the
exception classes we may need. (Robert Collins)
added:
errors.py errors.py-20080608055509-hnimeek7q8tctkqf-1
index.py index.py-20080608055509-hnimeek7q8tctkqf-2
tests/test_errors.py test_errors.py-20080608055509-hnimeek7q8tctkqf-3
tests/test_index.py test_index.py-20080608055509-hnimeek7q8tctkqf-4
modified:
NEWS news-20080608052041-z5bahsl8kwl0uf4x-2
commands.py commands.py-20080608052041-z5bahsl8kwl0uf4x-5
tests/__init__.py __init__.py-20080608052041-z5bahsl8kwl0uf4x-8
tests/test_blackbox.py test_blackbox.py-20080608052041-z5bahsl8kwl0uf4x-9
=== modified file 'NEWS'
--- a/NEWS 2008-06-08 05:20:44 +0000
+++ b/NEWS 2008-06-08 05:57:24 +0000
@@ -13,6 +13,9 @@
FEATURES:
+ * New command ``search`` to search a search index from within bzr.
+ (Robert Collins)
+
IMPROVEMENTS:
BUGFIXES:
@@ -23,3 +26,6 @@
INTERNALS:
+ * New modules: ``commands``, ``errors``, ``index``. These contain the
+ console ui, exceptions, and the search index core respectively.
+ (Robert Collins)
=== modified file 'commands.py'
--- a/commands.py 2008-06-08 05:20:44 +0000
+++ b/commands.py 2008-06-08 05:57:24 +0000
@@ -15,9 +15,11 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
-"""search commands."""
+"""The command console user interface for bzr search."""
import bzrlib.commands
+from bzrlib.plugins.search import index as _mod_index
+from bzrlib.transport import get_transport
class cmd_search(bzrlib.commands.Command):
@@ -30,4 +32,5 @@
takes_args = ['query+']
def run(self, query_list=[]):
- pass
+ trans = get_transport('.')
+ index = _mod_index.open_index_url(trans.base)
=== added file 'errors.py'
--- a/errors.py 1970-01-01 00:00:00 +0000
+++ b/errors.py 2008-06-08 05:57:24 +0000
@@ -0,0 +1,31 @@
+# search, a bzr plugin for searching within bzr branches/repositories.
+# Copyright (C) 2008 Robert Collins
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+#
+# 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+"""Error objects for search functions."""
+
+import bzrlib.commands
+from bzrlib.errors import BzrError
+import bzrlib.errors
+
+
+class NoSearchIndex(BzrError):
+ """Raised when there is no search index for a url."""
+
+ _fmt = "No search index present for %(url)r. Please see 'bzr help index'."
+
+ def __init__(self, url):
+ self.url = url
=== added file 'index.py'
--- a/index.py 1970-01-01 00:00:00 +0000
+++ b/index.py 2008-06-08 05:57:24 +0000
@@ -0,0 +1,30 @@
+# search, a bzr plugin for searching within bzr branches/repositories.
+# Copyright (C) 2008 Robert Collins
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+#
+# 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+"""The core logic for search."""
+
+from bzrlib.plugins.search import errors
+
+
+def open_index_url(url):
+ """Open a search index at url.
+
+ :param url: The url to open the index from.
+ :return: A search index.
+ :raises: NoSearchIndex if no index can be located.
+ """
+ raise errors.NoSearchIndex(url)
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2008-06-08 05:20:44 +0000
+++ b/tests/__init__.py 2008-06-08 05:57:24 +0000
@@ -22,6 +22,8 @@
def load_tests(standard_tests, module, loader):
test_modules = [
'blackbox',
+ 'errors',
+ 'index',
]
standard_tests.addTests(loader.loadTestsFromModuleNames(
['bzrlib.plugins.search.tests.test_' + name for
=== modified file 'tests/test_blackbox.py'
--- a/tests/test_blackbox.py 2008-06-08 05:20:44 +0000
+++ b/tests/test_blackbox.py 2008-06-08 05:57:24 +0000
@@ -24,3 +24,6 @@
def test_no_parameters_error(self):
self.run_bzr_error(['needs one or more'], ['search'])
+
+ def test_no_index_error(self):
+ self.run_bzr_error(['No search index'], ['search', 'robert'])
=== added file 'tests/test_errors.py'
--- a/tests/test_errors.py 1970-01-01 00:00:00 +0000
+++ b/tests/test_errors.py 2008-06-08 05:57:24 +0000
@@ -0,0 +1,30 @@
+# search, a bzr plugin for searching within bzr branches/repositories.
+# Copyright (C) 2008 Robert Collins
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+#
+# 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+"""Tests for error formatting."""
+
+from bzrlib.plugins.search import errors
+from bzrlib.tests import TestCaseWithTransport
+
+
+class TestErrors(TestCaseWithTransport):
+
+ def test_no_index_error(self):
+ error = errors.NoSearchIndex('a url')
+ self.assertEqualDiff(
+ "No search index present for 'a url'. Please see 'bzr help index'.",
+ str(error))
=== added file 'tests/test_index.py'
--- a/tests/test_index.py 1970-01-01 00:00:00 +0000
+++ b/tests/test_index.py 2008-06-08 05:57:24 +0000
@@ -0,0 +1,29 @@
+# search, a bzr plugin for searching within bzr branches/repositories.
+# Copyright (C) 2008 Robert Collins
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+#
+# 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+"""Tests for the index layer."""
+
+from bzrlib.plugins.search import errors, index
+from bzrlib.tests import TestCaseWithTransport
+
+
+class TestIndex(TestCaseWithTransport):
+
+ def test_no_index_error(self):
+ err = self.assertRaises(errors.NoSearchIndex, index.open_index_url,
+ self.get_url())
+ self.assertEqual(self.get_url(), err.url)
More information about the bazaar-commits
mailing list