From 23d5f30c1f4f03437efa62e947607982d3753fae Mon Sep 17 00:00:00 2001 From: James Date: Mon, 28 Aug 2023 11:06:25 +0200 Subject: [PATCH] fixing server error messages (#14588) * fixing server error messages * fix tests --- conans/server/rest/controller/v2/search.py | 4 +- conans/server/service/v2/search.py | 63 ++++++++----------- .../unittests/server/service/service_test.py | 4 +- 3 files changed, 29 insertions(+), 42 deletions(-) diff --git a/conans/server/rest/controller/v2/search.py b/conans/server/rest/controller/v2/search.py index 81fa80e52e5..092694e7f41 100644 --- a/conans/server/rest/controller/v2/search.py +++ b/conans/server/rest/controller/v2/search.py @@ -27,8 +27,8 @@ def search(auth_user): @app.route(r.common_search_packages, method=["GET"]) @app.route(r.common_search_packages_revision, method=["GET"]) def search_packages(name, version, username, channel, auth_user, revision=None): - query = request.params.get("q", None) + # query is no longer server side search_service = SearchService(app.authorizer, app.server_store, auth_user) ref = RecipeReference(name, version, username, channel, revision) - info = search_service.search_packages(ref, query) + info = search_service.search_packages(ref) return info diff --git a/conans/server/service/v2/search.py b/conans/server/service/v2/search.py index aa06371a4ff..0a02134de7a 100644 --- a/conans/server/service/v2/search.py +++ b/conans/server/service/v2/search.py @@ -3,8 +3,7 @@ import re from fnmatch import translate -from conan.api.output import ConanOutput -from conans.errors import NotFoundException, ForbiddenException, RecipeNotFoundException +from conans.errors import ForbiddenException, RecipeNotFoundException from conans.model.package_ref import PkgReference from conans.model.recipe_ref import RecipeReference from conans.paths import CONANINFO @@ -13,43 +12,31 @@ from conans.util.files import load -def _get_local_infos_min(server_store, ref, look_in_all_rrevs): - +def _get_local_infos_min(server_store, ref): result = {} - rrevs = server_store.get_recipe_revisions_references(ref) if look_in_all_rrevs else [None] - - for rrev in rrevs: - new_ref = copy.copy(ref) - if rrev: - new_ref.revision = rrev.revision - subdirs = list_folder_subdirs(server_store.packages(new_ref), level=1) - for package_id in subdirs: - if package_id in result: - continue - # Read conaninfo - try: - pref = PkgReference(new_ref, package_id) - revision_entry = server_store.get_last_package_revision(pref) - if not revision_entry: - raise NotFoundException("") - pref.revision = revision_entry.revision - info_path = os.path.join(server_store.package(pref), CONANINFO) - if not os.path.exists(info_path): - raise NotFoundException("") - content = load(info_path) - # From Conan 1.48 the conaninfo.txt is sent raw. - result[package_id] = {"content": content} - except Exception as exc: # FIXME: Too wide - ConanOutput().error("Package %s has no ConanInfo file" % str(pref)) - if str(exc): - ConanOutput().error(str(exc)) + new_ref = ref + subdirs = list_folder_subdirs(server_store.packages(new_ref), level=1) + for package_id in subdirs: + if package_id in result: + continue + # Read conaninfo + pref = PkgReference(new_ref, package_id) + revision_entry = server_store.get_last_package_revision(pref) + if not revision_entry: + continue # server can store empty package-revision list files + pref.revision = revision_entry.revision + info_path = os.path.join(server_store.package(pref), CONANINFO) + if not os.path.exists(info_path): + raise Exception(f"No conaninfo.txt file for listed {pref}") + content = load(info_path) + # From Conan 1.48 the conaninfo.txt is sent raw. + result[package_id] = {"content": content} + return result -def search_packages(server_store, ref, look_in_all_rrevs): +def search_packages(server_store, ref): """ - Used both for v1 and v2. V1 will iterate rrevs. - Return a dict like this: {package_ID: {name: "OpenCV", @@ -57,7 +44,7 @@ def search_packages(server_store, ref, look_in_all_rrevs): settings: {os: Windows}}} param ref: RecipeReference object """ - if not look_in_all_rrevs and ref.revision is None: + if ref.revision is None: # TODO: Verify this sometimes happen latest_rev = server_store.get_last_revision(ref).revision ref.revision = latest_rev @@ -65,7 +52,7 @@ def search_packages(server_store, ref, look_in_all_rrevs): ref_norev.revision = None if not os.path.exists(server_store.conan_revisions_root(ref_norev)): raise RecipeNotFoundException(ref) - infos = _get_local_infos_min(server_store, ref, look_in_all_rrevs) + infos = _get_local_infos_min(server_store, ref) return infos @@ -76,10 +63,10 @@ def __init__(self, authorizer, server_store, auth_user): self._server_store = server_store self._auth_user = auth_user - def search_packages(self, reference, look_in_all_rrevs=False): + def search_packages(self, reference): """Shared between v1 and v2, v1 will iterate rrevs""" self._authorizer.check_read_conan(self._auth_user, reference) - info = search_packages(self._server_store, reference, look_in_all_rrevs) + info = search_packages(self._server_store, reference) return info def _search_recipes(self, pattern=None, ignorecase=True): diff --git a/conans/test/unittests/server/service/service_test.py b/conans/test/unittests/server/service/service_test.py index a8ad19c6449..10406efe3ce 100644 --- a/conans/test/unittests/server/service/service_test.py +++ b/conans/test/unittests/server/service/service_test.py @@ -96,11 +96,11 @@ def test_search(self): ref3_norev.revision = None self.assertEqual(info, [ref3_norev]) - info = self.search_service.search_packages(ref2, None) + info = self.search_service.search_packages(ref2) self.assertEqual(info, {'12345587754': {'content': '\n[options]\n use_Qt=False\n', }}) - info = self.search_service.search_packages(ref3, None) + info = self.search_service.search_packages(ref3) self.assertEqual(info, {'77777777777': {'content': '\n[options]\n use_Qt=True\n'} })