PyFunceble/generate.py
def info_files(self):  # pylint: disable=inconsistent-return-statements
        """
        Generate the hosts file, the plain list and the splitted lists.
        """

        if self._do_not_produce_file():
            # We do not have to produce file.

            # We return false.
            return False

        if (
            "file_to_test" in PyFunceble.INTERN
            and PyFunceble.INTERN["file_to_test"]
            and (
                PyFunceble.CONFIGURATION["generate_hosts"]
                or PyFunceble.CONFIGURATION["plain_list_domain"]
                or PyFunceble.CONFIGURATION["generate_json"]
            )
        ):
            # * We are not testing as an imported module.
            # and
            # * The hosts file generation is activated.
            # or
            # * The plain list generation is activated.

            # We initiate a variable which whill save the splited testination.
            splited_destination = ""

            # We initiate the list of all analytic related statuses.
            http_list = []
            http_list.extend(PyFunceble.STATUS["list"]["potentially_up"])
            http_list.extend(PyFunceble.STATUS["list"]["potentially_down"])
            http_list.extend(PyFunceble.STATUS["list"]["http_active"])
            http_list.extend(PyFunceble.STATUS["list"]["suspicious"])

            # We partially initiate the path to the hosts file.
            output_hosts = (
                self.output_parent_dir
                + PyFunceble.OUTPUTS["hosts"]["directory"]
                + "%s"
                + directory_separator
                + PyFunceble.OUTPUTS["hosts"]["filename"]
            )

            # We partially initiate the path to the plain list file.
            output_domains = (
                self.output_parent_dir
                + PyFunceble.OUTPUTS["domains"]["directory"]
                + "%s"
                + directory_separator
                + PyFunceble.OUTPUTS["domains"]["filename"]
            )

            # We partially intiate the path to the json list file.
            output_json = (
                self.output_parent_dir
                + PyFunceble.OUTPUTS["json"]["directory"]
                + "%s"
                + directory_separator
                + PyFunceble.OUTPUTS["json"]["filename"]
            )

            if self.domain_status.lower() in PyFunceble.STATUS["list"]["up"]:
                # The status is in the list of up list.

                # We complete the path to the hosts file.
                hosts_destination = output_hosts % PyFunceble.STATUS["official"]["up"]

                # We complete the path to the plain list file.
                plain_destination = output_domains % PyFunceble.STATUS["official"]["up"]

                # We complete the path to the json list file.
                json_destination = output_json % PyFunceble.STATUS["official"]["up"]
            elif self.domain_status.lower() in PyFunceble.STATUS["list"]["valid"]:
                # The status is in the list of valid list.

                # We complete the path to the hosts file.
                hosts_destination = (
                    output_hosts % PyFunceble.STATUS["official"]["valid"]
                )

                # We complete the path to the plain list file.
                plain_destination = (
                    output_domains % PyFunceble.STATUS["official"]["valid"]
                )

                # We complete the path to the json list file.
                json_destination = output_json % PyFunceble.STATUS["official"]["valid"]
            elif self.domain_status.lower() in PyFunceble.STATUS["list"]["down"]:
                # The status is in the list of down list.

                # We complete the path to the hosts file.
                hosts_destination = output_hosts % PyFunceble.STATUS["official"]["down"]

                # We complete the path to the plain list file.
                plain_destination = (
                    output_domains % PyFunceble.STATUS["official"]["down"]
                )

                # We complete the path to the json list file.
                json_destination = output_json % PyFunceble.STATUS["official"]["down"]
            elif self.domain_status.lower() in PyFunceble.STATUS["list"]["invalid"]:
                # The status is in the list of invalid list.

                # We complete the path to the hosts file.
                hosts_destination = (
                    output_hosts % PyFunceble.STATUS["official"]["invalid"]
                )

                # We complete the path to the plain list file.
                plain_destination = (
                    output_domains % PyFunceble.STATUS["official"]["invalid"]
                )

                # We complete the path to the json list file.
                json_destination = (
                    output_json % PyFunceble.STATUS["official"]["invalid"]
                )
            elif self.domain_status.lower() in http_list:
                # The status is in the list of analytic status.

                # We construct the path to the analytic directory.
                output_dir = self._analytic_host_file_directory()

                if not output_dir.endswith(directory_separator):
                    # The output directory does not ends with the directory separator.

                    # We append the directory separator at the end of the output directory.
                    output_dir += directory_separator

                # We initiate the hosts file path.
                hosts_destination = output_dir + PyFunceble.OUTPUTS["hosts"]["filename"]

                # We initiate the plain list file path.
                plain_destination = (
                    output_dir + PyFunceble.OUTPUTS["domains"]["filename"]
                )

                # We complete the path to the json list file.
                json_destination = output_dir + PyFunceble.OUTPUTS["json"]["filename"]

                # We initiate the path to the http code file.
                # Note: We generate the http code file so that
                # we can have each domain in a file which is the
                # extracted http code.
                splited_destination = output_dir + str(PyFunceble.INTERN["http_code"])

            if PyFunceble.CONFIGURATION["generate_hosts"]:
                # The hosts file generation is activated.

                # We generate/append the currently tested element in its
                # final location. (hosts file format)
                # We print on screen and on file.
                Prints(
                    [PyFunceble.CONFIGURATION["custom_ip"], self.tested],
                    "FullHosts",
                    hosts_destination,
                ).data()

            if PyFunceble.CONFIGURATION["plain_list_domain"]:
                # The plain list generation is activated.

                # We generate/append the currently tested element in its
                # final location. (the plain list format)
                # We print on file.
                Prints([self.tested], "PlainDomain", plain_destination).data()

            if PyFunceble.CONFIGURATION["split"] and splited_destination:
                # The splited list generation is activated.

                # We generate/append the currently tested element in its
                # final location. (the split list format)
                # We print on file.
                Prints([self.tested], "PlainDomain", splited_destination).data()

            if PyFunceble.CONFIGURATION["generate_json"]:
                # The jsaon list generation is activated.

                # We generate/append the currently tested element in its
                # final location. (the json format)
                # We print on file.
                Prints([self.tested], "JSON", json_destination).data()
