def test_both_types(self): """Test each object store configures files correctly. """ i = 0 with self.dataset_populator.test_history() as history_id: # Loop breaks once each object store has at least once file of each type. while True: hda = self.dataset_populator.new_dataset(history_id, content=TEST_INPUT_FILES_CONTENT, wait=True) content = self.dataset_populator.get_history_dataset_content(history_id, hda["id"]) assert content.strip() == TEST_INPUT_FILES_CONTENT files1_count = files_count(self.files1_path) files2_count = files_count(self.files2_path) if files1_count and files2_count: break i += 1 if i > 50: raise Exception("Problem with logic of test, randomly each object store should have at least one file by now") def strip_to_id(x): match = re.match(r'dataset_(.*)\.dat', os.path.basename(x)) assert match return match.group(1) files1_paths = [strip_to_id(p) for p in _get_datasets_files_in_path(self.files1_path)] files2_paths = [strip_to_id(p) for p in _get_datasets_files_in_path(self.files2_path)] for files1_path in files1_paths: assert is_uuid(files1_path) for files2_path in files2_paths: assert files2_path.isdigit()
def directory_hash_id( id ): """ >>> directory_hash_id( 100 ) ['000'] >>> directory_hash_id( "90000" ) ['090'] >>> directory_hash_id("777777777") ['000', '777', '777'] >>> directory_hash_id("135ee48a-4f51-470c-ae2f-ce8bd78799e6") ['1', '3', '5'] """ s = str( id ) l = len( s ) # Shortcut -- ids 0-999 go under ../000/ if l < 4: return [ "000" ] if not is_uuid(s): # Pad with zeros until a multiple of three padded = ( ( 3 - len( s ) % 3 ) * "0" ) + s # Drop the last three digits -- 1000 files per directory padded = padded[:-3] # Break into chunks of three return [ padded[ i * 3 : (i + 1 ) * 3 ] for i in range( len( padded ) // 3 ) ] else: # assume it is a UUID return list(iter(s[0:3]))
def directory_hash_id(id): """ >>> directory_hash_id( 100 ) ['000'] >>> directory_hash_id( "90000" ) ['090'] >>> directory_hash_id("777777777") ['000', '777', '777'] >>> directory_hash_id("135ee48a-4f51-470c-ae2f-ce8bd78799e6") ['1', '3', '5'] """ s = str(id) l = len(s) # Shortcut -- ids 0-999 go under ../000/ if l < 4: return ["000"] if not is_uuid(s): # Pad with zeros until a multiple of three padded = ((3 - len(s) % 3) * "0") + s # Drop the last three digits -- 1000 files per directory padded = padded[:-3] # Break into chunks of three return [padded[i * 3:(i + 1) * 3] for i in range(len(padded) // 3)] else: # assume it is a UUID return list(iter(s[0:3]))
def _get_dynamic_tool(self, trans, request_id): manager = self.app.dynamic_tools_manager if util.is_uuid(request_id): dynamic_tool = manager.get_tool_by_uuid(request_id) else: dynamic_tool = manager.get_tool_by_id( trans.security.decode_id(request_id)) if dynamic_tool is None: raise ObjectNotFound() return dynamic_tool
def __get_stored_workflow( self, trans, workflow_id ): if util.is_uuid(workflow_id): # see if they have passed in the UUID for a workflow that is attached to a stored workflow workflow_uuid = uuid.UUID(workflow_id) stored_workflow = trans.sa_session.query(trans.app.model.StoredWorkflow).filter( and_( trans.app.model.StoredWorkflow.latest_workflow_id == trans.app.model.Workflow.id, trans.app.model.Workflow.uuid == workflow_uuid )).first() if stored_workflow is None: raise exceptions.ObjectNotFound( "Workflow not found: %s" % workflow_id ) else: workflow_id = self.decode_id( workflow_id ) query = trans.sa_session.query( trans.app.model.StoredWorkflow ) stored_workflow = query.get( workflow_id ) if stored_workflow is None: raise exceptions.ObjectNotFound( "No such workflow found." ) return stored_workflow
def get_stored_workflow(self, trans, workflow_id): """ Use a supplied ID (UUID or encoded stored workflow ID) to find a workflow. """ if util.is_uuid(workflow_id): # see if they have passed in the UUID for a workflow that is attached to a stored workflow workflow_uuid = uuid.UUID(workflow_id) workflow_query = trans.sa_session.query(trans.app.model.StoredWorkflow).filter(and_( trans.app.model.StoredWorkflow.latest_workflow_id == trans.app.model.Workflow.id, trans.app.model.Workflow.uuid == workflow_uuid )) else: workflow_id = decode_id(self.app, workflow_id) workflow_query = trans.sa_session.query(trans.app.model.StoredWorkflow).\ filter(trans.app.model.StoredWorkflow.id == workflow_id) stored_workflow = workflow_query.options(joinedload('annotations'), joinedload('tags'), subqueryload('latest_workflow').joinedload('steps').joinedload('*')).first() if stored_workflow is None: raise exceptions.ObjectNotFound("No such workflow found.") return stored_workflow