class FieldTester: value = fields.AbsolutePathField('value', type(None)) def __init__(self, value): self.value = value
class HostResources: """Resources associated with ReFrame execution on the current host. .. note:: .. versionadded:: 2.13 """ #: The prefix directory of ReFrame execution. #: This is always an absolute path. #: #: :type: :class:`str` #: #: .. caution:: #: Users may not set this field. #: prefix = fields.AbsolutePathField('prefix') outputdir = fields.AbsolutePathField('outputdir', type(None)) stagedir = fields.AbsolutePathField('stagedir', type(None)) perflogdir = fields.AbsolutePathField('perflogdir', type(None)) def __init__(self, prefix=None, stagedir=None, outputdir=None, perflogdir=None, timefmt=None): self.prefix = prefix or '.' self.stagedir = stagedir self.outputdir = outputdir self.perflogdir = perflogdir self.timefmt = timefmt self._timestamp = datetime.now() def _makedir(self, *dirs, wipeout=False): ret = os.path.join(*dirs) if wipeout: os_ext.rmtree(ret, ignore_errors=True) os.makedirs(ret, exist_ok=True) return ret def _format_dirs(self, *dirs): try: last = dirs[-1] except IndexError: return dirs current_run = runtime().current_run if current_run == 0: return dirs last += '_retry%s' % current_run return (*dirs[:-1], last) @property def timestamp(self): return self._timestamp.strftime(self.timefmt) if self.timefmt else '' @property def output_prefix(self): """The output prefix directory of ReFrame.""" if self.outputdir is None: return os.path.join(self.prefix, 'output', self.timestamp) else: return os.path.join(self.outputdir, self.timestamp) @property def stage_prefix(self): """The stage prefix directory of ReFrame.""" if self.stagedir is None: return os.path.join(self.prefix, 'stage', self.timestamp) else: return os.path.join(self.stagedir, self.timestamp) @property def perflog_prefix(self): if self.perflogdir is None: return os.path.join(self.prefix, 'perflogs') else: return self.perflogdir def make_stagedir(self, *dirs, wipeout=True): return self._makedir(self.stage_prefix, *self._format_dirs(*dirs), wipeout=wipeout) def make_outputdir(self, *dirs, wipeout=True): return self._makedir(self.output_prefix, *self._format_dirs(*dirs), wipeout=wipeout)