# -*- coding: utf-8 -*-
#########################################################################
#
# Copyright 2018, GeoSolutions Sas.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
#
#########################################################################


class BaseOutput(object):

    @classmethod
    def _get_output(cls, type, config):
        _sub_classes = [clazz for clazz in cls.__subclasses__()]
        for _clz in _sub_classes:
            if _clz.type() == type:
                return _clz(config)  # initialize here
        return None

    @classmethod
    def type(cls):
        raise NotImplemented

    def stream(self, buffer, record_id=None):
        raise NotImplemented


class FileOutput(BaseOutput):

    def __init__(self, config):
        self._dest_file = config.get(self.__class__.__name__, 'dest_file')

    @classmethod
    def type(cls):
        return 'FILE'

    def stream(self, buffer, record_id=None):
        _dest_file = self._dest_file
        if record_id:
            _dest_file = _dest_file.format(record_id)
        with open(_dest_file, "w") as text_file:
            text_file.write(buffer)

    def __str__(self):
        return "File Output Stream"


class CSWOutput(BaseOutput):

    def __init__(self, config):
        self._csw_url = config.get(self.__class__.__name__, 'csw_url')

        self._csw_usr = config.get(self.__class__.__name__, 'csw_usr') if \
            config.has_option(self.__class__.__name__, 'csw_usr') else None

        self._csw_pwd = config.get(self.__class__.__name__, 'csw_pwd') if \
            config.has_option(self.__class__.__name__, 'csw_pwd') else None

        from owslib.csw import CatalogueServiceWeb
        self._csw = CatalogueServiceWeb(url=self._csw_url, skip_caps=True)

    @classmethod
    def type(cls):
        return 'CSW'

    def stream(self, buffer, record_id=None):
        self._csw.transaction(ttype='insert', typename='gmd:MD_Metadata', record=buffer)

    def __str__(self):
        return "CSW Output Stream"

eee2d59f6876454f7da746ea7213714a40c8d17d
<mask token>


class FileOutput(BaseOutput):
    <mask token>
    <mask token>

    def stream(self, buffer, record_id=None):
        _dest_file = self._dest_file
        if record_id:
            _dest_file = _dest_file.format(record_id)
        with open(_dest_file, 'w') as text_file:
            text_file.write(buffer)
    <mask token>


class CSWOutput(BaseOutput):

    def __init__(self, config):
        self._csw_url = config.get(self.__class__.__name__, 'csw_url')
        self._csw_usr = config.get(self.__class__.__name__, 'csw_usr'
            ) if config.has_option(self.__class__.__name__, 'csw_usr'
            ) else None
        self._csw_pwd = config.get(self.__class__.__name__, 'csw_pwd'
            ) if config.has_option(self.__class__.__name__, 'csw_pwd'
            ) else None
        from owslib.csw import CatalogueServiceWeb
        self._csw = CatalogueServiceWeb(url=self._csw_url, skip_caps=True)

    @classmethod
    def type(cls):
        return 'CSW'

    def stream(self, buffer, record_id=None):
        self._csw.transaction(ttype='insert', typename='gmd:MD_Metadata',
            record=buffer)

    def __str__(self):
        return 'CSW Output Stream'

<mask token>


class FileOutput(BaseOutput):
    <mask token>

    @classmethod
    def type(cls):
        return 'FILE'

    def stream(self, buffer, record_id=None):
        _dest_file = self._dest_file
        if record_id:
            _dest_file = _dest_file.format(record_id)
        with open(_dest_file, 'w') as text_file:
            text_file.write(buffer)

    def __str__(self):
        return 'File Output Stream'


class CSWOutput(BaseOutput):

    def __init__(self, config):
        self._csw_url = config.get(self.__class__.__name__, 'csw_url')
        self._csw_usr = config.get(self.__class__.__name__, 'csw_usr'
            ) if config.has_option(self.__class__.__name__, 'csw_usr'
            ) else None
        self._csw_pwd = config.get(self.__class__.__name__, 'csw_pwd'
            ) if config.has_option(self.__class__.__name__, 'csw_pwd'
            ) else None
        from owslib.csw import CatalogueServiceWeb
        self._csw = CatalogueServiceWeb(url=self._csw_url, skip_caps=True)

    @classmethod
    def type(cls):
        return 'CSW'

    def stream(self, buffer, record_id=None):
        self._csw.transaction(ttype='insert', typename='gmd:MD_Metadata',
            record=buffer)

    def __str__(self):
        return 'CSW Output Stream'

<mask token>


