def submit(self, allow_invalid=False): self.db_desc = Descriptor() self.db_desc.is_public = self.is_public self.db_desc.user_id = self.user file = create_temporary_file(self.container.get_data()) if (isinstance(self.container, DescriptorDataCandidateURLContainer)): self.db_desc.data_url = self.container.get_url() self.db_desc.automatic_updating = self.automatic_updating else: self.db_desc.data_url = "" filename = uuid.uuid4().hex self.db_desc.data_file.save(filename, ContentFile(self.container.get_data())) self.db_desc.md5 = calculate_MD5(self.container.get_data()) if (self.carmin_platform): self.db_desc.carmin_platform = self.carmin_platform # Validation try: bosh.validate(file.name) self.validated = True except Exception as exc: self.validated = False file.close() if (not allow_invalid): # An invalid descriptor is allowed on submission only if the 'allow_invalid' argument is set return False # Add error message to desc self.db_desc.execution_status = EXECUTION_STATUS_ERROR self.db_desc.error_message = str(exc).replace('\n', '<br>') self.db_desc.last_updated = datetime.date.today() self.db_desc.save() return True self.db_desc.execution_status = EXECUTION_STATUS_UNCHECKED desc_JSON = json.loads(file.read()) self.db_desc.tool_name = desc_JSON["name"] self.db_desc.version = desc_JSON["tool-version"] self.db_desc.last_updated = datetime.date.today() self.db_desc.save() # Generate all the test profiles. desc_entry = DescriptorEntry(self.db_desc) desc_entry.generate_tests() return True
def _get_valid_descriptor_count(self, raw_descriptors): count = 0 for raw_descriptor in raw_descriptors: descriptor_file = create_temporary_file(raw_descriptor) try: bosh.validate(descriptor_file.name) count += 1 descriptor_file.close() except: descriptor_file.close() return count
def function(descriptor): ''' Returns a function to invoke bosh.execute on a descriptor. args: descriptor: Zenodo id, file name, or JSON string representing a descriptor. name: name of the function to create. Defaults to the tool name in the descriptor. ''' validate(descriptor) descriptor_json = loadJson(descriptor) def f(*args, **kwargs): # Set default mode to 'launch' if len(args) > 0: mode = args[0] else: mode = 'launch' if mode not in ['launch', 'simulate']: mode = 'launch' else: args = args[1:] # Call bosh execute if mode == 'launch': return execute(mode, descriptor, json.dumps(kwargs), *args) if len(kwargs) > 0: return execute(mode, descriptor, '-i', json.dumps(kwargs), *args) return execute(mode, descriptor, *args) f.__name__ = str(descriptor_json['name']) # Documentation doc = [] doc.append(r'''Runs {0} through its Boutiques interface. *args: - mode: 'launch' or 'simulate'. Defaults to 'launch'. - other arguments: will be passed to bosh execute. Examples: '-s', '-x'. See help(bosh.execute) for a complete list. *kwargs: {1} arguments as defined in the Boutiques descriptor, referenced from input ids. Example: {2}='some_value'. See complete list in descriptor help below. '''.format(f.__name__, f.__name__, descriptor_json['inputs'][0]['id'])) doc.append(pprint(descriptor)) f.__doc__ = ''.join(doc) return f
def validate(self): # This is here in case we have a URL container if (self.container.is_medium_erroneous()): self.validated = False self.message = self.container.get_error() return False else: desc_content = self.container.get_data() # Call bosh validate on the data file = create_temporary_file(desc_content) #backedup = sys.tracebacklimit #sys.tracebacklimit = None try: bosh.validate(file.name) self.validated = True except Exception as exc: self.validated = False error = str(exc).replace('\n', '<br>') #sys.tracebacklimit = backedup if (self.validated == True): desc = json.loads(file.read()) if (desc.get("tests") == None): n_tests = 0 else: n_tests = len(desc["tests"]) self.message = "Associated descriptor is valid.<br><b>" + str( n_tests) + "</b> tests found defined inside descriptor." else: self.message = "<b> Validation failure.<br>Boutiques returned the following error(s):</b><br>" + error file.close() return self.validated
def test_demo_descriptor_valid(self): self.assertFalse(boutiques.validate(self.get_json_descriptor(),"-b"))
def test_pythoninterface_validate(self): fil = op.join(op.split(bfile)[0], 'schema/examples/good.json') self.assertIsNone(boutiques.validate(fil))