Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow import/export of content not directly tied to repos #819

Merged
merged 1 commit into from
Aug 10, 2020

Conversation

daviddavis
Copy link
Contributor

fixes #7252

Please be sure you have read our documentation on creating PRs:
https://docs.pulpproject.org/contributing/pull-request-walkthrough.html

@daviddavis
Copy link
Contributor Author

Note this is WIP PR that only handles exporting the mapping so far. Here is an example of how this would be used:

class PackageResource(BaseContentResource):
    """
    Resource for import/export of rpm_package entities.
    """
    content_mapping = {}

    def _add_to_mapping(self, repo, uuids):
        if not uuids.exists():
            return

        self.content_mapping[repo.name] = list(map(str, uuids))

    def set_up_queryset(self):
        """
        :return: Packages specific to a specified repo-version.
        """
        packages = Package.objects.filter(pk__in=self.repo_version.content)
        self._add_to_mapping(self.repo_version.repository, packages.values_list("pulp_id",
                                                                                flat=True))

        tree = DistributionTree.objects.filter(pk__in=self.repo_version.content).first()
        if tree:
            for repo in tree.repositories():
                version = repo.latest_version()
                packages |= Package.objects.filter(pk__in=version.content)
                self._add_to_mapping(repo, packages.values_list("pulp_id", flat=True))

        return packages

    class Meta:
        model = Package
        import_id_fields = model.natural_key_fields()

And here is an example of the content_mapping that gets exported: https://gist.github.com/daviddavis/5d1575c6f89521bb3bff559afb7b5f2b.

@pulpbot
Copy link
Member

pulpbot commented Aug 3, 2020

Attached issue: https://pulp.plan.io/issues/7252

pulpcore/app/importexport.py Show resolved Hide resolved
pulpcore/app/importexport.py Outdated Show resolved Hide resolved
pulpcore/app/tasks/importer.py Show resolved Hide resolved


def _destination_repo(importer, source_repo_name):
"""Find the destination repository based on source repo's name."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Args are missing in the doc string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since PEP 257 only applies to public methods, I only added a single line docstring to give a general overview of the method since I didn't feel like an entire docstring was necessary.

pulpcore/plugin/importexport.py Outdated Show resolved Hide resolved
CHANGES/plugin_api/7252.feature Outdated Show resolved Hide resolved
@daviddavis daviddavis force-pushed the issue7252 branch 2 times, most recently from 66ac2d7 to ff8bd94 Compare August 10, 2020 15:30
Copy link
Member

@goosemania goosemania left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@goosemania
Copy link
Member

Travis is failing but I don't need to re-review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants