mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-11 04:17:15 +02:00
added defines for python (#498)
This commit is contained in:
@ -11,7 +11,7 @@ enums.cpp
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
from parse import remove_comments
|
||||
from parse import remove_comments, remove_ifdefs
|
||||
|
||||
|
||||
allow_bitwise_op = ["streamingInterface", "M3_GainCaps"]
|
||||
@ -98,25 +98,25 @@ def generate_enum_string(enums):
|
||||
return ''.join(data)
|
||||
|
||||
|
||||
def remove_ifdefs(lines):
|
||||
"""Keeps C++ version of the code"""
|
||||
out = []
|
||||
it = iter(lines)
|
||||
skip = False
|
||||
for line in it:
|
||||
# def remove_ifdefs(lines):
|
||||
# """Keeps C++ version of the code"""
|
||||
# out = []
|
||||
# it = iter(lines)
|
||||
# skip = False
|
||||
# for line in it:
|
||||
|
||||
if "#ifdef __cplusplus" in line:
|
||||
line = next(it)
|
||||
# if "#ifdef __cplusplus" in line:
|
||||
# line = next(it)
|
||||
|
||||
if "#else" in line:
|
||||
skip = True
|
||||
# if "#else" in line:
|
||||
# skip = True
|
||||
|
||||
if "#endif" in line:
|
||||
skip = False
|
||||
# if "#endif" in line:
|
||||
# skip = False
|
||||
|
||||
if not skip and "#endif" not in line:
|
||||
out.append(line)
|
||||
return out
|
||||
# if not skip and "#endif" not in line:
|
||||
# out.append(line)
|
||||
# return out
|
||||
|
||||
|
||||
with open('../../slsSupportLib/include/sls/sls_detector_defs.h') as f:
|
||||
|
30
python/scripts/generate_pydef.py
Normal file
30
python/scripts/generate_pydef.py
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
from parse import remove_comments, remove_ifdefs
|
||||
|
||||
with open('../../slsSupportLib/include/sls/sls_detector_defs.h') as f:
|
||||
data = f.read()
|
||||
|
||||
data = remove_comments(data)
|
||||
data = data.splitlines()
|
||||
# data = remove_ifdefs(data)
|
||||
|
||||
|
||||
ignore = ['#define MYROOT', '#define __cplusplus']
|
||||
|
||||
defines = {}
|
||||
for i, line in enumerate(data):
|
||||
if line.startswith('#define') and line not in ignore:
|
||||
_, name, value = line.split(maxsplit = 2)
|
||||
print(f'{name}={value}')
|
||||
defines[name]=value
|
||||
|
||||
|
||||
warning = '#WARINING This file is auto generated any edits might be overwritten without warning\n\n'
|
||||
with open('../slsdet/defines.py', 'w') as f:
|
||||
f.write(warning)
|
||||
for key, value in defines.items():
|
||||
f.write(f'{key}={value}\n')
|
@ -25,7 +25,25 @@ def remove_comments(text):
|
||||
)
|
||||
return re.sub(pattern, replacer, text)
|
||||
|
||||
def remove_ifdefs(lines):
|
||||
"""Keeps C++ version of the code"""
|
||||
out = []
|
||||
it = iter(lines)
|
||||
skip = False
|
||||
for line in it:
|
||||
|
||||
if "#ifdef __cplusplus" in line:
|
||||
line = next(it)
|
||||
|
||||
if "#else" in line:
|
||||
skip = True
|
||||
|
||||
if "#endif" in line:
|
||||
skip = False
|
||||
|
||||
if not skip and "#endif" not in line:
|
||||
out.append(line)
|
||||
return out
|
||||
|
||||
|
||||
#based on ccsyspath: https://github.com/AndrewWalker/ccsyspath
|
||||
|
Reference in New Issue
Block a user