def add(self, input_name, input_value): if self.input_name_prefix is not None: if input_name.startswith(self.input_name_prefix): input_name = input_name[len(self.input_name_prefix):] else: # Skip inputs that don't start with prefix return if ':' in input_name: input_class = input_name[input_name.find(':') + 1:] input_name = input_name[:input_name.find(':')] else: input_class = None if self.input_spec is not None: if input_name not in self.input_spec: raise Exception('Input field called ' + input_name + ' was not found in the input spec') input_class = self.input_spec[input_name]['class'] if input_class is None: done = False try: # Resolve "job-xxxx:output-name" syntax into a canonical job ref job_id, field = split_unescaped(':', input_value) if is_job_id(job_id) or is_localjob_id(job_id): input_value = {"job": job_id, "field": field} done = True except: pass if not done: try: parsed_input_value = json.loads(input_value, object_pairs_hook=collections.OrderedDict) if type(parsed_input_value) in (collections.OrderedDict, list, int, long, float): input_value = parsed_input_value else: raise Exception() except: # Not recognized JSON (list or dict), so resolve it as a name try: project, folderpath, entity_result = resolve_existing_path(input_value, expected='entity') except: # If not possible, then leave it as a string project, folderpath, entity_result = None, None, None if entity_result is not None: if is_hashid(input_value): input_value = {'$dnanexus_link': entity_result['id']} else: input_value = {"$dnanexus_link": {"project": entity_result['describe']['project'], "id": entity_result['id']}} self.inputs[input_name].append(input_value) else: # Input class is known. Respect the "array" class. input_value = parse_input_or_jbor(input_class, input_value) if input_class.startswith('array:'): self.inputs[input_name].append(input_value) else: self.inputs[input_name] = input_value
def parse_obj(string, klass): if string == '': raise ValueError('Error: Nonempty string cannot be resolved') project, path, entity_result = resolve_existing_path(string) if entity_result is None: raise TypeError('Could not resolve \"' + string + '\" to a name or ID') if not entity_result['describe']['class'] == klass: raise TypeError('Error: The given object is of class ' + entity_result['describe']['class'] + ' but an object of class ' + klass + ' was expected.') if is_hashid(string): return {'$dnanexus_link': entity_result['id']} else: return {'$dnanexus_link': {"project": entity_result['describe']['project'], "id": entity_result['id']}}
def parse_obj(string, klass): if string == '': raise ValueError('Error: Nonempty string cannot be resolved') project, path, entity_result = resolve_existing_path(string) if entity_result is None: raise TypeError('Could not resolve \"' + string + '\" to a name or ID') if not entity_result['describe']['class'] == klass: raise TypeError('Error: The given object is of class ' + entity_result['describe']['class'] + ' but an object of class ' + klass + ' was expected.') if is_hashid(string): return {'$dnanexus_link': entity_result['id']} else: return { '$dnanexus_link': { "project": entity_result['describe']['project'], "id": entity_result['id'] } }
def add(self, input_name, input_value): if self.input_name_prefix is not None: if input_name.startswith(self.input_name_prefix): input_name = input_name[len(self.input_name_prefix):] else: # Skip inputs that don't start with prefix return if ':' in input_name: input_class = input_name[input_name.find(':') + 1:] input_name = input_name[:input_name.find(':')] else: input_class = None if self.input_spec is not None: if input_name not in self.input_spec and self._desc.get( 'class') != 'workflow': raise Exception('Input field called ' + input_name + ' was not found in the input spec') elif input_name in self.input_spec: input_class = self.input_spec[input_name]['class'] if input_class is None: done = False try: # Resolve "job-xxxx:output-name" syntax into a canonical job ref job_id, field = split_unescaped(':', input_value) if is_job_id(job_id) or is_localjob_id(job_id): input_value = {"job": job_id, "field": field} done = True except: pass if not done: try: parsed_input_value = json.loads( input_value, object_pairs_hook=collections.OrderedDict) if type(parsed_input_value) in (collections.OrderedDict, list, int, long, float): input_value = parsed_input_value else: raise Exception() except: # Not recognized JSON (list or dict), so resolve it as a name try: project, folderpath, entity_result = resolve_existing_path( input_value, expected='entity') except: # If not possible, then leave it as a string project, folderpath, entity_result = None, None, None if entity_result is not None: if is_hashid(input_value): input_value = { '$dnanexus_link': entity_result['id'] } else: input_value = { "$dnanexus_link": { "project": entity_result['describe']['project'], "id": entity_result['id'] } } if isinstance(self.inputs[input_name], list) and \ not isinstance(self.inputs[input_name], basestring): self.inputs[input_name].append(input_value) else: self.inputs[input_name] = input_value else: # Input class is known. Respect the "array" class. input_value = parse_input_or_jbor(input_class, input_value) if input_class.startswith('array:'): self.inputs[input_name].append(input_value) else: self.inputs[input_name] = input_value