Пример #1
0
def get_hed_schema_from_pull_down(request):
    """Creates a HedSchema object from a section of form that uses a pull-down box and hed_cache
    Parameters
    ----------
    request: Request object
        A Request object containing user data from a form.

    Returns
    -------
    tuple: str
        A HedSchema object
    """

    if base_constants.SCHEMA_VERSION not in request.form:
        raise HedFileError("NoSchemaError",
                           "Must provide a valid schema or schema version", "")
    elif request.form[base_constants.
                      SCHEMA_VERSION] != base_constants.OTHER_VERSION_OPTION:
        hed_file_path = hedschema.get_path_from_hed_version(
            request.form[base_constants.SCHEMA_VERSION])
        hed_schema = hedschema.load_schema(hed_file_path)
    elif request.form[base_constants.SCHEMA_VERSION] == \
            base_constants.OTHER_VERSION_OPTION and base_constants.SCHEMA_PATH in request.files:
        f = request.files[base_constants.SCHEMA_PATH]
        hed_schema = hedschema.from_string(
            f.read(file_constants.BYTE_LIMIT).decode('ascii'),
            file_type=secure_filename(f.filename))
    else:
        raise HedFileError(
            "NoSchemaFile",
            "Must provide a valid schema for upload if other chosen", "")
    return hed_schema
Пример #2
0
def get_schema(schema_path=None,
               schema_url=None,
               schema_string=None,
               file_type=".xml"):
    """Return a schema object.

    Parameters
    ----------
    schema_path: str
        A string representing a path to a schema
    schema_url: str
        A string representing a URL of a schema
    schema_string: str
        A string representing a URL of a schema
    file_type: str
        A string representing the file extension including the .

    Returns
    -------
    HedSchema
        The HedSchema object that as loaded.
    """

    if schema_path:
        hed_schema = hedschema.load_schema(schema_path)
    elif schema_url:
        hed_schema = hedschema.load_schema(schema_url)
    elif schema_string:
        hed_schema = hedschema.from_string(schema_string, file_type=file_type)
    else:
        raise HedFileError("HedSchemaNotFound",
                           "A HED schema could not be located", "")

    return hed_schema
Пример #3
0
    def test_schema_as_string_wiki(self):
        with open(self.wiki_file) as file:
            hed_schema_as_string = "".join([line for line in file])

        string_schema = schema.from_string(hed_schema_as_string,
                                           file_type=".mediawiki")
        self.assertEqual(string_schema, self.hed_schema_wiki)
Пример #4
0
    def test_schema_as_string_xml(self):
        with open(self.xml_file) as file:
            hed_schema_as_string = "".join([line for line in file])

            string_schema = schema.from_string(hed_schema_as_string)

            self.assertEqual(string_schema, self.hed_schema_xml)
Пример #5
0
def schema_version_results():
    """Finds the information about the HED version of a file and returns as JSON.

    Parameters
    ----------

    Returns
    -------
    string
        A serialized JSON string containing information related to the spreadsheet columns.

    """

    try:
        hed_info = {}
        if base_constants.SCHEMA_PATH in request.files:
            f = request.files[base_constants.SCHEMA_PATH]
            hed_schema = hedschema.from_string(
                f.stream.read(file_constants.BYTE_LIMIT).decode('ascii'),
                file_type=secure_filename(f.filename))
            hed_info[base_constants.
                     SCHEMA_VERSION] = hed_schema.header_attributes['version']
        return json.dumps(hed_info)
    except Exception as ex:
        return handle_error(ex)
Пример #6
0
def get_input_schema(parameters):

    if base_constants.SCHEMA_STRING in parameters and parameters[
            base_constants.SCHEMA_STRING]:
        the_schema = hedschema.from_string(
            parameters[base_constants.SCHEMA_STRING])
    elif base_constants.SCHEMA_URL in parameters and parameters[
            base_constants.SCHEMA_URL]:
        schema_url = parameters[base_constants.SCHEMA_URL]
        the_schema = hedschema.load_schema(schema_url)
    elif base_constants.SCHEMA_VERSION in parameters and parameters[
            base_constants.SCHEMA_VERSION]:
        hed_file_path = hedschema.get_path_from_hed_version(
            parameters[base_constants.SCHEMA_VERSION])
        the_schema = hedschema.load_schema(hed_file_path)
    else:
        the_schema = []
    return the_schema