PyFunceble/directory_structure.py
def backup(self):
        """
        Backup the developer state of `output/` in order to make it restorable
            and portable for user.
        """

        # We set the current output directory path.
        output_path = self.base + PyFunceble.OUTPUTS["parent_directory"]

        # We initiate the structure base.
        result = {PyFunceble.OUTPUTS["parent_directory"]: {}}

        for root, _, files in PyFunceble.walk(output_path):
            # We loop through the current output directory structure.

            # We get the currently read directory name.
            directories = Directory(root.split(output_path)[1]).fix_path()

            # We initiate a local variable which will get the structure of the subdirectory.
            local_result = result[PyFunceble.OUTPUTS["parent_directory"]]

            for file in files:
                # We loop through the list of files.

                # We construct the file path.
                file_path = root + PyFunceble.directory_separator + file

                # We get the hash of the file.
                file_hash = Hash(file_path, "sha512", True).get()

                # We convert the file content to a list.
                lines_in_list = [line.rstrip("\n") for line in open(file_path)]

                # We convert the file content into a more flat format.
                # We use `@@@` as glue and implicitly replacement for `\n`.
                formatted_content = "@@@".join(lines_in_list)

                # We update the local result (and implicitly the global result)
                # with the files and directory informations/structure.
                local_result = local_result.setdefault(
                    directories,
                    {file: {"sha512": file_hash, "content": formatted_content}},
                )

        # We finally save the directory structure into the production file.
        Dict(result).to_json(self.base + "dir_structure_production.json")
def backup(self):
        """
        Backup the developer state of `output/` in order to make it restorable
            and portable for user.
        """

        # We set the current output directory path.
        output_path = self.base + PyFunceble.OUTPUTS["parent_directory"]

        # We initiate the structure base.
        result = {PyFunceble.OUTPUTS["parent_directory"]: {}}

        for root, _, files in PyFunceble.walk(output_path):
            # We loop through the current output directory structure.

            # We get the currently read directory name.
            directories = Directory(root.split(output_path)[1]).fix_path()

            # We initiate a local variable which will get the structure of the subdirectory.
            local_result = result[PyFunceble.OUTPUTS["parent_directory"]]

            for file in files:
                # We loop through the list of files.

                # We construct the file path.
                file_path = root + PyFunceble.directory_separator + file

                # We get the hash of the file.
                file_hash = Hash(file_path, "sha512", True).get()

                # We convert the file content to a list.
                lines_in_list = [line.rstrip("\n") for line in open(file_path)]

                # We convert the file content into a more flat format.
                # We use `@@@` as glue and implicitly replacement for `\n`.
                formatted_content = "@@@".join(lines_in_list)

                # We update the local result (and implicitly the global result)
                # with the files and directory informations/structure.
                local_result = local_result.setdefault(
                    directories,
                    {file: {"sha512": file_hash, "content": formatted_content}},
                )

        # We finally save the directory structure into the production file.
        Dict(result).to_json(self.base + "dir_structure_production.json")
def backup ( self ) : # We set the current output directory path. output_path = self . base + PyFunceble . OUTPUTS [ "parent_directory" ] # We initiate the structure base. result = { PyFunceble . OUTPUTS [ "parent_directory" ] : { } } for root , _ , files in PyFunceble . walk ( output_path ) : # We loop through the current output directory structure. # We get the currently read directory name. directories = Directory ( root . split ( output_path ) [ 1 ] ) . fix_path ( ) # We initiate a local variable which will get the structure of the subdirectory. local_result = result [ PyFunceble . OUTPUTS [ "parent_directory" ] ] for file in files : # We loop through the list of files. # We construct the file path. file_path = root + PyFunceble . directory_separator + file # We get the hash of the file. file_hash = Hash ( file_path , "sha512" , True ) . get ( ) # We convert the file content to a list. lines_in_list = [ line . rstrip ( "\n" ) for line in open ( file_path ) ] # We convert the file content into a more flat format. # We use `@@@` as glue and implicitly replacement for `\n`. formatted_content = "@@@" . join ( lines_in_list ) # We update the local result (and implicitly the global result) # with the files and directory informations/structure. local_result = local_result . setdefault ( directories , { file : { "sha512" : file_hash , "content" : formatted_content } } , ) # We finally save the directory structure into the production file. Dict ( result ) . to_json ( self . base + "dir_structure_production.json" )
Backup the developer state of `output/` in order to make it restorable
            and portable for user.
Backup the developer state of output / in order to make it restorable and portable for user .