+class Condition:
+ RECOVERABLE = False
+
+ def getErrorMessage(self, task):
+ return _("An error has occured. (%s)") % (self.__class__.__name__)
+
+class WorkspaceExistsPrecondition(Condition):
+ def check(self, task):
+ return os.access(task.job.workspace, os.W_OK)
+
+class DiskspacePrecondition(Condition):
+ def __init__(self, diskspace_required):
+ self.diskspace_required = diskspace_required
+ self.diskspace_available = 0
+
+ def check(self, task):
+ import os
+ try:
+ s = os.statvfs(task.job.workspace)
+ self.diskspace_available = s.f_bsize * s.f_bavail
+ return self.diskspace_available >= self.diskspace_required
+ except OSError:
+ return False
+
+ def getErrorMessage(self, task):
+ return _("Not enough diskspace. Please free up some diskspace and try again. (%d MB required, %d MB available)") % (self.diskspace_required / 1024 / 1024, self.diskspace_available / 1024 / 1024)
+
+class ToolExistsPrecondition(Condition):