PyFunceble/database.py
def _reformat_historical_formating_error(self):  # pragma: no cover
        """
        Format the old format so it can be merged into the newer format.
        """

        if PyFunceble.CONFIGURATION["inactive_database"]:
            # The database subsystem is activated.

            # We construct the possible path to an older version of the database.
            historical_formating_error = (
                PyFunceble.CURRENT_DIRECTORY + "inactive-db.json"
            )

            if PyFunceble.path.isfile(historical_formating_error):
                # The histortical file already exists.

                # We get its content.
                data = Dict().from_json(File(historical_formating_error).read())

                # We initiate a variable which will save the data that is going
                # to be merged.
                data_to_parse = {}

                # We get the database keybase.
                top_keys = data.keys()

                for top_key in top_keys:
                    # We loop through the list of upper keys.

                    # We get the lowest keys.
                    low_keys = data[top_key].keys()

                    # We initiate the data to parse.
                    data_to_parse[top_key] = {}

                    for low_key in low_keys:
                        # We loop through the list of lower keys.

                        if low_key.isdigit():
                            # The current low key is a digit.

                            # We parse its content (from the old) into the new format.
                            # In between, we remove 30 days from the low_key so that
                            # it become in the past. This way they will be retested
                            # automatically.
                            data_to_parse[top_key][
                                int(low_key) - (self.one_day_in_seconds * 30)
                            ] = data[top_key][low_key]
                        else:
                            # The current low key is not a digit.

                            # We parse its content (from the old) into the new format.
                            # In between, we remove 30 days from the current time so that
                            # it become in the past. This way they will be retested
                            # automatically.
                            data_to_parse[top_key][
                                int(PyFunceble.time()) - (self.one_day_in_seconds * 30)
                            ] = data[top_key][low_key]

                if "inactive_db" in PyFunceble.INTERN:
                    # The current (new) database is not empty.

                    # We update add the content of the old into the current database.
                    PyFunceble.INTERN["inactive_db"].update(data_to_parse)
                else:
                    # The current (new) database is empty.

                    # We replace the content with the data_to_parse as it is complient
                    # with the new format.
                    PyFunceble.INTERN["inactive_db"] = data_to_parse

                # We delete the old database file.
                File(historical_formating_error).delete()
def _reformat_historical_formating_error(self):  # pragma: no cover
        if PyFunceble.CONFIGURATION["inactive_database"]:
            # The database subsystem is activated.

            # We construct the possible path to an older version of the database.
            historical_formating_error = (
                PyFunceble.CURRENT_DIRECTORY + "inactive-db.json"
            )

            if PyFunceble.path.isfile(historical_formating_error):
                # The histortical file already exists.

                # We get its content.
                data = Dict().from_json(File(historical_formating_error).read())

                # We initiate a variable which will save the data that is going
                # to be merged.
                data_to_parse = {}

                # We get the database keybase.
                top_keys = data.keys()

                for top_key in top_keys:
                    # We loop through the list of upper keys.

                    # We get the lowest keys.
                    low_keys = data[top_key].keys()

                    # We initiate the data to parse.
                    data_to_parse[top_key] = {}

                    for low_key in low_keys:
                        # We loop through the list of lower keys.

                        if low_key.isdigit():
                            # The current low key is a digit.

                            # We parse its content (from the old) into the new format.
                            # In between, we remove 30 days from the low_key so that
                            # it become in the past. This way they will be retested
                            # automatically.
                            data_to_parse[top_key][
                                int(low_key) - (self.one_day_in_seconds * 30)
                            ] = data[top_key][low_key]
                        else:
                            # The current low key is not a digit.

                            # We parse its content (from the old) into the new format.
                            # In between, we remove 30 days from the current time so that
                            # it become in the past. This way they will be retested
                            # automatically.
                            data_to_parse[top_key][
                                int(PyFunceble.time()) - (self.one_day_in_seconds * 30)
                            ] = data[top_key][low_key]

                if "inactive_db" in PyFunceble.INTERN:
                    # The current (new) database is not empty.

                    # We update add the content of the old into the current database.
                    PyFunceble.INTERN["inactive_db"].update(data_to_parse)
                else:
                    # The current (new) database is empty.

                    # We replace the content with the data_to_parse as it is complient
                    # with the new format.
                    PyFunceble.INTERN["inactive_db"] = data_to_parse

                # We delete the old database file.
                File(historical_formating_error).delete()
def _reformat_historical_formating_error ( self ) : # pragma: no cover if PyFunceble . CONFIGURATION [ "inactive_database" ] : # The database subsystem is activated. # We construct the possible path to an older version of the database. historical_formating_error = ( PyFunceble . CURRENT_DIRECTORY + "inactive-db.json" ) if PyFunceble . path . isfile ( historical_formating_error ) : # The histortical file already exists. # We get its content. data = Dict ( ) . from_json ( File ( historical_formating_error ) . read ( ) ) # We initiate a variable which will save the data that is going # to be merged. data_to_parse = { } # We get the database keybase. top_keys = data . keys ( ) for top_key in top_keys : # We loop through the list of upper keys. # We get the lowest keys. low_keys = data [ top_key ] . keys ( ) # We initiate the data to parse. data_to_parse [ top_key ] = { } for low_key in low_keys : # We loop through the list of lower keys. if low_key . isdigit ( ) : # The current low key is a digit. # We parse its content (from the old) into the new format. # In between, we remove 30 days from the low_key so that # it become in the past. This way they will be retested # automatically. data_to_parse [ top_key ] [ int ( low_key ) - ( self . one_day_in_seconds * 30 ) ] = data [ top_key ] [ low_key ] else : # The current low key is not a digit. # We parse its content (from the old) into the new format. # In between, we remove 30 days from the current time so that # it become in the past. This way they will be retested # automatically. data_to_parse [ top_key ] [ int ( PyFunceble . time ( ) ) - ( self . one_day_in_seconds * 30 ) ] = data [ top_key ] [ low_key ] if "inactive_db" in PyFunceble . INTERN : # The current (new) database is not empty. # We update add the content of the old into the current database. PyFunceble . INTERN [ "inactive_db" ] . update ( data_to_parse ) else : # The current (new) database is empty. # We replace the content with the data_to_parse as it is complient # with the new format. PyFunceble . INTERN [ "inactive_db" ] = data_to_parse # We delete the old database file. File ( historical_formating_error ) . delete ( )
Format the old format so it can be merged into the newer format.
Format the old format so it can be merged into the newer format .