Skip to content

Commit

Permalink
[Task.py] Update to pli version
Browse files Browse the repository at this point in the history
  • Loading branch information
teamblue-e2 committed Jun 4, 2024
1 parent 40f89c3 commit 900158b
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions lib/python/Components/Task.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# -*- coding: utf-8 -*-
# A Job consists of many "Tasks".
# A task is the run of an external tool, with proper methods for failure handling

from Tools.CList import CList
import six


class Job:
NOT_STARTED, IN_PROGRESS, FINISHED, FAILED = list(range(4))
NOT_STARTED, IN_PROGRESS, FINISHED, FAILED = range(4)

def __init__(self, name):
self.tasks = []
Expand Down Expand Up @@ -204,13 +202,12 @@ def cleanup(self, failed):
pass

def processStdout(self, data):
self.processOutput(data)
self.processOutput(data.decode())

def processStderr(self, data):
self.processOutput(data)
self.processOutput(data.decode())

def processOutput(self, data):
data = six.ensure_str(data)
self.output_line += data
while True:
i = self.output_line.find('\n')
Expand All @@ -221,6 +218,7 @@ def processOutput(self, data):

def processOutputLine(self, line):
print("[Task %s]" % self.name, line[:-1])
pass

def processFinished(self, returncode):
self.returncode = returncode
Expand Down Expand Up @@ -382,13 +380,13 @@ def kick(self):
self.active_job.start(self.jobDone)

def notifyFailed(self, job, task, problems):
import Tools.Notifications
from Tools.Notifications import AddNotification, AddNotificationWithCallback
from Screens.MessageBox import MessageBox
if problems[0].RECOVERABLE:
Tools.Notifications.AddNotificationWithCallback(self.errorCB, MessageBox, _("Error: %s\nRetry?") % (problems[0].getErrorMessage(task)))
AddNotificationWithCallback(self.errorCB, MessageBox, _("Error: %s\nRetry?") % (problems[0].getErrorMessage(task)))
return True
else:
Tools.Notifications.AddNotification(MessageBox, job.name + "\n" + _("Error") + ': %s' % (problems[0].getErrorMessage(task)), type=MessageBox.TYPE_ERROR)
AddNotification(MessageBox, job.name + "\n" + _("Error") + (': %s') % (problems[0].getErrorMessage(task)), type=MessageBox.TYPE_ERROR)
return False

def jobDone(self, job, task, problems):
Expand All @@ -405,10 +403,10 @@ def jobDone(self, job, task, problems):
# Set job.onSuccess to this function if you want to pop up the jobview when the job is done/
def popupTaskView(self, job):
if not self.visible:
import Tools.Notifications
from Tools.Notifications import AddNotification
from Screens.TaskView import JobView
self.visible = True
Tools.Notifications.AddNotification(JobView, job)
AddNotification(JobView, job)

def errorCB(self, answer):
if answer:
Expand Down Expand Up @@ -464,19 +462,13 @@ def getPendingJobs(self):


class Condition:
def __init__(self):
pass

RECOVERABLE = False

def getErrorMessage(self, task):
return _("An unknown error occurred!") + " (%s @ task %s)" % (self.__class__.__name__, task.__class__.__name__)


class WorkspaceExistsPrecondition(Condition):
def __init__(self):
pass

def check(self, task):
return os.access(task.job.workspace, os.W_OK)

Expand Down Expand Up @@ -510,9 +502,7 @@ def check(self, task):
self.realpath = task.cmd
path = os.environ.get('PATH', '').split(os.pathsep)
path.append(task.cwd + '/')
# FIXME PY3 map,filter
absolutes = list(filter(lambda _file: os.access(_file, os.X_OK), map(lambda directory, _file=task.cmd: os.path.join(directory, _file), path)))
#absolutes = list([_file for _file in map(lambda directory, _file=task.cmd: os.path.join(directory, _file), path) if os.access(_file, os.X_OK)])
absolutes = list(filter(lambda file: os.access(file, os.X_OK), list(map(lambda directory, file=task.cmd: os.path.join(directory, file), path))))
if absolutes:
self.realpath = absolutes[0]
return True
Expand All @@ -523,17 +513,11 @@ def getErrorMessage(self, task):


class AbortedPostcondition(Condition):
def __init__(self):
pass

def getErrorMessage(self, task):
return _("Cancelled upon user request")


class ReturncodePostcondition(Condition):
def __init__(self):
pass

def check(self, task):
return task.returncode == 0

Expand Down

0 comments on commit 900158b

Please sign in to comment.