Beispiel #1
0
    def execute(self):

        # Get the stage of the job; running, finished or does not exist at all.
        output = Job.get_job_stage(self.job_id, self.running_jobs)

        # Check if it is running.
        if isinstance(output, Job):

            # Kill the job.
            output.kill()

            #Create a success object informing the client that no errors
            # happened, send it and tell the client to accept a new request
            # from the user.
            success = Success("Job" + str(self.job_id) + " was killed")
            self.pickle.send(success.create_dictionary())
            self.pickle.send(Terminate().create_dictionary())

        # If it is not a job then it is either True or False.
        elif output:
            # Send a message to the client informing it that it has already
            # finished.
            success = Success("This job has already finished")
            self.pickle.send(success.create_dictionary())
            self.pickle.send(Terminate().create_dictionary())

        else:
            # Send an error message to the client informing it that the
            # required job does not exist.
            error = Error("No such job with that id: " + self.job_id)
            self.pickle.send(error.create_dictionary())
Beispiel #2
0
    def execute(self):

        # Get the stage of the job; running, finished or does not exist at all.
        output = Job.get_job_stage(self.job_id, self.running_jobs)

        # Check if it is running.
        if isinstance(output, Job):

            # Get its status.
            job_status = output.get_status(Job.format_status,
                                           **{"delimiter": "\t"})

            # Create a success object with the status being its message, send
            # it and tell the client to accept the new request from the user.
            success = Success(job_status)
            self.pickle.send(success.create_dictionary())
            self.pickle.send(Terminate().create_dictionary())

        # If it is not a job then it is either True or False.
        elif output:

            # Send a message to the client informing it that it has already
            # finished.
            success = Success("This job has already finished")
            self.pickle.send(success.create_dictionary())
            self.pickle.send(Terminate().create_dictionary())

        else:
            # Send an error message to the client informing it that the
            # required job does not exist.
            error = Error("No such job with that id: " + str(self.job_id))
            self.pickle.send(error.create_dictionary())
Beispiel #3
0
    def execute(self, string_request: str):
        """Creates the associated parser and passes the request to it.

        Args:
            string_request: The client request.
        """

        # Check if the request is an empty string.
        if not string_request:
            # Tell the client to prompt the user to enter another command.
            self.pickle.send(Terminate().create_dictionary())
            return

        # Split the request. shlex was used here in order not to split quoted
        # strings.
        split = shlex.split(string_request, posix=False)

        # The instruction is the first word in the request.
        instruction = split[0].strip()

        # The arguments to that instruction is the rest of the request.
        argv = split[1:]

        # Try to execute the request. Get the right parser by the instruction
        try:
            self.parsers[instruction].execute(argv=argv, pickle=self.pickle,

                                              client_libraries=
                                              self.client_libraries,

                                              running_jobs=self.running_jobs,

                                              job_id_lock=self.job_id_lock,

                                              running_jobs_lock=
                                              self.running_jobs_lock)
        except KeyError as e:
            # A KeyError was raised because the instruction does not exist
            # (Not in the parsers dictionary). Create an error and send it
            # to the client.
            error = Error("No such instruction: " + str(e))
            self.pickle.send(error.create_dictionary())


        except ValueError as e:
            # This is raised because of the help or error message.
            self.pickle.send(Success(str(e)).create_dictionary())
            self.pickle.send(Terminate().create_dictionary())
Beispiel #4
0
    def execute(self):

        # Get the stage of the job; running, finished or does not exist at all.
        output = Job.get_job_stage(self.job_id, self.running_jobs)

        # Check if the job is still running.
        if isinstance(output, Job):
            # - Still running.
            # - Then there is no report generated yet. Inform the client.
            self.pickle.send(Error("Job is still running").create_dictionary())

        # Finished
        elif output:

            # Great, tell the client to be prepared to receive the folder.
            receive = Receive(pickle=None, path=self.client_reports_library)
            self.pickle.send(receive.create_dictionary())

            # Get the path to the results folder.
            server_path = get_server_job_report_path_by_id(self.job_id)

            # Send it.
            self.pickle.send_folder(server_path, server_jobs_reports_library)

            # client, you can accept the next request from the user, buddy.
            self.pickle.send(Terminate().create_dictionary())

        else:
            # No job was that ID, dude.
            error = Error("No such job with that id: " + self.job_id)
            self.pickle.send(error.create_dictionary())
