示例#1
0
 def publish(self):
     """
     Publish the repository.
     """
     manifest = Manifest('PULP_MANIFEST')
     manifest.write(self._publish())
     metadata = PublishedMetadata(
         relative_path=os.path.basename(manifest.path),
         publication=self.publication,
         file=File(open(manifest.path, 'rb')))
     metadata.save()
示例#2
0
def publish(publisher_pk, repository_version_pk):
    """
    Use provided publisher to create a Publication based on a RepositoryVersion.

    Args:
        publisher_pk (str): Use the publish settings provided by this publisher.
        repository_version_pk (str): Create a publication from this repository version.

    """
    if publisher_pk:
        publisher = FilePublisher.objects.get(pk=publisher_pk)
        manifest = publisher.manifest
        publisher_name = publisher.name
    else:
        publisher = None
        manifest = 'PULP_MANIFEST'
        publisher_name = ''

    repo_version = RepositoryVersion.objects.get(pk=repository_version_pk)

    log.info(
        _('Publishing: repository={repo}, version={ver}, publisher={pub}').
        format(
            repo=repo_version.repository.name,
            ver=repo_version.number,
            pub=publisher_name,
        ))

    with WorkingDirectory():
        with FilePublication.create(repo_version, publisher,
                                    pass_through=True) as publication:
            manifest = Manifest(manifest)
            manifest.write(populate(publication))
            metadata = PublishedMetadata(
                relative_path=os.path.basename(manifest.relative_path),
                publication=publication,
                file=File(open(manifest.relative_path, 'rb')))
            metadata.save()

    log.info(
        _('Publication: {publication} created').format(
            publication=publication.pk))