Save the tested release workflows, RAM media processing, program discovery, FLIRT library, and shared-object maintenance. Add Git exclusions, file attributes, and instructions for a later push using a forwarded SSH agent.
32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
"""RAM-only scratch policy shared by standalone validation tools."""
|
|
import os
|
|
import pathlib
|
|
import re
|
|
import shutil
|
|
|
|
|
|
def ram_workspace(config):
|
|
path = pathlib.Path(config.get('workspace', '/tmp/verstack-workspace')).resolve()
|
|
path.mkdir(parents=True, exist_ok=True)
|
|
mounts = []
|
|
for line in pathlib.Path('/proc/self/mountinfo').read_text().splitlines():
|
|
fields, filesystem = line.split(' - ', 1)
|
|
point = pathlib.Path(re.sub(r'\\([0-7]{3})', lambda m: chr(int(m[1], 8)), fields.split()[4]))
|
|
if path.is_relative_to(point):
|
|
mounts.append((len(point.parts), filesystem.split()[0]))
|
|
if not mounts or max(mounts)[1] not in ('tmpfs', 'ramfs'):
|
|
raise ValueError('validation workspace must be on tmpfs/ramfs; no disk fallback')
|
|
budget = int(config.get('workspace_bytes', 8 * 1024**3))
|
|
if budget <= 0 or budget > shutil.disk_usage(path).free:
|
|
raise ValueError('insufficient free RAM workspace for configured workspace_bytes')
|
|
return path, budget
|
|
|
|
|
|
def scratch_environment(root):
|
|
root = pathlib.Path(root).resolve()
|
|
scratch = root / 'tmp'
|
|
scratch.mkdir(exist_ok=True)
|
|
return {**os.environ, 'TMPDIR': str(scratch), 'TMP': str(scratch),
|
|
'TEMP': str(scratch), 'XDG_CACHE_HOME': str(root / 'cache'),
|
|
'PYTHONDONTWRITEBYTECODE': '1'}
|