Beispiel #5
0
    def execute(self):
        path_to_remove = remove_file_name(self.path)

        if not self.path.endswith("/E.tgz"):
            error = Error("The file must be named E.tgz and should contain the"
                          "folder E/")
            self.pickle.send(error.create_dictionary())
            return

        send = Send(None, self.path, path_to_remove)

        self.pickle.send(send.create_dictionary())
        prover_path = get_prover_path(self.prover_id)
        os.makedirs(prover_path, exist_ok=True)

        self.pickle.receive_folder(save_to=prover_path)

        success = Success("Extracting and installing...")
        self.pickle.send(success.create_dictionary())

        installer = Installer(self.prover_id)
        try:
            installer.install()

        except OSError as e:
            self.pickle.send(Error(str(e)).create_dictionary())

        else:
            success = Success("Prover submitted and installer")
            self.pickle.send(success.create_dictionary())
            self.pickle.send(Terminate().create_dictionary())
Beispiel #6
0
    def execute(self):
        # Make the directories needed to save the incoming folder/
        os.makedirs(self.to, exist_ok=True)

        # Ask the client to send the folder.
        # pickle is None here since if it were sent, the client would not be
        # able to use it because the receiver would be the client it self not
        # the server. The client would update it itself.
        send = Send(pickle=None,
                    path=self.from_,
                    path_to_remove=os.path.dirname(self.from_))

        # Send send to the client after converting it to a dictionary.
        self.pickle.send(send.create_dictionary())

        # Try to receive the folder.
        try:
            self.pickle.receive_folder(save_to=self.to)
        except ValueError as e:
            # No data was sent. exit and wait for the next request.
            return

        else:

            # Data was sent and saved. Inform the client.
            success_message = "Library was saved at " + self.to
            self.pickle.send(Success(success_message).create_dictionary())

            self.pickle.send(Terminate().create_dictionary())
Beispiel #7
0
    def execute(self):

        if self.recursive:
            libraries = []

            # Get a list of tuples: [(root path, folders in it, files in it).
            # Loop on it and append the folders only to the list that will be
            # sent to the client.
            for root, folders, files_ in os.walk(self.directory):
                for folder in folders:
                    libraries.append(os.path.join(root, folder))

        else:

            # Get the contents of this folder including files.
            libraries = os.listdir(server_problems_library)

        if libraries:
            # Found some folders in the library
            message = "Here is a list of the libraries:-\n- " + \
                      "\n- ".join(libraries)

        else:
            # Nothing was found. Send some text instead of empty list.
            message = "No libraries found!"

        # Create and send the success message.
        success = Success(message)
        self.pickle.send(success.create_dictionary())
        self.pickle.send(Terminate().create_dictionary())
Beispiel #8
0
    def execute(self):

        # Get the stage of the job; running, finished or does not exist at all.
        output = Job.get_job_stage(self.job_id, self.running_jobs)

        # If it is running, then output is the job, if it finished then output
        # Is true. In any of these two cases, the results folder can be sent.
        if output:

            # Create an instance from receive and send it to the client
            # infroming it that the server is going to send the results folder.
            # Also Tell the client to save it in the results library by adding
            # its path in Receive.
            receive = Receive(pickle=None, path=self.client_results_library)
            self.pickle.send(receive.create_dictionary())

            # Get the path of the results folder on the server.
            server_path = get_server_job_results_path_by_id(self.job_id)

            # Send it.
            self.pickle.send_folder(server_path, server_jobs_results_library)

            # Send a success message to the client.
            success = Success(
                "Job{} results folder was sent successfully".format(
                    self.job_id))

            # Tell the client to accept new requests from the user.
            self.pickle.send(success.create_dictionary())
            self.pickle.send(Terminate().create_dictionary())

        else:
            error = Error("No such job with that id: " + self.job_id)
            self.pickle.send(error.create_dictionary())
Beispiel #9
0
    def execute(self):
        """Execute the request."""

        # Try to make the directory the client asked for.
        try:
            os.makedirs(server_problems_library + self.directory)

        except OSError as e:
            # - That directory already exists.
            # - Then send that to the client.
            self.pickle.send(Error(str(e)).create_dictionary())

        else:

            # Inform the client that the library was created.
            # 1. Define the success message.
            success_message = "Library " + self.directory + \
                              " was created successfully"

            # 2. Create the success object using this message.
            success = Success(success_message)

            # 3. Create a dictionary of it.
            success_dictionary = success.create_dictionary()

            # 4. Send that dictionary to the client.
            self.pickle.send(success_dictionary)

            # Send Terminate to the client so that it prompts the user to enter
            # the next command
            # 1. Create an instance from Terminate.
            terminate = Terminate()

            # 2. Create a dictionary from it.
            terminate_dictionary = terminate.create_dictionary()

            # 3. send that dictionary.
            self.pickle.send(terminate_dictionary)