def info_files(self):  # pylint: disable=inconsistent-return-statements
        """
        Generate the hosts file, the plain list and the splitted lists.
        """

        if self._do_not_produce_file():
            # We do not have to produce file.

            # We return false.
            return False

        if (
            "file_to_test" in PyFunceble.INTERN
            and PyFunceble.INTERN["file_to_test"]
            and (
                PyFunceble.CONFIGURATION["generate_hosts"]
                or PyFunceble.CONFIGURATION["plain_list_domain"]
                or PyFunceble.CONFIGURATION["generate_json"]
            )
        ):
            # * We are not testing as an imported module.
            # and
            # * The hosts file generation is activated.
            # or
            # * The plain list generation is activated.

            # We initiate a variable which whill save the splited testination.
            splited_destination = ""

            # We initiate the list of all analytic related statuses.
            http_list = []
            http_list.extend(PyFunceble.STATUS["list"]["potentially_up"])
            http_list.extend(PyFunceble.STATUS["list"]["potentially_down"])
            http_list.extend(PyFunceble.STATUS["list"]["http_active"])
            http_list.extend(PyFunceble.STATUS["list"]["suspicious"])

            # We partially initiate the path to the hosts file.
            output_hosts = (
                self.output_parent_dir
                + PyFunceble.OUTPUTS["hosts"]["directory"]
                + "%s"
                + directory_separator
                + PyFunceble.OUTPUTS["hosts"]["filename"]
            )

            # We partially initiate the path to the plain list file.
            output_domains = (
                self.output_parent_dir
                + PyFunceble.OUTPUTS["domains"]["directory"]
                + "%s"
                + directory_separator
                + PyFunceble.OUTPUTS["domains"]["filename"]
            )

            # We partially intiate the path to the json list file.
            output_json = (
                self.output_parent_dir
                + PyFunceble.OUTPUTS["json"]["directory"]
                + "%s"
                + directory_separator
                + PyFunceble.OUTPUTS["json"]["filename"]
            )

            if self.domain_status.lower() in PyFunceble.STATUS["list"]["up"]:
                # The status is in the list of up list.

                # We complete the path to the hosts file.
                hosts_destination = output_hosts % PyFunceble.STATUS["official"]["up"]

                # We complete the path to the plain list file.
                plain_destination = output_domains % PyFunceble.STATUS["official"]["up"]

                # We complete the path to the json list file.
                json_destination = output_json % PyFunceble.STATUS["official"]["up"]
            elif self.domain_status.lower() in PyFunceble.STATUS["list"]["valid"]:
                # The status is in the list of valid list.

                # We complete the path to the hosts file.
                hosts_destination = (
                    output_hosts % PyFunceble.STATUS["official"]["valid"]
                )

                # We complete the path to the plain list file.
                plain_destination = (
                    output_domains % PyFunceble.STATUS["official"]["valid"]
                )

                # We complete the path to the json list file.
                json_destination = output_json % PyFunceble.STATUS["official"]["valid"]
            elif self.domain_status.lower() in PyFunceble.STATUS["list"]["down"]:
                # The status is in the list of down list.

                # We complete the path to the hosts file.
                hosts_destination = output_hosts % PyFunceble.STATUS["official"]["down"]

                # We complete the path to the plain list file.
                plain_destination = (
                    output_domains % PyFunceble.STATUS["official"]["down"]
                )

                # We complete the path to the json list file.
                json_destination = output_json % PyFunceble.STATUS["official"]["down"]
            elif self.domain_status.lower() in PyFunceble.STATUS["list"]["invalid"]:
                # The status is in the list of invalid list.

                # We complete the path to the hosts file.
                hosts_destination = (
                    output_hosts % PyFunceble.STATUS["official"]["invalid"]
                )

                # We complete the path to the plain list file.
                plain_destination = (
                    output_domains % PyFunceble.STATUS["official"]["invalid"]
                )

                # We complete the path to the json list file.
                json_destination = (
                    output_json % PyFunceble.STATUS["official"]["invalid"]
                )
            elif self.domain_status.lower() in http_list:
                # The status is in the list of analytic status.

                # We construct the path to the analytic directory.
                output_dir = self._analytic_host_file_directory()

                if not output_dir.endswith(directory_separator):
                    # The output directory does not ends with the directory separator.

                    # We append the directory separator at the end of the output directory.
                    output_dir += directory_separator

                # We initiate the hosts file path.
                hosts_destination = output_dir + PyFunceble.OUTPUTS["hosts"]["filename"]

                # We initiate the plain list file path.
                plain_destination = (
                    output_dir + PyFunceble.OUTPUTS["domains"]["filename"]
                )

                # We complete the path to the json list file.
                json_destination = output_dir + PyFunceble.OUTPUTS["json"]["filename"]

                # We initiate the path to the http code file.
                # Note: We generate the http code file so that
                # we can have each domain in a file which is the
                # extracted http code.
                splited_destination = output_dir + str(PyFunceble.INTERN["http_code"])

            if PyFunceble.CONFIGURATION["generate_hosts"]:
                # The hosts file generation is activated.

                # We generate/append the currently tested element in its
                # final location. (hosts file format)
                # We print on screen and on file.
                Prints(
                    [PyFunceble.CONFIGURATION["custom_ip"], self.tested],
                    "FullHosts",
                    hosts_destination,
                ).data()

            if PyFunceble.CONFIGURATION["plain_list_domain"]:
                # The plain list generation is activated.

                # We generate/append the currently tested element in its
                # final location. (the plain list format)
                # We print on file.
                Prints([self.tested], "PlainDomain", plain_destination).data()

            if PyFunceble.CONFIGURATION["split"] and splited_destination:
                # The splited list generation is activated.

                # We generate/append the currently tested element in its
                # final location. (the split list format)
                # We print on file.
                Prints([self.tested], "PlainDomain", splited_destination).data()

            if PyFunceble.CONFIGURATION["generate_json"]:
                # The jsaon list generation is activated.

                # We generate/append the currently tested element in its
                # final location. (the json format)
                # We print on file.
                Prints([self.tested], "JSON", json_destination).data()
