-#
-#class DiskspacePrecondition:
-# def __init__(self, diskspace_required):
-# self.diskspace_required = diskspace_required
-#
-# def check(self, task):
-# return getFreeDiskspace(task.workspace) >= self.diskspace_required
-#
-class ToolExistsPrecondition:
+
+class Condition:
+ RECOVERABLE = False
+
+ def getErrorMessage(self, task):
+ return _("An unknown error occured!") + " (%s @ task %s)" % (self.__class__.__name__, task.__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):