Skip to content

Commit

Permalink
PDG: mantra parser searches PDG_RESULT for image
Browse files Browse the repository at this point in the history
Task environment variables are passed to parser.

References: #514.
  • Loading branch information
timurhai committed Aug 13, 2021
1 parent 5b69b89 commit 0cd1806
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions afanasy/python/check_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def UsageExit(message=''):
taskInfo = dict()
taskInfo['frames_num'] = framesNum
taskInfo['wdir'] = os.getcwd()
taskInfo['environment'] = dict()
taskInfo['environment']['PDG_DIR'] = os.getcwd()
parser.setTaskInfo(taskInfo)

arguments = []
Expand Down
19 changes: 19 additions & 0 deletions afanasy/python/parsers/mantra.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

IMAGE_RE = re.compile(r'.*Generating Image: (.+) \(\d+x\d+\)')

PDG_IMG_RE = re.compile(r'PDG_RESULT:.*;\s*(.*)\s*;.*;.*')

ErrorsRE = [re.compile(r'Error loading geometry .* from stdin')]

PeakMem_RE = re.compile('.*Peak Memory Usage: *(.*)')
Expand Down Expand Up @@ -51,6 +53,12 @@ def do(self, i_args):
m = IMAGE_RE.match(line)
if m:
self.appendFile(m.group(1))
m = PDG_IMG_RE.search(line)
if m:
img = m.group(1)
if cgruutils.isImageExt(img):
self.appendFile(self.expandEnvVars(img))


percent_pos = data.find(PERCENT)
if percent_pos > -1:
Expand Down Expand Up @@ -89,3 +97,14 @@ def do(self, i_args):
res = res.strip()
if len(res):
self.resources = res


def expandEnvVars(self, i_str):

if not 'environment' in self.taskInfo:
return i_str

for name in self.taskInfo['environment']:
i_str = i_str.replace('__%s__' % name, cgruutils.toStr(self.taskInfo['environment'][name]))

return i_str
5 changes: 5 additions & 0 deletions afanasy/src/libafanasy/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ void Service::initialize( const TaskExec * i_task_exec, const std::string & i_st
PyList_Append( pHostsList, PyBytes_FromString((*it).c_str()));


PyObject * pEenvDict = PyDict_New();
for (auto const& it : i_task_exec->getEnv())
PyDict_SetItemString(pEenvDict, it.first.c_str(), PyBytes_FromString(it.second.c_str()));

PyObject *pArgs;
pArgs = PyTuple_New( 2);

Expand All @@ -189,6 +193,7 @@ void Service::initialize( const TaskExec * i_task_exec, const std::string & i_st
PyDict_SetItemString( task_info, "file_size_max", PyLong_FromLong( i_task_exec->getFileSizeMax()));
PyDict_SetItemString( task_info, "hosts", pHostsList);
PyDict_SetItemString( task_info, "parsed_files", pParsedFilesList);
PyDict_SetItemString(task_info, "environment", pEenvDict);

PyDict_SetItemString( task_info, "frame_start", PyLong_FromLong(i_task_exec->getFrameStart()));
PyDict_SetItemString( task_info, "frame_finish", PyLong_FromLong(i_task_exec->getFrameFinish()));
Expand Down

0 comments on commit 0cd1806

Please sign in to comment.