def run(self, **kwargs): """ The run function for the export command. This is the self.method method which is defined in the Command super class. This method does all the work for a group export run call. """ # Grab all the configuration options group_id = kwargs[options.OPTION_GROUP_ID.keyword] iso_prefix = kwargs[OPTION_ISO_PREFIX.keyword] iso_size = kwargs[OPTION_ISO_SIZE.keyword] start_date = kwargs[OPTION_START_DATE.keyword] end_date = kwargs[OPTION_END_DATE.keyword] export_dir = kwargs[OPTION_EXPORT_DIR.keyword] serve_http = kwargs[SERVE_HTTP] serve_https = kwargs[SERVE_HTTPS] background = kwargs[BACKGROUND] # Since the export distributor is not added to a repository group on creation, add it here # if it is not already associated with the group id try: self.context.server.repo_group_distributor.distributor(group_id, self.distributor_id) except exceptions.NotFoundException: distributor_config = { constants.PUBLISH_HTTP_KEYWORD: serve_http, constants.PUBLISH_HTTPS_KEYWORD: serve_https, } self.context.server.repo_group_distributor.create( group_id, ids.TYPE_ID_DISTRIBUTOR_GROUP_EXPORT, distributor_config, self.distributor_id ) publish_config = { constants.PUBLISH_HTTP_KEYWORD: serve_http, constants.PUBLISH_HTTPS_KEYWORD: serve_https, constants.ISO_PREFIX_KEYWORD: iso_prefix, constants.ISO_SIZE_KEYWORD: iso_size, constants.START_DATE_KEYWORD: start_date, constants.END_DATE_KEYWORD: end_date, constants.EXPORT_DIRECTORY_KEYWORD: export_dir, } self.prompt.render_title(_("Exporting Repository Group [%s]" % group_id)) # Retrieve all publish tasks for this repository group task_id = _get_publish_task_id("repository_group", group_id, self.context) if task_id is not None: msg = _("A publish task is already in progress for this repository.") if not background: msg += _(" Its progress will be tracked below.") self.context.prompt.render_paragraph(msg, tag="in-progress") else: # If there is no existing publish for this repo group, start one response = self.context.server.repo_group_actions.publish(group_id, self.distributor_id, publish_config) task_id = response.response_body.task_id if not background: # Show the task status status.display_task_status(self.context, self.renderer, task_id) else: msg = _("The status of this publish can be displayed using the status command.") self.context.prompt.render_paragraph(msg, "background")
def run(self, **kwargs): """ This is the self.method method which is defined in the Command super class. This method does all the work for a group export status call. """ group_id = kwargs[options.OPTION_GROUP_ID.keyword] self.prompt.render_title(_("Repository Group [%s] Export Status" % group_id)) # Retrieve the task id, if it exists task_id = _get_publish_task_id("repository_group", group_id, self.context) if task_id is None: msg = _("The repository group is not performing any operations") self.prompt.render_paragraph(msg, tag="no-tasks") else: status.display_task_status(self.context, self.renderer, task_id)
def run(self, **kwargs): repo_id = kwargs[options.OPTION_REPO_ID.keyword] background = kwargs[NAME_BACKGROUND] override_config = {} # Generate override_config if any of the override options are passed. if self.override_config_keywords: override_config = self.generate_override_config(**kwargs) self.prompt.render_title( _('Publishing Repository [%(r)s]') % {'r': repo_id}) # Display override configuration used if override_config: self.prompt.render_paragraph( _('The following publish configuration options will be used:')) self.prompt.render_document(override_config) # See if an existing publish is running for the repo. If it is, resume # progress tracking. existing_publish_tasks = self.context.server.tasks.get_repo_publish_tasks( repo_id).response_body task_id = tasks.relevant_existing_task_id(existing_publish_tasks) if task_id is not None: msg = _( 'A publish task is already in progress for this repository. ') if not background: msg += _('Its progress will be tracked below.') self.context.prompt.render_paragraph(msg, tag='in-progress') else: if not override_config: override_config = None response = self.context.server.repo_actions.publish( repo_id, self.distributor_id, override_config) task_id = response.response_body.task_id if not background: status.display_task_status(self.context, self.renderer, task_id) else: msg = _( 'The status of this publish can be displayed using the status command.' ) self.context.prompt.render_paragraph(msg, 'background')
def run(self, **kwargs): repo_id = kwargs[options.OPTION_REPO_ID.keyword] background = kwargs[NAME_BACKGROUND] override_config = {} # Generate override_config if any of the override options are passed. if self.override_config_keywords: override_config = self.generate_override_config(**kwargs) self.prompt.render_title(_('Publishing Repository [%(r)s]') % {'r' : repo_id}) # Display override configuration used if override_config: self.prompt.render_paragraph(_('The following publish configuration options will be used:')) self.prompt.render_document(override_config) # See if an existing publish is running for the repo. If it is, resume # progress tracking. existing_publish_tasks = self.context.server.tasks.get_repo_publish_tasks(repo_id).response_body task_id = tasks.relevant_existing_task_id(existing_publish_tasks) if task_id is not None: msg = _('A publish task is already in progress for this repository. ') if not background: msg += _('Its progress will be tracked below.') self.context.prompt.render_paragraph(msg, tag='in-progress') else: if not override_config: override_config = None response = self.context.server.repo_actions.publish(repo_id, self.distributor_id, override_config) task_id = response.response_body.task_id if not background: status.display_task_status(self.context, self.renderer, task_id) else: msg = _('The status of this publish can be displayed using the status command.') self.context.prompt.render_paragraph(msg, 'background')
def test_display_task_status(self, mock_display, mock_get): """ Simple test to make sure the pass through to _display_status is correct. """ # Setup task = mock.MagicMock() mock_get.return_value = mock.MagicMock() mock_get.return_value.response_body = task task_id = 'fus' # Test status.display_task_status(self.context, self.renderer, task_id) # Verify self.assertEqual(1, mock_get.call_count) self.assertEqual(task_id, mock_get.call_args[0][0]) self.assertEqual(1, mock_display.call_count) self.assertEqual(self.context, mock_display.call_args[0][0]) self.assertEqual(self.renderer, mock_display.call_args[0][1]) self.assertEqual([task], mock_display.call_args[0][2])