Skip to content

# File sorter

The tool to check the availability or syntax of domain, IP or URL.

::

    ██████╗ ██╗   ██╗███████╗██╗   ██╗███╗   ██╗ ██████╗███████╗██████╗ ██╗     ███████╗
    ██╔══██╗╚██╗ ██╔╝██╔════╝██║   ██║████╗  ██║██╔════╝██╔════╝██╔══██╗██║     ██╔════╝
    ██████╔╝ ╚████╔╝ █████╗  ██║   ██║██╔██╗ ██║██║     █████╗  ██████╔╝██║     █████╗
    ██╔═══╝   ╚██╔╝  ██╔══╝  ██║   ██║██║╚██╗██║██║     ██╔══╝  ██╔══██╗██║     ██╔══╝
    ██║        ██║   ██║     ╚██████╔╝██║ ╚████║╚██████╗███████╗██████╔╝███████╗███████╗
    ╚═╝        ╚═╝   ╚═╝      ╚═════╝ ╚═╝  ╚═══╝ ╚═════╝╚══════╝╚═════╝ ╚══════╝╚══════╝

Provides our file sorter worker. This is the description of a file sorter worker.

Author: Nissar Chababy, @funilrys, contactTATAfunilrysTODTODcom

Special thanks: https://pyfunceble.github.io/#/special-thanks

Contributors: https://pyfunceble.github.io/#/contributors

Project link: https://github.com/funilrys/PyFunceble

Project documentation: https://docs.pyfunceble.com

Project homepage: https://pyfunceble.github.io/

License: ::

    Copyright 2017, 2018, 2019, 2020, 2022, 2023, 2024, 2025 Nissar Chababy

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        https://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

## `FileSorterWorker`

Bases: `FileSorterWorkerBase`

Provides our file sorter worker. The objective of this worker is to provides a single worker (or process if you prefer) which will be used to handle the sorting of the content of a given file.

Expected (input) message:

::

    {
        "file": str,
        "remove_duplicates": bool,
        "write_header": bool
    }

Expected (output) message:

::

    None

Source code in `PyFunceble/cli/processes/workers/file_sorter.py`

     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113

    class FileSorterWorker(FileSorterWorkerBase):
        """
        Provides our file sorter worker. The objective of this worker is to provides
        a single worker (or process if you prefer) which will be used to handle
        the sorting of the content of a given file.

        Expected (input) message:

        ::

            {
                "file": str,
                "remove_duplicates": bool,
                "write_header": bool
            }

        Expected (output) message:

        ::

            None
        """

        def target(self, consumed: Any) -> Optional[Tuple[Any, ...]]:
            """
            The producer of the worker.

            :param consumed:
                The consumed data to work with.
            """

            if (
                not isinstance(consumed, dict)
                and "file" not in consumed
                or not consumed["file"]
            ):
                PyFunceble.facility.Logger.info(
                    "Ignoring consumed data because no data to work with."
                )

                return None

            # Just for human brain :-)
            file = consumed["file"]

            remove_duplicates = consumed.get("remove_duplicates", True)
            write_header = consumed.get("write_header", True)

            self.process_file_sorting(
                file, remove_duplicates=remove_duplicates, write_header=write_header
            )

            return None

### `target(consumed)`

The producer of the worker.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`consumed` | `Any` | The consumed data to work with. | required

Source code in `PyFunceble/cli/processes/workers/file_sorter.py`

     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113

    def target(self, consumed: Any) -> Optional[Tuple[Any, ...]]:
        """
        The producer of the worker.

        :param consumed:
            The consumed data to work with.
        """

        if (
            not isinstance(consumed, dict)
            and "file" not in consumed
            or not consumed["file"]
        ):
            PyFunceble.facility.Logger.info(
                "Ignoring consumed data because no data to work with."
            )

            return None

        # Just for human brain :-)
        file = consumed["file"]

        remove_duplicates = consumed.get("remove_duplicates", True)
        write_header = consumed.get("write_header", True)

        self.process_file_sorting(
            file, remove_duplicates=remove_duplicates, write_header=write_header
        )

        return None