1#!/usr/bin/env python
2#############################################################################
3# Copyright (c) 2015-2018 Balabit
4#
5# This program is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 2 as published
7# by the Free Software Foundation, or (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17#
18# As an additional exemption you are allowed to compile & link against the
19# OpenSSL libraries as published by the OpenSSL project. See the file
20# COPYING for details.
21#
22#############################################################################
23from pathlib2 import Path
24
25import src.testcase_parameters.testcase_parameters as tc_parameters
26from src.driver_io.file.file_io import FileIO
27from src.syslog_ng_config.statements.destinations.destination_driver import DestinationDriver
28
29
30class ExampleDestination(DestinationDriver):
31    def __init__(self, filename, **options):
32        self.driver_name = "example-destination"
33        self.path = Path(tc_parameters.WORKING_DIR, filename)
34        self.io = FileIO(self.path)
35        super(ExampleDestination, self).__init__(None, dict({"filename": self.path.resolve()}, **options))
36
37    def get_path(self):
38        return self.path
39
40    def read_log(self):
41        return self.read_logs(1)[0]
42
43    def read_logs(self, counter):
44        return self.io.read_number_of_lines(counter)
45
46    def read_until_logs(self, logs):
47        return self.io.read_until_lines(logs)
48