def validate_jar(filename, include_xforms=True): '''Validates a jar for use with CommCare HQ. It performs the following steps and checks: 1. Ensures the jar is valid and contains at least one xform in the root. == If include_xforms is True == 2. Runs every found xform through the schema conversion logic and ensures that there are no problems. 3. Runs every generated schema through validation that checks for the existence of a <meta> block, and that there are no missing/ duplicate/extra tags in it.''' temp_directory = tempfile.mkdtemp() try: xforms = extract_xforms(filename, temp_directory) if not xforms: raise BuildError("Jar file must have at least 1 xform") # when things go wrong we'll store them here. # we'll throw a big fat exception at the end, that # will wrap all the other ones. errors = [] if include_xforms: # now run through each of the forms and try to convert to # a schema, as well as adding all kinds of validation checks for xform in xforms: try: xformvalidator.validate(xform) except Exception, e: errors.append(e) if errors: raise BuildError("Problem validating jar!", errors)
def validate_xforms(self): '''Validates this build's xforms.''' errors = [] for form in self.xforms.all(): try: xformvalidator.validate(form.file_location) except Exception, e: errors.append(e)
def check_and_release_xforms(self): '''Checks this build's xforms against the xformmanager and releases them, if they pass compatibility tests''' errors = [] to_skip = [] to_register = [] for form in self.xforms.all(): try: formdef = xformvalidator.validate(form.file_location) modelform = FormDefModel.get_model(formdef.target_namespace, self.project.domain, formdef.version) if modelform: # if the model form exists we must ensure it is compatible # with the version we are trying to release existing_formdef = modelform.to_formdef() differences = existing_formdef.get_differences(formdef) if differences.is_empty(): # this is all good to_skip.append(form) else: raise BuildError("""Schema %s is not compatible with %s. Because of the following differences: %s You must update your version number!""" % (existing_formdef, formdef, differences)) else: # this must be registered to_register.append(form) except Exception, e: errors.append(e)