forked from NSLS-II-LIX/lixdc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request NSLS-II-LIX#4 from hhslepicka/master
Bug fixes. Added configuration file for services connection and others
- Loading branch information
Showing
13 changed files
with
184 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
# lixdc | ||
User interface for data collection at LIX beam line. | ||
|
||
|
||
## lixdc configuration | ||
|
||
Lixdc requires the following configuration information: | ||
|
||
``` | ||
amostra_host: localhost | ||
amostra_port: 7772 | ||
base_path: /Users/hugoslepicka/data | ||
``` | ||
|
||
|
||
This configuration information can live in up to four different places, as | ||
defined in the docstring of the `load_configuration` function in | ||
`lixdc/conf.py`. In order of increasing precedence: | ||
|
||
1. The conda environment | ||
- CONDA_ENV/etc/{name}.yaml (if CONDA_ETC_env is defined) | ||
1. At the system level | ||
- /etc/{name}.yml | ||
1. In the user's home directory | ||
- ~/.config/{name}/connection.yml | ||
1. Environmental variables | ||
- {PREFIX}_{FIELD} | ||
|
||
where | ||
|
||
- {name} is lixdc | ||
- {PREFIX} is LIXDC and {FIELD} is one of {amostra_host, amostra_port, base_path} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# no yaml, just python or command line for now | ||
import os | ||
import yaml | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def load_configuration(name, prefix, fields, allow_missing=False): | ||
""" | ||
Load configuration data form a cascading series of locations. | ||
The precedence order is (highest priority last): | ||
1. CONDA_ENV/etc/{name}.yaml (if CONDA_ETC_ env is defined) | ||
2. /etc/{name}.yml | ||
3. ~/.config/{name}/connection.yml | ||
4. reading {PREFIX}_{FIELD} environmental variables | ||
Parameters | ||
---------- | ||
name : str | ||
The expected base-name of the configuration files | ||
prefix : str | ||
The prefix when looking for environmental variables | ||
fields : iterable of strings | ||
The required configuration fields | ||
Returns | ||
------ | ||
conf : dict | ||
Dictionary keyed on ``fields`` with the values extracted | ||
""" | ||
filenames = [os.path.join('/etc', name + '.yml'), | ||
os.path.join(os.path.expanduser('~'), '.config', | ||
name, 'connection.yml'), | ||
] | ||
if 'CONDA_ETC_' in os.environ: | ||
filenames.insert(0, os.path.join(os.environ['CONDA_ETC_'], | ||
name + '.yml')) | ||
|
||
config = {} | ||
for filename in filenames: | ||
if os.path.isfile(filename): | ||
with open(filename) as f: | ||
config.update(yaml.load(f)) | ||
logger.debug("Using db connection specified in config file. \n%r", | ||
config) | ||
|
||
for field in fields: | ||
var_name = prefix + '_' + field.upper().replace(' ', '_') | ||
config[field] = os.environ.get(var_name, config.get(field, None)) | ||
|
||
missing = [k for k, v in config.items() if v is None] | ||
if not allow_missing and missing: | ||
raise KeyError("The configuration field(s) {0} were not found in any " | ||
"file or environmental variable.".format(missing)) | ||
return config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
class State(): | ||
def __init__(self): | ||
self.user = None | ||
self.project = None | ||
self.proposal_id = None | ||
self.run_id = None | ||
self.beamline_id = "LIX" | ||
self.login_timestamp = None | ||
self.configs = None | ||
|
||
def __str__(self): | ||
return "User: {}, Project: {}, Beamline: {}, Login Timestamp: {}".format(self.user, self.project, self.beamline_id, self.login_timestamp) | ||
return "User: {}, Proposal: {}, Beamline: {}, Login Timestamp: {}".format(self.user, self.proposal_id, self.beamline_id, self.login_timestamp) | ||
|
||
def get_default_fields(self): | ||
return {'owner': self.user, 'project': self.project, 'beamline_id': | ||
self.beamline_id} | ||
return {'owner': self.user, 'proposal_id': self.proposal_id, 'beamline_id': | ||
self.beamline_id, 'run_id': self.run_id} | ||
|
||
def get_user_path(self): | ||
return "{}/{}/{}/".format(self.configs['base_path'], self.proposal_id, | ||
self.run_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.