Exemple #1
0
    def follow_task(self, task_id):
        """
        Follow a task which is remotely executed on the Cobbler-server.

        :param task_id: The id of the task to follow.
        """
        logfile = "/var/log/cobbler/tasks/%s.log" % task_id
        # adapted from:  http://code.activestate.com/recipes/157035/
        file = open(logfile, 'r')
        # Find the size of the file and move to the end
        # st_results = os.stat(filename)
        # st_size = st_results[6]
        # file.seek(st_size)

        while 1:
            where = file.tell()
            line = file.readline()
            if line.find("### TASK COMPLETE ###") != -1:
                print("*** TASK COMPLETE ***")
                return 0
            if line.find("### TASK FAILED ###") != -1:
                print("!!! TASK FAILED !!!")
                return 1
            if not line:
                time.sleep(1)
                file.seek(where)
            else:
                if line.find(" | "):
                    line = line.split(" | ")[-1]
                print(line, end='')
Exemple #2
0
    def follow_task(self, task_id):
        logfile = "/var/log/cobbler/tasks/%s.log" % task_id
        # adapted from:  http://code.activestate.com/recipes/157035/
        file = open(logfile, 'r')
        # Find the size of the file and move to the end
        # st_results = os.stat(filename)
        # st_size = st_results[6]
        # file.seek(st_size)

        while 1:
            where = file.tell()
            line = file.readline()
            if line.find("### TASK COMPLETE ###") != -1:
                print("*** TASK COMPLETE ***")
                sys.exit(0)
            if line.find("### TASK FAILED ###") != -1:
                print("!!! TASK FAILED !!!")
                sys.exit(1)
            if not line:
                time.sleep(1)
                file.seek(where)
            else:
                if line.find(" | "):
                    line = line.split(" | ")[-1]
                print(line, end='')
Exemple #3
0
    def follow_task(self, task_id):
        """
        Parse out this task's specific messages from the global log

        :param task_id: The id of the task to follow.
        """
        logfile = "/var/log/cobbler/cobbler.log"
        # adapted from:  http://code.activestate.com/recipes/157035/
        file = open(logfile, 'r')
        # Find the size of the file and move to the end
        # st_results = os.stat(filename)
        # st_size = st_results[6]
        # file.seek(st_size)

        while 1:
            where = file.tell()
            line = file.readline()
            if not line.startswith("[" + task_id + "]"):
                continue
            if line.find("### TASK COMPLETE ###") != -1:
                print("*** TASK COMPLETE ***")
                return 0
            if line.find("### TASK FAILED ###") != -1:
                print("!!! TASK FAILED !!!")
                return 1
            if not line:
                time.sleep(1)
                file.seek(where)
            else:
                if line.find(" | "):
                    line = line.split(" | ")[-1]
                print(line, end='')