def execute_install(self): """ Install a collection. """ self.log.debug('self.options: %s', self.options) galaxy_context = self._get_galaxy_context(self.options, self.config) requested_spec_strings = self.args # TODO: build requirement_specs from requested_collection_specs strings rc = install.install_repository_specs_loop( galaxy_context, editable=self.options.editable_install, repository_spec_strings=requested_spec_strings, namespace_override=self.options.namespace, display_callback=self.display, ignore_errors=self.options.ignore_errors, no_deps=self.options.no_deps, force_overwrite=self.options.force) return rc
def sync(remote_pk, repository_pk): """ Sync Collections with ``remote_pk``, and save a new RepositoryVersion for ``repository_pk``. Args: remote_pk (str): The remote PK. repository_pk (str): The repository PK. Raises: ValueError: If the remote does not specify a URL to sync or a ``whitelist`` of Collections to sync. """ remote = CollectionRemote.objects.get(pk=remote_pk) repository = Repository.objects.get(pk=repository_pk) if not remote.url: raise ValueError( _("A CollectionRemote must have a 'url' specified to synchronize.") ) if not remote.whitelist: raise ValueError( _("A CollectionRemote must have a 'whitelist' specified to synchronize." )) repository_spec_strings = remote.whitelist.split(' ') def nowhere(*args, **kwargs): pass collections_created_pks = [] with tempfile.TemporaryDirectory() as temp_ansible_path: galaxy_context = GalaxyContext( collections_path=temp_ansible_path, server={ 'url': remote.url, 'ignore_certs': False, }, ) install_repository_specs_loop( display_callback=nowhere, galaxy_context=galaxy_context, repository_spec_strings=repository_spec_strings, ) content_walk_generator = os.walk(temp_ansible_path) for dirpath, dirnames, filenames in content_walk_generator: if 'MANIFEST.json' in filenames: with open(dirpath + os.path.sep + 'MANIFEST.json') as manifest_file: manifest_data = json.load(manifest_file) info = manifest_data['collection_info'] filename = '{namespace}-{name}-{version}'.format( namespace=info['namespace'], name=info['name'], version=info['version'], ) tarfile_path = temp_ansible_path + os.path.sep + filename + '.tar.gz' with tarfile.open(name=tarfile_path, mode='w|gz') as newtar: newtar.add(dirpath, arcname=filename) with transaction.atomic(): collection, created = Collection.objects.get_or_create( namespace=info['namespace'], name=info['name'], version=info['version']) if created: artifact = Artifact.init_and_validate(newtar.name) artifact.save() ContentArtifact.objects.create( artifact=artifact, content=collection, relative_path=collection.relative_path, ) collections_created_pks.append(collection) if collections_created_pks: with RepositoryVersion.create(repository) as new_version: collections = Collection.objects.filter( pk__in=collections_created_pks) new_version.add_content(collections)