From cfe97d392429793d03945ca61229a19033f22c39 Mon Sep 17 00:00:00 2001 From: Mitch Roote Date: Sat, 8 Feb 2020 00:41:18 -0500 Subject: [PATCH 1/6] Add method to copy repo content --- pubtools/pulplib/_impl/client/client.py | 12 ++++++++++++ setup.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pubtools/pulplib/_impl/client/client.py b/pubtools/pulplib/_impl/client/client.py index 65c52558..f1278147 100644 --- a/pubtools/pulplib/_impl/client/client.py +++ b/pubtools/pulplib/_impl/client/client.py @@ -316,6 +316,18 @@ def set_maintenance(self, report): return f_flat_map(upload_ft, lambda _: repo.publish()) + def copy_repo_content(self, origin_repo, dest_repo): + url = os.path.join( + self._url, + "pulp/api/v2/repositories/%s/actions/associate/" % dest_repo + ) + + body = {"source_repo_id": origin_repo} + + return self._task_executor.submit( + self._do_request, method="POST", url=url, json=body + ) + def get_content_type_ids(self): """Get the content types supported by this Pulp server. diff --git a/setup.py b/setup.py index 5feb4896..729657a5 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def get_requirements(): setup( name="pubtools-pulplib", - version="2.4.0", + version="2.4.1", packages=find_packages(exclude=["tests"]), package_data={"pubtools.pulplib._impl.schema": ["*.yaml"]}, url="https://github.com/release-engineering/pubtools-pulplib", From 3586d8fa0b4a3194604d3487ea120dd520bc71b3 Mon Sep 17 00:00:00 2001 From: Mitch Roote Date: Sat, 8 Feb 2020 01:10:57 -0500 Subject: [PATCH 2/6] Add optional params to copy api call --- pubtools/pulplib/_impl/client/client.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pubtools/pulplib/_impl/client/client.py b/pubtools/pulplib/_impl/client/client.py index f1278147..1469d4ba 100644 --- a/pubtools/pulplib/_impl/client/client.py +++ b/pubtools/pulplib/_impl/client/client.py @@ -316,16 +316,20 @@ def set_maintenance(self, report): return f_flat_map(upload_ft, lambda _: repo.publish()) - def copy_repo_content(self, origin_repo, dest_repo): + def copy_repo_content(self, origin_repo, dest_repo, criteria=None, override_config=None): url = os.path.join( self._url, "pulp/api/v2/repositories/%s/actions/associate/" % dest_repo ) - body = {"source_repo_id": origin_repo} + data = {"source_repo_id": origin_repo} + if criteria: + data['criteria'] = criteria + if override_config: + data['override_config'] = override_config return self._task_executor.submit( - self._do_request, method="POST", url=url, json=body + self._do_request, method="POST", url=url, json=data ) def get_content_type_ids(self): From af24718cda2abbaa6b60d878cd28400c529c15ab Mon Sep 17 00:00:00 2001 From: Mitch Roote Date: Sat, 8 Feb 2020 02:47:05 -0500 Subject: [PATCH 3/6] Add docstring comment for copy_repo method --- pubtools/pulplib/_impl/client/client.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pubtools/pulplib/_impl/client/client.py b/pubtools/pulplib/_impl/client/client.py index 1469d4ba..73d6f2f4 100644 --- a/pubtools/pulplib/_impl/client/client.py +++ b/pubtools/pulplib/_impl/client/client.py @@ -317,6 +317,21 @@ def set_maintenance(self, report): return f_flat_map(upload_ft, lambda _: repo.publish()) def copy_repo_content(self, origin_repo, dest_repo, criteria=None, override_config=None): + """ + Args: + origin_repo: + String of the origin repo name + dest_repo: + String of the destination repo name + criteria: + optional Criteria object with filter parameters + override_config: + optional dictionary to override configuration options + Return: + Future[list[:class:`~pubtools.pulplib.Task`]] + A future which is resolved when the packages have been copied + to the destination repo + """ url = os.path.join( self._url, "pulp/api/v2/repositories/%s/actions/associate/" % dest_repo From 86c365e28bda34b6c5d21d04be8db314d51ea2af Mon Sep 17 00:00:00 2001 From: Mitch Roote Date: Sat, 8 Feb 2020 07:24:57 -0500 Subject: [PATCH 4/6] Bump version to 2.5.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 729657a5..b2fde7fd 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def get_requirements(): setup( name="pubtools-pulplib", - version="2.4.1", + version="2.5.0", packages=find_packages(exclude=["tests"]), package_data={"pubtools.pulplib._impl.schema": ["*.yaml"]}, url="https://github.com/release-engineering/pubtools-pulplib", From ab60d8bd0820f2ea004c97401ff6af9d4319d299 Mon Sep 17 00:00:00 2001 From: Mitch Roote Date: Sat, 8 Feb 2020 07:51:57 -0500 Subject: [PATCH 5/6] Black formatting --- pubtools/pulplib/_impl/client/client.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pubtools/pulplib/_impl/client/client.py b/pubtools/pulplib/_impl/client/client.py index 73d6f2f4..bde72bdc 100644 --- a/pubtools/pulplib/_impl/client/client.py +++ b/pubtools/pulplib/_impl/client/client.py @@ -316,7 +316,9 @@ def set_maintenance(self, report): return f_flat_map(upload_ft, lambda _: repo.publish()) - def copy_repo_content(self, origin_repo, dest_repo, criteria=None, override_config=None): + def copy_repo_content( + self, origin_repo, dest_repo, criteria=None, override_config=None + ): """ Args: origin_repo: @@ -333,15 +335,14 @@ def copy_repo_content(self, origin_repo, dest_repo, criteria=None, override_conf to the destination repo """ url = os.path.join( - self._url, - "pulp/api/v2/repositories/%s/actions/associate/" % dest_repo + self._url, "pulp/api/v2/repositories/%s/actions/associate/" % dest_repo ) data = {"source_repo_id": origin_repo} if criteria: - data['criteria'] = criteria + data["criteria"] = criteria if override_config: - data['override_config'] = override_config + data["override_config"] = override_config return self._task_executor.submit( self._do_request, method="POST", url=url, json=data From 2b383900f482153a69e96c511ad6c717e7ae2aaa Mon Sep 17 00:00:00 2001 From: Allen Ji Date: Fri, 6 Mar 2020 16:37:06 -0500 Subject: [PATCH 6/6] Incorporate search by regex to copy_repo_content --- pubtools/pulplib/_impl/client/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pubtools/pulplib/_impl/client/client.py b/pubtools/pulplib/_impl/client/client.py index bde72bdc..677ad9dc 100644 --- a/pubtools/pulplib/_impl/client/client.py +++ b/pubtools/pulplib/_impl/client/client.py @@ -340,7 +340,8 @@ def copy_repo_content( data = {"source_repo_id": origin_repo} if criteria: - data["criteria"] = criteria + prepared_search = search_for_criteria(criteria) + data["criteria"] = { "filters": prepared_search.filters} if override_config: data["override_config"] = override_config