Skip to content

Commit

Permalink
Merge 8d847ec into 7049e8b
Browse files Browse the repository at this point in the history
  • Loading branch information
dralley committed Dec 14, 2018
2 parents 7049e8b + 8d847ec commit 88b9de2
Showing 1 changed file with 78 additions and 7 deletions.
85 changes: 78 additions & 7 deletions pulp_smash/pulp3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,16 @@ def get_content(repo, version_href=None):

if version_href is None:
# Repository has no latest version, and therefore no content.
return []
return {}

client = api.Client(config.get_config(), api.page_handler)
return client.get(urljoin(version_href, 'content/'))
repo_version = client.get(version_href)

content = {}
for content_type, content_url in repo_version['content_hrefs'].items():
typed_content = client.get(content_url)
content[content_type] = typed_content
return content


def get_added_content(repo, version_href=None):
Expand All @@ -146,10 +152,16 @@ def get_added_content(repo, version_href=None):

if version_href is None:
# Repository has no latest version, and therefore no content.
return []
return {}

client = api.Client(config.get_config(), api.page_handler)
return client.get(urljoin(version_href, 'added_content/'))
repo_version = client.get(version_href)

content = {}
for content_type, content_url in repo_version['content_added_hrefs'].items():
typed_content = client.get(content_url)
content[content_type] = typed_content
return content


def get_removed_content(repo, version_href=None):
Expand All @@ -165,10 +177,16 @@ def get_removed_content(repo, version_href=None):

if version_href is None:
# Repository has no latest version, and therefore no content.
return []
return {}

client = api.Client(config.get_config(), api.page_handler)
return client.get(urljoin(version_href, 'removed_content/'))
repo_version = client.get(version_href)

content = {}
for content_type, content_url in repo_version['content_removed_hrefs'].items():
typed_content = client.get(content_url)
content[content_type] = typed_content
return content


def get_content_summary(repo, version_href=None):
Expand All @@ -192,6 +210,48 @@ def get_content_summary(repo, version_href=None):
return client.get(version_href)['content_summary']


def get_content_added_summary(repo, version_href=None):
"""Read the "content summary" of a given repository version.
Repository versions have a "content_summary" which lists the content types
and the number of units of that type present in the repo version.
:param repo: A dict of information about the repository.
:param version_href: The repository version to read. If none, read the
latest repository version.
:returns: The "content_summary" of the repo version.
"""
version_href = version_href or repo['_latest_version_href']

if version_href is None:
# Repository has no latest version, and therefore no content.
return {}

client = api.Client(config.get_config(), api.page_handler)
return client.get(version_href)['content_added_summary']


def get_content_removed_summary(repo, version_href=None):
"""Read the "content summary" of a given repository version.
Repository versions have a "content_summary" which lists the content types
and the number of units of that type present in the repo version.
:param repo: A dict of information about the repository.
:param version_href: The repository version to read. If none, read the
latest repository version.
:returns: The "content_summary" of the repo version.
"""
version_href = version_href or repo['_latest_version_href']

if version_href is None:
# Repository has no latest version, and therefore no content.
return {}

client = api.Client(config.get_config(), api.page_handler)
return client.get(version_href)['content_removed_summary']


def delete_orphans(cfg=None):
"""Clean all content units present in pulp.
Expand Down Expand Up @@ -231,7 +291,18 @@ def get_artifact_paths(repo, version_href=None):
:returns: A set with the paths of units present in a given repository.
"""
# content['artifact'] consists of a file path and name.
return {content['artifact'] for content in get_content(repo, version_href)}
artifact_paths = set()
for typed_content in get_content(repo, version_href).values():
for content in typed_content:
# some content types with 1-to-1 artifact-content relationship
# override 'artifacts', but some plugins will still have multiple
# artifacts for their content.
if content.get('artifact'):
artifact_paths.add(content['artifact'])
else:
for artifact in content.get('artifacts'):
artifact_paths.add(artifact)
return artifact_paths


def delete_version(repo, version_href=None):
Expand Down

0 comments on commit 88b9de2

Please sign in to comment.