示例#1
0
    def from_url(cls, server_uri, stanza):

        parts = urllib.parse.urlparse(server_uri)
        scheme = parts.scheme
        host = parts.hostname
        port = parts.port

        service = Service(
            scheme=scheme,
            host=host,
            port=port,
            username=parts.username,
            password=parts.password,
        )
        service.login()

        server_scheme = scheme
        server_host = host
        server_port = port
        token = service.token
        log_dir = environ.get_log_folder()

        kind, name = cls._split_stanza(stanza)
        inputs = list()
        for item in service.inputs:
            if item.kind != kind:
                continue
            if item.name != name:
                continue
            stanza = Stanza(kind, name, item.content)
            inputs.append(stanza)

        checkpoint_dir = environ.get_checkpoint_folder(kind)
        return cls(server_scheme, server_host, server_port, token,
                   checkpoint_dir, log_dir, inputs)
示例#2
0
    def from_stream(cls, stream):
        definition = InputDefinition.parse(stream)

        metadata = definition.metadata
        parts = urllib.parse.urlparse(metadata['server_uri'])
        scheme = parts.scheme
        host = parts.hostname
        port = parts.port
        token = metadata['session_key']

        server_scheme = scheme
        server_host = host
        server_port = port
        token = token
        log_dir = environ.get_log_folder()

        inputs = list()
        for name, params in list(definition.inputs.items()):
            kind, name = cls._split_stanza(name)
            stanza = Stanza(kind, name, params)
            inputs.append(stanza)

        checkpoint_dir = metadata['checkpoint_dir']
        return cls(server_scheme, server_host, server_port, token,
                   checkpoint_dir, log_dir, inputs)
示例#3
0
 def __call__(self):
     """
     Returns the default handlers.
     :return:
     """
     filename = self._assemble_file_name()
     log_dir = environ.get_log_folder()
     filepath = os.path.join(log_dir, filename)
     # Make the file handle not inheritable on Windows
     handler = RotatingFileHandler(
         filepath, maxBytes=1024 * 1024 * 25, backupCount=5, delay=True
     )
     if os.name == 'nt':
         handler.mode = 'aN'
     return handler