Beispiel #1
0
def __main__():
    """
        Main function, creates the loop and starts the controller class.
    """
    taskslist = readfile()
    tasks = createtasks(taskslist["tasks"])
    controller = Controller.getinstance()
    controller.starttasks(tasks)
    controller.printresults()
    controller.end()
 async def executetask(self, depencencesevent, finalevent):
     """
     This function execute the task arguments
     :return: None
     """
     print("Started " + self.__name)          # The task starts
     if depencencesevent is not None:
         await depencencesevent.wait()
     if self.__type == "exec":    # The task has shell commands
         try:
             proc = await asyncio.create_subprocess_shell(
                 self.__arguments, stdout=asyncio.subprocess.PIPE)    # Execute the shell commands
             await proc.wait()                                       # Wait until the instruction ends
             if proc.returncode != 0:            # If the return code is not 0 we set the task as failed
                 self.__taskstatus = "fail"
             else:
                 lines = (await proc.communicate())[0].splitlines()
                 for line in lines:
                     print(line.strip())
                 self.__taskstatus = "ok"
         except Exception as e:
             print(e)
             self.__taskstatus = "fail"
     else:                           # The task has code snippet
         try:
             proc = await asyncio.create_subprocess_exec(
                 sys.executable, '-c', self.__arguments,
                 stdout=asyncio.subprocess.PIPE)             # Execute the task code
             await proc.wait()                               # Wait until the instruction ends
             lines = (await proc.communicate())[0].splitlines()
             for line in lines:
                 print(line.strip())
             self.__taskstatus = "ok"
         except Exception as e:
             print(e)
             self.__taskstatus = "fail"
     print("Ended " + self.__name)
     Controller.getinstance().sendmessage([self.__name, self.__taskstatus])  # Informs that the current task is done
     finalevent.set()                # Wakes up the controller