def synchronize(remote_pk, repository_pk, mirror): """ Sync content from the remote repository. Create a new version of the repository that is synchronized with the remote. Args: remote_pk (str): The remote PK. repository_pk (str): The repository PK. mirror (bool): True for mirror mode, False for additive. Raises: ValueError: If the remote does not specify a URL to sync. """ remote = FileRemote.objects.get(pk=remote_pk) repository = Repository.objects.get(pk=repository_pk) if not remote.url: raise ValueError( _("A remote must have a url specified to synchronize.")) first_stage = FileFirstStage(remote) dv = DeclarativeVersion(first_stage, repository, mirror=mirror) dv.create()
def synchronize(remote_pk, repository_pk, mirror=False): """ Sync content from the remote repository. Create a new version of the repository that is synchronized with the remote. Args: remote_pk (str): The remote PK. repository_pk (str): The repository PK. mirror (bool): True for mirror mode, False for additive. Raises: ValueError: If the remote does not specify a URL to sync. """ remote = GitRemote.objects.get(pk=remote_pk) repository = AnsibleRepository.objects.get(pk=repository_pk) if not remote.url: raise ValueError( _("A remote must have a url specified to synchronize.")) log.info(_("Synchronizing: repository=%(r)s remote=%(p)s"), { "r": repository.name, "p": remote.name }) first_stage = GitFirstStage(remote) d_version = DeclarativeVersion(first_stage, repository, mirror=mirror) return d_version.create()
def synchronize(remote_pk, repository_pk, mirror): """ Sync content from the remote repository. Create a new version of the repository that is synchronized with the remote. Args: remote_pk (str): The remote PK. repository_pk (str): The repository PK. mirror (bool): True for mirror mode, False for additive. Raises: ValueError: If the remote does not specify a URL to sync. """ remote = FileRemote.objects.get(pk=remote_pk) repository = FileRepository.objects.get(pk=repository_pk) if not remote.url: raise ValueError( _("A remote must have a url specified to synchronize.")) first_stage = FileFirstStage(remote) dv = DeclarativeVersion(first_stage, repository, mirror=mirror) rv = dv.create() if rv and mirror: # TODO: this is awful, we really should rewrite the DeclarativeVersion API to # accomodate this use case global metadata_files with FilePublication.create(rv, pass_through=True) as publication: (mdfile_path, relative_path) = metadata_files.pop() PublishedMetadata.create_from_file( file=File(open(mdfile_path, "rb")), relative_path=relative_path, publication=publication, ) publication.manifest = relative_path publication.save() log.info( _("Publication: {publication} created").format( publication=publication.pk)) return rv