Beispiel #10
0
    def execute(self):

        # List the directory that has all the provers. Remove the first letter
        # as the server adds 'E' at the beginning of every ID. Sort them.
        provers = sorted(
            [prover[1:] for prover in os.listdir(provers_library)])

        # Check if there are no provers.
        if not provers:
            message = "No provers found!"
        else:
            # Create a success instance having its message as the list of the
            # provers.
            message = "Here is a list of the ids of the provers:-\n" + \
                "\n".join(provers)

        success = Success(message)
        self.pickle.send(success.create_dictionary())
        self.pickle.send(Terminate().create_dictionary())
Beispiel #11
0
    def execute(self):

        # Import the Parsers object.
        from parsers.argparser import Parsers

        # The first line of the help message.
        help_message = "Here is a list of all the instructions:-\n"

        # Create a new instance from Parsers in order to have access to its
        # dictionary.
        for key, value in Parsers(None, None, None, None).parsers.items():

            # Add every key to that dictionary.
            help_message += " -" + key + "\n"

        # The last line of the help message.
        help_message += "Select any of them and type -h to learn more about it"

        # Send the message.
        self.pickle.send(Success(help_message).create_dictionary())
        self.pickle.send(Terminate().create_dictionary())
Beispiel #12
0
    def execute(self):

        # Get details about all the jobs then convert them into a json string.
        data = Job.list_jobs(self.running_jobs,
                             json.dumps,
                             indent=2,
                             sort_keys=True,
                             default=lambda x: x.__dict__)

        if not data:

            # -No data was found.
            # -Make the success message say that there are neither running nor
            # finished jobs.
            success = Success("No running or finished jobs to list!")
        else:
            # Create a success instance with data being its message.
            success = Success(data)

        # Send the success message to the client.
        self.pickle.send(success.create_dictionary())
        self.pickle.send(Terminate().create_dictionary())
Beispiel #13
0
    def execute(self):
        try:
            self.configuration.verify_prover()
        except OSError as e:
            self.pickle.send(Error(str(e)).create_dictionary())
        else:
            try:
                problems = Job.get_problems_from_library(
                    self.problems_path, [])
                job = Job(problems, self.configuration,
                          self.maximum_problems_in_parallel, self.running_jobs,
                          self.running_jobs_lock, self.job_id_lock)

            except ValueError as e:
                self.pickle.send(Error(str(e)).create_dictionary())

            else:
                run_job_thread = Thread(name="run_job", target=job.run)
                run_job_thread.start()

                success = Success("Job submitted with id: " + str(job.id))
                self.pickle.send(success.create_dictionary())

                self.pickle.send(Terminate().create_dictionary())
Beispiel #14
0
    def execute(self):

        # Get the stage of the job; running, finished or does not exist at all.
        output = Job.get_job_stage(self.job_id, self.running_jobs)

        # Check if it is running.
        if isinstance(output, Job):

            # Send and error to the client since a job can not be rerun if it
            # is already running.
            error = Error("This job is already running")
            self.pickle.send(error.create_dictionary())

        elif output:

            # It has finished. Try to open the report. surrounding it with try
            # and catch is an extra precaution.
            try:
                with open(get_job_report(self.job_id), "r") as f:

                    # Get the prover options from the report.
                    prover_options = f.readline().split("\t")[1].strip()

                    # Get the prover ID from the report.
                    prover_id = f.readline().split("\t")[1].strip()

            except FileNotFoundError as e:
                # Report was not found. Inform the client.
                self.pickle.send(Error(str(e)).create_dictionary())

            else:

                # Make a new configuration object using the options and ID.
                configuration = Configuration(prover_options, prover_id)

                # Check if the prover exists.
                try:
                    configuration.verify_prover()

                except OSError as e:
                    self.pickle.send(Error(str(e)).create_dictionary())

                else:

                    # Get all the problems that failed or were removed.
                    problems = Problem.get_problems_from_report(self.job_id)

                    try:

                        # Create a job object.
                        job = Job(problems, configuration,
                                  self.maximum_problems_in_parallel,
                                  self.running_jobs, self.running_jobs_lock,
                                  self.job_id_lock, self.job_id)

                        # Create a thread to run that job and run it.
                        run_job_thread = Thread(name="run_job", target=job.run)
                        run_job_thread.start()

                    except ValueError as e:

                        # -Could not create a job.
                        # -Send the error to the client.
                        self.pickle.send(Error(str(e)).create_dictionary())

                    else:

                        # Send a success message to the client.
                        success = Success("Job" + str(self.job_id) +
                                          " was resubmitted")
                        self.pickle.send(success.create_dictionary())
                        self.pickle.send(Terminate().create_dictionary())

        else:
            # No job with that ID. Send that to the client.
            error = Error("No such job with that id: " + self.job_id)
            self.pickle.send(error.create_dictionary())