-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove most use of literal lists of simulators. #200
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""Information about hardware supported by Panoptes.""" | ||
|
||
ALL_NAMES = sorted(['camera', 'dome', 'mount', 'night', 'weather']) | ||
|
||
|
||
def GetAllNames(all_names=ALL_NAMES, without=None): | ||
""" | ||
""" | ||
if without: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you change the default to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
return [v for v in all_names if v not in without] | ||
return list(all_names) | ||
|
||
|
||
def GetSimulatorNames(simulator=None, kwargs=None, config=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
"""Returns the names of the simulators to be used in lieu of hardware drivers. | ||
|
||
Note that returning a list containing 'X' doesn't mean that the config calls for a driver | ||
of type 'X'; that is up to the code working with the config to create drivers for real or | ||
simulated hardware. | ||
|
||
This funciton is intended to be called from PanBase or similar, which receives kwargs that | ||
may include simulator, config or both. For example: | ||
GetSimulatorNames(config=self.config, kwargs=kwargs) | ||
Or: | ||
GetSimulatorNames(simulator=simulator, config=self.config) | ||
|
||
The reason this function doesn't just take **kwargs as its sole arg is that we need to allow | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't doubt this is true but seems odd. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Annoying but true. |
||
for the case where the caller is passing in simulator (or config) twice, once on its own, | ||
and once in the kwargs (which won't be examined). Python doesn't permit a keyword argument | ||
to be passed in twice. | ||
|
||
Args: | ||
simulator: | ||
An explicit list of names of hardware to be simulated (i.e. hardware drivers | ||
to be replaced with simulators). | ||
kwargs: | ||
The kwargs passed in to the caller, which is inspected for an arg called 'simulator'. | ||
config: | ||
Dictionary created from pocs.yaml or similar. | ||
|
||
Returns: | ||
List of names of the hardware to be simulated. | ||
""" | ||
def ExtractSimulator(d): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if d: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I keep meaning to mention this in other places, but the more pythonic way (EAFP) would be to:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I decided on yet another approach. |
||
return d.get('simulator') | ||
return None | ||
for simulator in [simulator, ExtractSimulator(kwargs), ExtractSimulator(config)]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems odd to reuse There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed... and what a stupid idea! Clearly a sign that I added the simulator kwarg after deciding that the for loop variable would be called simulator. |
||
if not simulator: | ||
continue | ||
if isinstance(simulator, str): | ||
simulator = [simulator] | ||
if 'all' in simulator: | ||
return GetAllNames() | ||
else: | ||
return sorted(simulator) | ||
return [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from pocs import hardware | ||
from pocs import POCS | ||
|
||
pocs = POCS(simulator=['camera', 'weather']) | ||
pocs = POCS(simulator=hardware.GetAllNames(without=['mount', 'night'])) | ||
pocs.observatory.mount.initialize() | ||
pocs.observatory.mount.home_and_park() | ||
pocs.power_down() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_all_names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.