示例#1
0
def _main():
    """Main entry point.

    """
    doc = pyesdoc.read(options.file, options.encoding)

    print pyesdoc.encode(doc, pyesdoc.ENCODING_JSON)
示例#2
0
def init(institution_id):
    """Initialises seedings from institutional seeding config files.

    :param str institution_id: ID of institution being processed.

    """
    # Reset.
    global DOCUMENTS
    DOCUMENTS = list()

    # Set root folder path.
    fpath = os.getenv('CMIP6_HOME')
    fpath = os.path.join(fpath, 'repos')
    fpath = os.path.join(fpath, 'institutional')
    fpath = os.path.join(fpath, institution_id)
    fpath = os.path.join(fpath, 'cmip5')
    fpath = os.path.join(fpath, 'models')
    if not os.path.exists(fpath):
        return

    # Cache each model's cim document.
    for model_id in os.listdir(fpath):
        path = os.path.join(fpath, model_id)
        path = os.path.join(path, 'cim')
        if not os.path.exists(path):
            continue

        # Cache extended documents.
        for fname in os.listdir(path):
            doc_path = os.path.join(path, fname)
            DOCUMENTS.append(pyesdoc.extend(pyesdoc.read(doc_path)))

    return len(DOCUMENTS) > 0
示例#3
0
    def get_document(self, extend=True):
        """Returns deserialized document.

        :returns: Deserialized archived document.
        :rtype: object

        """
        # Read from file system.
        try:
            document = pyesdoc.read(self.path)
        except Exception as err:
            raise exceptions.LoadingException(err)

        # Parse - performs project/source specific processing.
        try:
            pyesdoc.archive.parse(document, self.encoding, self.project, self.source)
        except Exception as err:
            raise exceptions.ParsingException(err)

        # Extend - performs generic processing.
        if extend:
            try:
                pyesdoc.extend(document)
            except exceptions.ExtendingException as err:
                raise err
            except Exception as err:
                raise exceptions.ExtendingException(err)

        return document
示例#4
0
def _main():
    """Main entry point.

    """
    doc = pyesdoc.read(options.file, options.encoding)

    print pyesdoc.encode(doc, 'json')
示例#5
0
def _main():
    """Main entry point.

    """
    doc = pyesdoc.read(options.file, options.encoding)

    print pyesdoc.encode(doc, pyesdoc.ENCODING_JSON)
示例#6
0
def init(institution_id):
    """Initialises seedings from institutional seeding config files.

    :param str institution_id: ID of institution being processed.

    """
    # Reset.
    global DOCUMENTS
    DOCUMENTS = list()

    # Set root folder path.
    fpath = os.getenv('ESDOC_HOME')
    fpath = os.path.join(fpath, 'repos')
    fpath = os.path.join(fpath, 'institutional')
    fpath = os.path.join(fpath, institution_id)
    fpath = os.path.join(fpath, 'cmip5')
    fpath = os.path.join(fpath, 'models')
    if not os.path.exists(fpath):
        return

    # Cache each model's cim document.
    for model_id in os.listdir(fpath):
        path = os.path.join(fpath, model_id)
        path = os.path.join(path, 'cim')
        if not os.path.exists(path):
            continue

        # Cache extended documents.
        for fname in os.listdir(path):
            doc_path = os.path.join(path, fname)
            DOCUMENTS.append(pyesdoc.extend(pyesdoc.read(doc_path)))

    return len(DOCUMENTS) > 0
示例#7
0
    def get_document(self, extend=True):
        """Returns deserialized document.

        :returns: Deserialized archived document.
        :rtype: object

        """
        # Read from file system.
        try:
            document = pyesdoc.read(self.path)
        except Exception as err:
            raise exceptions.LoadingException(err)

        # Parse - performs project/source specific processing.
        try:
            pyesdoc.archive.parse(document, self.encoding, self.project,
                                  self.source)
        except Exception as err:
            raise exceptions.ParsingException(err)

        # Extend - performs generic processing.
        if extend:
            try:
                pyesdoc.extend(document)
            except exceptions.ExtendingException as err:
                raise err
            except Exception as err:
                raise exceptions.ExtendingException(err)

        return document
示例#8
0
def _main():
    """Main entry point.

    """
    # Open document & validate.
    doc = pyesdoc.read(options.file)
    report = pyesdoc.validate(doc)

    # Inform user of validation result.
    if report:
        if options.outfile:
            _emit_to_file_system(report)
        else:
            _emit_to_stdout(report)
    else:
        pyesdoc.rt.log("Documemt is valid.")
示例#9
0
def _main():
    """Main entry point.

    """
    # Open document & validate.
    doc = pyesdoc.read(options.file)
    report = pyesdoc.validate(doc)

    # Inform user of validation result.
    if report:
        if options.outfile:
            _emit_to_file_system(report)
        else:
            _emit_to_stdout(report)
    else:
        pyesdoc.rt.log("Documemt is valid.")
def _yield_documents(input_dir, doc_type):
    """Yields set of document for further processing.

    """
    for fpath in glob.iglob("{}/{}*.*".format(input_dir, doc_type)):
        yield pyesdoc.read(fpath)
示例#11
0
def _yield_documents(input_dir, type_key):
    """Yields set of document for further processing.

    """
    for fpath in glob.iglob("{}/{}*.*".format(input_dir, type_key)):
        yield pyesdoc.read(fpath)
示例#12
0
def _main():
    """Main entry point."""
    for fp in _FILEPATHS:
        print pyesdoc.read(fp, pyesdoc.METAFOR_CIM_XML_ENCODING)