Example #1
0
    def get_problems_from_library(path: str, problems: [Problem]):
        if not os.path.isdir(path):
            raise ValueError("No library with that path: " + path)
        for item in os.listdir(path):
            new_path = directorize(path) + directorize(item)
            if os.path.isdir(new_path):
                Job.get_problems_from_library(new_path, problems)
            else:
                if item.endswith(Problem.problems_extensions):
                    problems.append(
                        Problem("/" + directorize(os.path.abspath(path)) +
                                item))

        return problems
Example #2
0
    def receive_folder(self, save_to: str) -> None:
        """Receives the folder that was sent by send_folder()

        Args:
            save_to: Where to save this damn folder to.
        """

        # Make sure that it ends with '/'
        save_to = directorize(save_to)
        data = self.receive()

        # Raise an error if there is no data. Let each side de-side what to
        # do in this situation.
        if not data:
            raise ValueError("No data was sent")

        # Loop on the received data.
        for file_path, file_data in data:

            # Append to 'save_to' since its the main folder.
            # The received file may need to be saved in a subfolder
            full_path = save_to + file_path

            # Make this subfolder. If it exists then do not raise an error.
            os.makedirs(remove_file_name(full_path), exist_ok=True)

            # Write that file in that folder.
            with open(full_path, "wb") as f:
                f.write(file_data)
Example #3
0
        def __get_all_folder_contents(path: str, data: [(str, str)]):
            """
            Read all files in the given path 'path' and its subfolders
            Provided that it is a folder.

            Args:
                path: Path to folder or file.
                data: A list of tuples. The second entry of a tuple is the
                      file and the first is the path to it. These files
                      are the read files.

            Returns:
                [(str, str)]: It is the very same argument 'data' (It is a
                              recursive function).
            """

            # Check if 'path' is a file.
            if os.path.isfile(path):
                # -It is a file
                # -Good, no need for more recursion then. read it.
                with open(path, "rb") as f:
                    file_ = f.read()

                # now add it to our list 'data'.
                data.append((path.replace(path_to_remove, ""), file_))

            else:
                # -No it is a folder.
                # -Then we will have to do the same for all of its contents.
                # First ensure that it ends with a '/' as we will append
                # another string to it.
                path = directorize(path)

                # Useless if condition. Or at least I do not remember why it
                # is here. If it is not a file then it is a directory.
                if os.path.isdir(path):

                    # Loop on every item in that folder.
                    for item in os.listdir(path):
                        # Now repeat the process but for this item instead.
                        __get_all_folder_contents(path + item, data)

            return data
Example #4
0
def prepare_input_path(path: str) -> str:
    return directorize(os.path.abspath(os.path.expanduser(path)))
Example #5
0
    argparser = ArgumentParser(description="For parsing paths")
    argparser.add_argument(
        "-s",
        "--server-library",
        help="The main library path that will contain all the "
        "other libraries for the Server")

    argparser.add_argument(
        "-c",
        "--client-library",
        help="The main library path that will contain all the "
        "other libraries for the client")

    args = argparser.parse_args()

    default_server_library = directorize(
        os.path.abspath("./server_libraries/"))

    default_client_library = directorize(
        os.path.abspath("./client_libraries/"))

    server_libraries = prepare_input_path(args.server_library) if \
        args.server_library else default_server_library

    client_libraries = prepare_input_path(args.client_library) if \
        args.client_library else default_client_library

    jobs = "jobs/"
    jobs_reports = jobs + "reports/"
    jobs_results = jobs + "results/"
    jobs_details = jobs + "details/"