Skip to content

Commit

Permalink
Make stack.process available for import
Browse files Browse the repository at this point in the history
  • Loading branch information
jooste committed Jan 15, 2025
1 parent 33aea81 commit 8bea773
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
9 changes: 8 additions & 1 deletion bluesky/stack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
from bluesky.stack.stackbase import stack, forward, sender, get_scenname, get_scendata, set_scendata
from bluesky.stack.cmdparser import command, commandgroup, append_commands, \
remove_commands, get_commands
from bluesky.stack.argparser import refdata, ArgumentError
from bluesky.stack.argparser import ArgumentError


def process(ext_cmds):
''' Dummy process that will get replaced by sim or client implementation during init. '''
pass


def init(mode='client'):
if mode[:3] == 'sim':
import bluesky.stack.simstack as simstack
from bluesky.stack.importer import Importer
simstack.init()
globals()['process'] = simstack.process
else:
import bluesky.stack.clientstack as clientstack
clientstack.init()
globals()['process'] = clientstack.process
12 changes: 5 additions & 7 deletions bluesky/stack/simstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,16 @@ def reset():

# Close recording file and reset scenario recording settings
recorder.reset()
# Reset parser reference values
argparser.reset()


def process(from_pcall=None):
def process(ext_cmds=None):
''' Sim-side stack processing. '''
# First check for commands in scenario file
if from_pcall is None:
# If no commands are passed, check for commands in scenario file
if ext_cmds is None:
checkscen()

# Process stack of commands
for cmdline in Stack.commands(from_pcall):
for cmdline in Stack.commands(ext_cmds):
success = True
echotext = ''
echoflags = bs.BS_OK
Expand Down Expand Up @@ -127,7 +125,7 @@ def process(from_pcall=None):
bs.scr.echo(echotext, echoflags)

# Clear the processed commands
if from_pcall is None:
if ext_cmds is None:
Stack.clear()


Expand Down
12 changes: 9 additions & 3 deletions bluesky/stack/stackbase.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
''' BlueSky Stack base data and functions. '''
from itertools import repeat

import bluesky as bs
from bluesky.network import subscriber, context as ctx
from bluesky.stack.cmdparser import command
Expand Down Expand Up @@ -30,10 +32,14 @@ def reset(cls):
cls.sender_id = None

@classmethod
def commands(cls, from_pcall=None):
def commands(cls, ext_cmds=None):
''' Generator function to iterate over stack commands. '''
# Return commands from PCALL if passed, otherwise own command stack
for cls.current, cls.sender_id in from_pcall or cls.cmdstack:
# Return explicitly passed commands if given, otherwise own command stack
if isinstance(ext_cmds, str):
# If argument is a single string convert it to an appropriate list
ext_cmds = zip(ext_cmds.split(';'), repeat(cls.sender_id))

for cls.current, cls.sender_id in ext_cmds or cls.cmdstack:
yield cls.current
# After processing commands, current command and sender id should be reset
cls.current = ''
Expand Down

0 comments on commit 8bea773

Please sign in to comment.