def build_from_current_history(self, trans, job_ids=None, dataset_ids=None, dataset_collection_ids=None, workflow_name=None, dataset_names=None, dataset_collection_names=None): user = trans.get_user() history = trans.get_history() if not user: return trans.show_error_message("Must be logged in to create workflows") if (job_ids is None and dataset_ids is None) or workflow_name is None: jobs, warnings = summarize(trans) # Render return trans.fill_template( "workflow/build_from_current_history.mako", jobs=jobs, warnings=warnings, history=history ) else: # If there is just one dataset name selected or one dataset collection, these # come through as string types instead of lists. xref #3247. dataset_names = util.listify(dataset_names) dataset_collection_names = util.listify(dataset_collection_names) stored_workflow = extract_workflow( trans, user=user, job_ids=job_ids, dataset_ids=dataset_ids, dataset_collection_ids=dataset_collection_ids, workflow_name=workflow_name, dataset_names=dataset_names, dataset_collection_names=dataset_collection_names ) # Index page with message workflow_id = trans.security.encode_id(stored_workflow.id) return trans.show_message('Workflow "%s" created from current history. ' 'You can <a href="%s" target="_parent">edit</a> or <a href="%s" target="_parent">run</a> the workflow.' % (escape(workflow_name), url_for(controller='workflow', action='editor', id=workflow_id), url_for(controller='workflows', action='run', id=workflow_id)))
def test_implicit_map_job_hdca(self): creating_job = model.Job() hdca = MockHdca(implicit_output_name="out1", job=creating_job) self.history.active_datasets.append(hdca) job_dict, warnings = extract.summarize(trans=self.trans) assert not warnings assert len(job_dict) == 1 job = next(iter(job_dict.keys())) assert job is creating_job
def test_implicit_map_job_hdca(self): creating_job = model.Job() hdca = MockHdca(implicit_output_name="out1", job=creating_job) self.history.active_datasets.append(hdca) job_dict, warnings = extract.summarize(trans=self.trans) assert not warnings assert len(job_dict) == 1 job = job_dict.keys()[0] assert job is creating_job
def test_fake_job_hdca(self): hdca = MockHdca() self.history.active_datasets.append(hdca) job_dict, warnings = extract.summarize(trans=self.trans) assert not warnings assert len(job_dict) == 1 fake_job = next(iter(job_dict.keys())) assert fake_job.id.startswith("fake_") assert fake_job.is_fake content_instances = next(iter(job_dict.values())) assert content_instances == [(None, hdca)]
def test_finds_original_job_if_copied(self): hda = MockHda() derived_hda_1 = MockHda() derived_hda_1.copied_from_history_dataset_association = hda derived_hda_2 = MockHda() derived_hda_2.copied_from_history_dataset_association = derived_hda_1 self.history.active_datasets.append(derived_hda_2) job_dict, warnings = extract.summarize(trans=self.trans) assert not warnings assert len(job_dict) == 1 self.assertEqual(job_dict[hda.job], [('out1', derived_hda_2)])
def test_fake_job_hdca(self): hdca = MockHdca() self.history.active_datasets.append(hdca) job_dict, warnings = extract.summarize(trans=self.trans) assert not warnings assert len(job_dict) == 1 fake_job = job_dict.keys()[0] assert fake_job.id.startswith("fake_") assert fake_job.is_fake content_instances = next(iter(job_dict.values())) assert content_instances == [(None, hdca)]
def test_fake_job_hda_name_guess(self): hda_from_history = MockHda(job=UNDEFINED_JOB) hda_from_history.copied_from_history_dataset_association = MockHda( job=UNDEFINED_JOB) self.history.active_datasets.append(hda_from_history) job_dict, warnings = extract.summarize(trans=self.trans) assert not warnings assert len(job_dict) == 1 fake_job = next(iter(job_dict.keys())) assert "History" in fake_job.name self.history.active_datasets.remove(hda_from_history) hda_from_library = MockHda(job=UNDEFINED_JOB) hda_from_library.copied_from_library_dataset_dataset_association = MockHda( job=UNDEFINED_JOB) self.history.active_datasets.append(hda_from_library) job_dict, warnings = extract.summarize(trans=self.trans) assert not warnings assert len(job_dict) == 1 fake_job = next(iter(job_dict.keys())) assert "Library" in fake_job.name
def test_fake_job_hda(self): """ Fakes job if creating_job_associations is empty. """ hda = MockHda(job=UNDEFINED_JOB) self.history.active_datasets.append(hda) job_dict, warnings = extract.summarize(trans=self.trans) assert not warnings assert len(job_dict) == 1 fake_job = next(iter(job_dict.keys())) assert fake_job.id.startswith("fake_") datasets = next(iter(job_dict.values())) assert datasets == [(None, hda)]
def test_fake_job_hda(self): """ Fakes job if creating_job_associations is empty. """ hda = MockHda(job=UNDEFINED_JOB) self.history.active_datasets.append(hda) job_dict, warnings = extract.summarize(trans=self.trans) assert not warnings assert len(job_dict) == 1 fake_job = job_dict.keys()[0] assert fake_job.id.startswith("fake_") datasets = list(job_dict.values())[0] assert datasets == [(None, hda)]
def get_workflow(this): from galaxy import util from galaxy.webapps.galaxy.controllers.workflow import WorkflowController from galaxy.workflow.extract import extract_workflow from galaxy.workflow.extract import summarize tmpuser = this.user if not this.user: tmpusername = os.getenv('GALAXY_DEFAULT_WORKFLOWGENERATOR_USER', os.environ['GALAXY_DEFAULT_ADMIN_USER']) if not tmpusername: tmpuser = UserManager(this.trans.app).admins()[0] tmpuser = this.trans.sa_session.query(this.trans.app.model.User).filter_by(username=tmpusername,deleted=False).all()[0] #html = WorkflowController(this.trans.app).build_from_current_history(this.trans) #use reimplementation since controller does user=trans.get_user() || error jobs, warnings = summarize(this.trans) html = this.trans.fill_template("workflow/build_from_current_history.mako", jobs=jobs, warnings=warnings, history=this.history) job_ids = re.findall('job_ids.+value="([^"]+)',html) dataset_ids = re.findall('dataset_ids.+value="([^"]+)',html) dataset_names = re.findall('dataset_names.+value="([^"]+)',html) dataset_collection_ids = re.findall('dataset_collection_ids.+value="(\d+)',html) dataset_collection_names = re.findall('dataset_collection_names.+value="(\d+)',html) dataset_names = util.listify(dataset_names) dataset_collection_names = util.listify(dataset_collection_names) stored = extract_workflow( this.trans, user=tmpuser, job_ids=job_ids, dataset_ids=dataset_ids, dataset_collection_ids=dataset_collection_ids, workflow_name='de.STAIR Guide Workflow', dataset_names=dataset_names, dataset_collection_names=dataset_collection_names ) this.workflow = WorkflowController(this.trans.app)._workflow_to_dict(this.trans, stored) # reimplement deletion which originally makes use of get_stored_workflow which failes in case of anon user stored.deleted = True tmpuser.stored_workflow_menu_entries = [entry for entry in tmpuser.stored_workflow_menu_entries if entry.stored_workflow != stored] this.trans.sa_session.add(stored) this.trans.sa_session.flush() return { 'workflow': this.workflow }
def test_summarize_returns_name_and_dataset_list(self): # Create two jobs and three datasets, test they are groupped # by job correctly with correct output names. hda1 = MockHda() self.history.active_datasets.append(hda1) hda2 = MockHda(job=hda1.job, output_name="out2") self.history.active_datasets.append(hda2) hda3 = MockHda(output_name="out3") self.history.active_datasets.append(hda3) job_dict, warnings = extract.summarize(trans=self.trans) assert len(job_dict) == 2 assert not warnings self.assertEqual(job_dict[hda1.job], [('out1', hda1), ('out2', hda2)]) self.assertEqual(job_dict[hda3.job], [('out3', hda3)])
def test_empty_history(self): job_dict, warnings = extract.summarize(trans=self.trans) assert not warnings assert not job_dict
def test_warns_and_skips_datasets_if_not_finished(self): hda = MockHda(state='queued') self.history.active_datasets.append(hda) job_dict, warnings = extract.summarize(trans=self.trans) assert warnings assert len(job_dict) == 0