Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #57 from psyfood/assume_default_config_directory
Browse files Browse the repository at this point in the history
Assume default location of Qmix configuration.
  • Loading branch information
hoechenberger authored Oct 8, 2018
2 parents 53195fc + 73c9026 commit beda10e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2018-10-06
----------
* Assume default location of Qmix configuration files (to avoid full path).

2018-10-04
----------
* Rename `switch_valve_when_finished` keyword argument to
Expand Down
4 changes: 2 additions & 2 deletions pyqmix/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def __init__(self, auto_open=True, auto_start=True):
if config_dir is not None:
self.config_dir = config_dir
else:
msg = ('Please specify the Qmix configuration directory via '
'pyqmix.config.set_qmix_config_dir() first.')
msg = ('Please specify the Qmix configuration via '
'pyqmix.config.set_qmix_config() first.')
raise RuntimeError(msg)

self.auto_open = auto_open
Expand Down
66 changes: 60 additions & 6 deletions pyqmix/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
PYQMIX_CONFIG_DIR = user_config_dir(appname='pyqmix', appauthor=False)
PYQMIX_CONFIG_FILE = os.path.join(PYQMIX_CONFIG_DIR, 'config.yaml')

DEFAULT_CONFIGS_DIR = os.path.normpath('C:/Users/Public/Documents/'
'QmixElements/Projects/default_project/'
'Configurations')

# Python 2 compatibility
try:
Expand Down Expand Up @@ -63,18 +66,69 @@ def delete_config():
pass


def set_qmix_config_dir(d):
def get_available_qmix_configs(configs_dir=None):
"""
Specify the location of the directory containing the Qmix configurations.
Create a list of available qmix configurations
Parameters
----------
d : string
The Qmix configuration directory. Must be an absolute path.
configs_dir : string or None
The parent directory containing the Qmix configurations.
If ``None``, assume the default directory used by
Qmix Elements, i.e.,
`C:/Users/Public/Documents/QmixElements/Projects/default_project/Configurations/`.
Returns
-------
list of strings
Names of available Qmix configurations.
"""
if configs_dir is None:
configs_dir = DEFAULT_CONFIGS_DIR

def get_immediate_subdirectories(a_dir):
return [name for name in os.listdir(a_dir)
if os.path.isdir(os.path.join(a_dir, name))]

return get_immediate_subdirectories(configs_dir)


def set_qmix_config(config_name, configs_dir=None):
"""
Specify a Qmix configuration.
Parameters
----------
config_name : string
The name of a Qmix configuration. Assumed to be stored at the default directory.
configs_dir : string or None
The parent directory containing the Qmix configurations.
If ``None``, we will look for the Qmix configuration in the current
directory; if not found, move on to look in the Qmix default
directory.
Raises
------
ValueError
If the specified configuration could not be found.
"""

if configs_dir is None:
if os.path.exists(config_name):
configs_dir = os.path.abspath('.')
else:
configs_dir = DEFAULT_CONFIGS_DIR

config_dir = os.path.join(configs_dir, config_name)

if not os.path.exists(config_dir):
msg = 'The specified configuration does not exist: %s' % config_dir
raise ValueError(msg)

cfg = read_config()
cfg['qmix_config_dir'] = d
cfg['qmix_config_dir'] = config_dir

with open(PYQMIX_CONFIG_FILE, 'w') as f:
yaml.dump(cfg, f)
Expand All @@ -87,7 +141,7 @@ def set_qmix_dll_dir(d):
Parameters
----------
d : string
Th Qmix SDK DLL directory. Must be an absolute path.
The Qmix SDK DLL directory. Must be an absolute path.
"""
cfg = read_config()
Expand Down
5 changes: 3 additions & 2 deletions pyqmix/examples/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
import time

# Location of Qmix device configuration and Qmix SDK DLLs.
config_dir = op.abspath('./qmix_config')
configs_dir = op.abspath('./')
config_name = 'qmix_config'
dll_dir = op.normpath('D:/QmixSDK')

config.set_qmix_config_dir(config_dir)
config.set_qmix_config(config_name=config_name, configs_dir=configs_dir)
config.set_qmix_dll_dir(dll_dir)

# Initialize the connection to the pump system.
Expand Down
5 changes: 3 additions & 2 deletions pyqmix/examples/two_pumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

# Location of Qmix device configuration and Qmix SDK DLLs.
# Adjust as needed.
config_dir = op.abspath('./qmix_config')
configs_dir = op.abspath('./')
config_name = 'qmix_config'
dll_dir = op.normpath('D:/QmixSDK')

config.set_qmix_config_dir(config_dir)
config.set_qmix_config(config_name=config_name, configs_dir=configs_dir)
config.set_qmix_dll_dir(dll_dir)

# Flow and volume units and dimensions of the syringes.
Expand Down

0 comments on commit beda10e

Please sign in to comment.