3
import boinc_path_config
4
from assimilator import *
7
class PymwAssimilator(Assimilator):
9
PyMW Assimilator. Copies workunit results to a predefined output directory.
13
Assimilator.__init__(self)
16
def _copy_to_output(self, result, error_mask=0):
17
# validate that the destination path still exists
18
if not os.path.exists(self.pymwDir):
19
self.logCritical("PyMW path does not exist or is inaccessible: %s\n", \
23
resultFullPath = self.get_file_path(result)
24
resultName = re.search('<open_name>(.*)</open_name>',result.xml_doc_in).group(1)
26
# validate that the source path is accessible
27
if not error_mask and not os.path.exists(resultFullPath):
28
self.logCritical("Result path does not exist or is inaccessible: %s\n", \
32
# copy the file to the output directory where it
33
# will be processed by PyMW
35
dest = os.path.join(self.pymwDir, resultName)
40
f.writelines("BOINC error: " + str(error_mask) + "\n")
42
f.writelines("STD ERR: " + result.stderr_out + "\n")
43
f.writelines("For additional information, check: " +
44
"$project/log_$machine/pymw_assimilator.py.log\n")
46
self.logNormal("Error flag created [%s]\n", resultName)
48
shutil.copy2(resultFullPath, dest)
49
self.logNormal("Result copied [%s]\n", resultName)
51
self.logCritical("Error copying output\n" + \
55
resultFullPath, dest, msg)
57
def assimilate_handler(self, wu, results, canonical_result):
59
Assimilates a canonical result by copying the result file
60
to the PyMW pickup directory, self.pymwDir
63
# check for valid wu.canonical_result
64
if wu.canonical_result:
65
self.logNormal("[%s] Found canonical result\n", wu.name)
66
self._copy_to_output(canonical_result, wu.error_mask)
67
elif wu.error_mask != 0:
69
self.logNormal("[%s] Workunit failed, sending arbitrary result\n", wu.name)
70
self._copy_to_output(results[0], wu.error_mask)
71
self.logNormal("[%s] No canonical result\n", wu.name)
73
self.logNormal("[%s] No canonical result\n", wu.name)
75
# report errors with the workunit
76
if self.report_errors(wu):
80
def parse_args(self, args):
82
This overridden version adds support for a PyMW destination directory.
85
# scan the args for the -pymw_dir switch
86
# remove it when found so the base class doesn't complain
87
# then call the base parse_args method
95
if arg.strip() == '-pymw_dir':
97
self.logCritical("Error, path switch found, but no path specified\n")
100
self.pymwDir = args.pop()
101
if not os.path.exists(self.pymwDir):
102
self.logNormal("Warning, path does not exist or is inaccessible: %s\n", \
111
self.logCritical("Error, path argument expected: -pymw_dir <PATH>\n")
114
Assimilator.parse_args(self, newArgs)
116
# allow the module to be executed as an application
117
if __name__ == '__main__':
118
asm = PymwAssimilator()