slsDetectorPackage/docs/gen_server_doc.py.in
Erik Frojdh 8ae0659478 docs
2020-09-11 15:09:44 +02:00

44 lines
1.3 KiB
Python

import os
import re
from pathlib import Path
# @CMAKE_CURRENT_BINARY_DIR@
src = Path('@CMAKE_SOURCE_DIR@')/'slsDetectorServers/'
detectors = ['Mythen3', 'Gotthard2', 'Eiger', 'Jungfrau', 'Moench', 'Gotthard']
for det in detectors:
with open(src/f'{det.lower()}DetectorServer/slsDetectorServer_defs.h') as f:
lines = f.read().replace('\\\n', '')
lines = lines.splitlines(keepends = True)
lines = [l.strip('#define').strip(' ') for l in lines if l.startswith('#define')]
output = []
signals = []
fields = ['Name,', 'Value', 'Comment']
excluded = ['DAC_NAMES', 'DEFAULT_DAC_VALS', 'CLK_NAMES', 'ONCHIP_DAC_NAMES']
header = f'{fields[0]:35}{fields[1]:35}\n'
output.append(header)
signals.append(header)
for line in lines:
name, *parts = line.split()
arg = ' '.join(parts)
value, *comments = arg.split('//')
value = value.strip('() ')
# value = value.replace(', ', ' ')
value = value.replace('\"', '')
if name not in excluded:
name += ','
if name.startswith('SIGNAL_'):
signals.append(f'{name:35}{value}\n')
else:
output.append(f'{name:35}\"{value}\"\n')
rstpath = Path('@CMAKE_SOURCE_DIR@')/'docs/src/'
with open(f'src/{det.lower()}.csv', 'w') as f:
f.writelines(output)