Skip to content

Commit

Permalink
TST #333 refactor so testable
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Jul 7, 2020
1 parent 4d25731 commit 09f9d2d
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions apstools/beamtime/bss_info_makedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,35 +135,43 @@
proposal:user9:userId stringout
""".strip().splitlines()

print("""\
#
# file: bss_info.db
# EPICS database for information from APS ESAF & Proposal databases
#
# BSS: Beamtime Scheduling System
#
# note: this file autogenerated by make_database.py
# ./bss_info_makedb.py | tee bss_info.db
#
# Start the EPICS IOC with a command (from EPICS base):
# softIoc -m P=ioc:bss: -d bss_info.db
""")

for row in raw_data:
parts = row.split()
pvname, rtyp = parts[:2]
head = f'record({rtyp}, "$(P){pvname}")'
fields = []
if rtyp == "waveform" and len(parts) == 3:
length = parts[-1]
fields.append(f'field(FTVL, "CHAR")')
fields.append(f'field(NELM, {length})')
elif rtyp == "bo":
fields.append(f'field(ZNAM, "OFF")')
fields.append(f'field(ONAM, "ON")')
record = head
newline = "\n"
if len(fields) > 0:
field_specs = "\n".join([f" {field}" for field in fields])
record += " {\n" + f"{field_specs}" + "\n}"
print("\n" + record)
def main():
header = """\
#
# file: bss_info.db
# EPICS database for information from APS ESAF & Proposal databases
#
# BSS: Beamtime Scheduling System
#
# note: this file autogenerated by make_database.py
# ./bss_info_makedb.py | tee bss_info.db
#
# Start the EPICS IOC with a command (from EPICS base):
# softIoc -m P=ioc:bss: -d bss_info.db
"""
for line in header.splitlines():
print(line.strip())

for row in raw_data:
parts = row.split()
pvname, rtyp = parts[:2]
head = f'record({rtyp}, "$(P){pvname}")'
fields = []
if rtyp == "waveform" and len(parts) == 3:
length = parts[-1]
fields.append(f'field(FTVL, "CHAR")')
fields.append(f'field(NELM, {length})')
elif rtyp == "bo":
fields.append(f'field(ZNAM, "OFF")')
fields.append(f'field(ONAM, "ON")')
record = head
newline = "\n"
if len(fields) > 0:
field_specs = "\n".join([f" {field}" for field in fields])
record += " {\n" + f"{field_specs}" + "\n}"
print("\n" + record)


if __name__ == "__main__":
main()

0 comments on commit 09f9d2d

Please sign in to comment.