Skip to content
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

spec2ophyd: config file as command-line argument #368

Merged
merged 3 commits into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions apstools/migration/spec2ophyd.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@
output of ophyd configuration to stdout

*new in apstools release 1.1.7*

**USAGE**

.. code-block:: bash

user@host ~ $ ./spec2ophyd.py
usage: spec2ophyd.py [-h] [-v] configFileName
spec2ophyd.py: error: the following arguments are required: configFileName

user@host ~ $ ./spec2ophyd.py -h
usage: spec2ophyd.py [-h] [-v] configFileName

read SPEC config file and convert to ophyd setup commands

positional arguments:
configFileName SPEC config file name

optional arguments:
-h, --help show this help message and exit
-v, --version print version number and exit

"""


Expand Down Expand Up @@ -222,7 +243,6 @@ def ophyd_config(self):
return s



class SpecCounter(ItemNameBase):
"""
SPEC configuration of a counter channel
Expand Down Expand Up @@ -372,8 +392,37 @@ def create_ophyd_setup(spec_config):
print(f"{device.ophyd_config()}")


def get_options():
"""Handle command line arguments."""
import argparse
import os
import sys
from apstools._version import get_versions

version = get_versions()['version']

parser = argparse.ArgumentParser(
prog=os.path.split(sys.argv[0])[-1],
description=__doc__.strip().splitlines()[0],
)

parser.add_argument('-v',
'--version',
action='version',
help='print version number and exit',
version=version)

parser.add_argument(
'configFileName',
type=str,
help="SPEC config file name")

return parser.parse_args()


def main():
spec_cfg = SpecConfig(CONFIG_FILE)
args = get_options()
spec_cfg = SpecConfig(args.configFileName)
spec_cfg.read_config()
create_ophyd_setup(spec_cfg)

Expand Down
8 changes: 4 additions & 4 deletions docs/source/applications/spec2ophyd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ spec2ophyd
Read SPEC config file and convert to ophyd setup commands.

This is a tool to help migration from SPEC to bluesky. It reads
a SPEC configuration file named `config`
*in the present working directory*
the SPEC configuration file provided on the comand line
and converts the lines it recognizes into ophyd
commands which create ophyd objects. These commands are printed
to `sys.stdout`. The output can be copied into a setup file for ophyd.
Expand Down Expand Up @@ -75,9 +74,11 @@ SPEC config file
command line
~~~~~~~~~~~~

Translate the SPEC config file in the present directory:

.. code-block:: bash

spec2ophyd
spec2ophyd ./config


output
Expand Down Expand Up @@ -112,7 +113,6 @@ Cautions
* *spec2ophyd* is a work-in-progress.
* *spec2ophyd* does not rely on any libraries of *apstools*
* It is not necessarily robust
* There is no command line help for this utility.
* It is not packaged or installed with the apstools.
* It is only available from the source code repository.
* It may be refactored or removed at any time.
Expand Down