Skip to content

Commit

Permalink
Added option for config filename
Browse files Browse the repository at this point in the history
  • Loading branch information
tdiethe committed Nov 6, 2017
1 parent 501b746 commit 0b1a061
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ output/
.Rhistory
docs_tmp
venv3
.idea/
6 changes: 3 additions & 3 deletions hyperstream/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ def __init__(self, interval, sleep=5, iterations=100, alarm=None):

class HyperStreamConfig(Printable):
"""
Wrapper around the hyperstream configuration file (hyperstream_config.json)
Wrapper around the hyperstream configuration file
"""
def __init__(self):
def __init__(self, filename="hyperstream_config.json"):
"""
Initialise the configuration - currently uses fixed file name (hyperstream_config.json)
"""
self.mongo = None

try:
with open('hyperstream_config.json', 'r') as f:
with open(filename, 'r') as f:
logging.getLogger("hyperstream")
logging.info('Reading ' + os.path.abspath(f.name))
config = json.load(f)
Expand Down
7 changes: 5 additions & 2 deletions hyperstream/hyperstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class HyperStream(object):
For py2k/py3k compatability we use the six decorator add_metaclass:
https://pythonhosted.org/six/#six.add_metaclass
"""
def __init__(self, loglevel=logging.INFO, file_logger=True, console_logger=True, mqtt_logger=None):
def __init__(self, loglevel=logging.INFO, file_logger=True, console_logger=True, mqtt_logger=None,
config_filename="hyperstream_config.json"):
"""
Initialise the HyperStream class. This starts the logger, loads the config files, connects to the main mongodb,
and initialises the managers (channels, plates, workflows).
Expand All @@ -61,7 +62,9 @@ def __init__(self, loglevel=logging.INFO, file_logger=True, console_logger=True,
:param console_logger: The console logger. Either specify "True" in which case defaults are used,
otherwise a dict optionally containing loglevel
:param mqtt_logger: Dict containing mqtt server, topic, and optionally loglevel
:param config_filename: Configuration file
"""
self.config_filename = config_filename
self._session = None

self.parameters = dict(
Expand All @@ -73,7 +76,7 @@ def __init__(self, loglevel=logging.INFO, file_logger=True, console_logger=True,

self.logger = HyperStreamLogger(
default_loglevel=loglevel, file_logger=file_logger, console_logger=console_logger, mqtt_logger=mqtt_logger)
self.config = HyperStreamConfig()
self.config = HyperStreamConfig(filename=config_filename)
self.client = Client(self.config.mongo)

# Define some managers
Expand Down

0 comments on commit 0b1a061

Please sign in to comment.