class FileOutput(BaseOutput):

    def __init__(self, config):
        self._dest_file = config.get(self.__class__.__name__, 'dest_file')

    @classmethod
    def type(cls):
        return 'FILE'

    def stream(self, buffer, record_id=None):
        _dest_file = self._dest_file
        if record_id:
            _dest_file = _dest_file.format(record_id)
        with open(_dest_file, 'w') as text_file:
            text_file.write(buffer)

    def __str__(self):
        return 'File Output Stream'


class CSWOutput(BaseOutput):

    def __init__(self, config):
        self._csw_url = config.get(self.__class__.__name__, 'csw_url')
        self._csw_usr = config.get(self.__class__.__name__, 'csw_usr'
            ) if config.has_option(self.__class__.__name__, 'csw_usr'
            ) else None
        self._csw_pwd = config.get(self.__class__.__name__, 'csw_pwd'
            ) if config.has_option(self.__class__.__name__, 'csw_pwd'
            ) else None
        from owslib.csw import CatalogueServiceWeb
        self._csw = CatalogueServiceWeb(url=self._csw_url, skip_caps=True)

    @classmethod
    def type(cls):
        return 'CSW'

    def stream(self, buffer, record_id=None):
        self._csw.transaction(ttype='insert', typename='gmd:MD_Metadata',
            record=buffer)

    def __str__(self):
        return 'CSW Output Stream'

class BaseOutput(object):
    <mask token>
    <mask token>

    def stream(self, buffer, record_id=None):
        raise NotImplemented


class FileOutput(BaseOutput):

    def __init__(self, config):
        self._dest_file = config.get(self.__class__.__name__, 'dest_file')

    @classmethod
    def type(cls):
        return 'FILE'

    def stream(self, buffer, record_id=None):
        _dest_file = self._dest_file
        if record_id:
            _dest_file = _dest_file.format(record_id)
        with open(_dest_file, 'w') as text_file:
            text_file.write(buffer)

    def __str__(self):
        return 'File Output Stream'


class CSWOutput(BaseOutput):

    def __init__(self, config):
        self._csw_url = config.get(self.__class__.__name__, 'csw_url')
        self._csw_usr = config.get(self.__class__.__name__, 'csw_usr'
            ) if config.has_option(self.__class__.__name__, 'csw_usr'
            ) else None
        self._csw_pwd = config.get(self.__class__.__name__, 'csw_pwd'
            ) if config.has_option(self.__class__.__name__, 'csw_pwd'
            ) else None
        from owslib.csw import CatalogueServiceWeb
        self._csw = CatalogueServiceWeb(url=self._csw_url, skip_caps=True)

    @classmethod
    def type(cls):
        return 'CSW'

    def stream(self, buffer, record_id=None):
        self._csw.transaction(ttype='insert', typename='gmd:MD_Metadata',
            record=buffer)

    def __str__(self):
        return 'CSW Output Stream'

# -*- coding: utf-8 -*-
#########################################################################
#
# Copyright 2018, GeoSolutions Sas.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
#
#########################################################################


class BaseOutput(object):

    @classmethod
    def _get_output(cls, type, config):
        _sub_classes = [clazz for clazz in cls.__subclasses__()]
        for _clz in _sub_classes:
            if _clz.type() == type:
                return _clz(config)  # initialize here
        return None

    @classmethod
    def type(cls):
        raise NotImplemented

    def stream(self, buffer, record_id=None):
        raise NotImplemented


class FileOutput(BaseOutput):

    def __init__(self, config):
        self._dest_file = config.get(self.__class__.__name__, 'dest_file')

    @classmethod
    def type(cls):
        return 'FILE'

    def stream(self, buffer, record_id=None):
        _dest_file = self._dest_file
        if record_id:
            _dest_file = _dest_file.format(record_id)
        with open(_dest_file, "w") as text_file:
            text_file.write(buffer)

    def __str__(self):
        return "File Output Stream"


class CSWOutput(BaseOutput):

    def __init__(self, config):
        self._csw_url = config.get(self.__class__.__name__, 'csw_url')

        self._csw_usr = config.get(self.__class__.__name__, 'csw_usr') if \
            config.has_option(self.__class__.__name__, 'csw_usr') else None

        self._csw_pwd = config.get(self.__class__.__name__, 'csw_pwd') if \
            config.has_option(self.__class__.__name__, 'csw_pwd') else None

        from owslib.csw import CatalogueServiceWeb
        self._csw = CatalogueServiceWeb(url=self._csw_url, skip_caps=True)

    @classmethod
    def type(cls):
        return 'CSW'

    def stream(self, buffer, record_id=None):
        self._csw.transaction(ttype='insert', typename='gmd:MD_Metadata', record=buffer)

    def __str__(self):
        return "CSW Output Stream"