def info_files ( self ) : # pylint: disable=inconsistent-return-statements if self . _do_not_produce_file ( ) : # We do not have to produce file. # We return false. return False if ( "file_to_test" in PyFunceble . INTERN and PyFunceble . INTERN [ "file_to_test" ] and ( PyFunceble . CONFIGURATION [ "generate_hosts" ] or PyFunceble . CONFIGURATION [ "plain_list_domain" ] or PyFunceble . CONFIGURATION [ "generate_json" ] ) ) : # * We are not testing as an imported module. # and # * The hosts file generation is activated. # or # * The plain list generation is activated. # We initiate a variable which whill save the splited testination. splited_destination = "" # We initiate the list of all analytic related statuses. http_list = [ ] http_list . extend ( PyFunceble . STATUS [ "list" ] [ "potentially_up" ] ) http_list . extend ( PyFunceble . STATUS [ "list" ] [ "potentially_down" ] ) http_list . extend ( PyFunceble . STATUS [ "list" ] [ "http_active" ] ) http_list . extend ( PyFunceble . STATUS [ "list" ] [ "suspicious" ] ) # We partially initiate the path to the hosts file. output_hosts = ( self . output_parent_dir + PyFunceble . OUTPUTS [ "hosts" ] [ "directory" ] + "%s" + directory_separator + PyFunceble . OUTPUTS [ "hosts" ] [ "filename" ] ) # We partially initiate the path to the plain list file. output_domains = ( self . output_parent_dir + PyFunceble . OUTPUTS [ "domains" ] [ "directory" ] + "%s" + directory_separator + PyFunceble . OUTPUTS [ "domains" ] [ "filename" ] ) # We partially intiate the path to the json list file. output_json = ( self . output_parent_dir + PyFunceble . OUTPUTS [ "json" ] [ "directory" ] + "%s" + directory_separator + PyFunceble . OUTPUTS [ "json" ] [ "filename" ] ) if self . domain_status . lower ( ) in PyFunceble . STATUS [ "list" ] [ "up" ] : # The status is in the list of up list. # We complete the path to the hosts file. hosts_destination = output_hosts % PyFunceble . STATUS [ "official" ] [ "up" ] # We complete the path to the plain list file. plain_destination = output_domains % PyFunceble . STATUS [ "official" ] [ "up" ] # We complete the path to the json list file. json_destination = output_json % PyFunceble . STATUS [ "official" ] [ "up" ] elif self . domain_status . lower ( ) in PyFunceble . STATUS [ "list" ] [ "valid" ] : # The status is in the list of valid list. # We complete the path to the hosts file. hosts_destination = ( output_hosts % PyFunceble . STATUS [ "official" ] [ "valid" ] ) # We complete the path to the plain list file. plain_destination = ( output_domains % PyFunceble . STATUS [ "official" ] [ "valid" ] ) # We complete the path to the json list file. json_destination = output_json % PyFunceble . STATUS [ "official" ] [ "valid" ] elif self . domain_status . lower ( ) in PyFunceble . STATUS [ "list" ] [ "down" ] : # The status is in the list of down list. # We complete the path to the hosts file. hosts_destination = output_hosts % PyFunceble . STATUS [ "official" ] [ "down" ] # We complete the path to the plain list file. plain_destination = ( output_domains % PyFunceble . STATUS [ "official" ] [ "down" ] ) # We complete the path to the json list file. json_destination = output_json % PyFunceble . STATUS [ "official" ] [ "down" ] elif self . domain_status . lower ( ) in PyFunceble . STATUS [ "list" ] [ "invalid" ] : # The status is in the list of invalid list. # We complete the path to the hosts file. hosts_destination = ( output_hosts % PyFunceble . STATUS [ "official" ] [ "invalid" ] ) # We complete the path to the plain list file. plain_destination = ( output_domains % PyFunceble . STATUS [ "official" ] [ "invalid" ] ) # We complete the path to the json list file. json_destination = ( output_json % PyFunceble . STATUS [ "official" ] [ "invalid" ] ) elif self . domain_status . lower ( ) in http_list : # The status is in the list of analytic status. # We construct the path to the analytic directory. output_dir = self . _analytic_host_file_directory ( ) if not output_dir . endswith ( directory_separator ) : # The output directory does not ends with the directory separator. # We append the directory separator at the end of the output directory. output_dir += directory_separator # We initiate the hosts file path. hosts_destination = output_dir + PyFunceble . OUTPUTS [ "hosts" ] [ "filename" ] # We initiate the plain list file path. plain_destination = ( output_dir + PyFunceble . OUTPUTS [ "domains" ] [ "filename" ] ) # We complete the path to the json list file. json_destination = output_dir + PyFunceble . OUTPUTS [ "json" ] [ "filename" ] # We initiate the path to the http code file. # Note: We generate the http code file so that # we can have each domain in a file which is the # extracted http code. splited_destination = output_dir + str ( PyFunceble . INTERN [ "http_code" ] ) if PyFunceble . CONFIGURATION [ "generate_hosts" ] : # The hosts file generation is activated. # We generate/append the currently tested element in its # final location. (hosts file format) # We print on screen and on file. Prints ( [ PyFunceble . CONFIGURATION [ "custom_ip" ] , self . tested ] , "FullHosts" , hosts_destination , ) . data ( ) if PyFunceble . CONFIGURATION [ "plain_list_domain" ] : # The plain list generation is activated. # We generate/append the currently tested element in its # final location. (the plain list format) # We print on file. Prints ( [ self . tested ] , "PlainDomain" , plain_destination ) . data ( ) if PyFunceble . CONFIGURATION [ "split" ] and splited_destination : # The splited list generation is activated. # We generate/append the currently tested element in its # final location. (the split list format) # We print on file. Prints ( [ self . tested ] , "PlainDomain" , splited_destination ) . data ( ) if PyFunceble . CONFIGURATION [ "generate_json" ] : # The jsaon list generation is activated. # We generate/append the currently tested element in its # final location. (the json format) # We print on file. Prints ( [ self . tested ] , "JSON" , json_destination ) . data ( )
Generate the hosts file, the plain list and the splitted lists.
Generate the hosts file the plain list and the splitted lists .