Skip to content

Commit

Permalink
Merge pull request #57 from marionleborgne/fix-publish-entrypoint
Browse files Browse the repository at this point in the history
Fix 'publish' positional argument on entrypoint
  • Loading branch information
jnaulty committed Sep 2, 2015
2 parents 7f9c7c4 + 7bae256 commit 47b6239
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 53 deletions.
97 changes: 56 additions & 41 deletions cloudbrain/publishers/sensor_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,63 @@
_SUPPORTED_DEVICES = get_supported_devices()


def parse_args():
parser = argparse.ArgumentParser()

parser.add_argument('-i', '--device_id', required=True,
help="A unique ID to identify the device you are sending data from. "
"For example: 'octopicorn2015'")
parser.add_argument('-m', '--mock', action='store_true', required=False,
help="Use this flag to generate mock data for a "
"supported device name %s" % _SUPPORTED_DEVICES)
parser.add_argument('-n', '--device_name', required=True,
help="The name of the device your are sending data from. "
"Supported devices are: %s" % _SUPPORTED_DEVICES)
parser.add_argument('-c', '--cloudbrain', default=RABBITMQ_ADDRESS,
help="The address of the CloudBrain instance you are sending data to, for pika publisher.\n"
"Use " + RABBITMQ_ADDRESS + " to send data to our hosted service. \n"
"Otherwise use 'localhost' if running CloudBrain locally")
parser.add_argument('-o', '--output', default=None,
help="The named pipe you are sending data to (e.g. /tmp/eeg_pipe), for pipe publisher.\n"
"The publisher will create the pipe.\n"
"By default this is the standard output.")

parser.add_argument('-b', '--buffer_size', default=10,
help='Size of the buffer ')
parser.add_argument('-p', '--device_port', help="Port used for OpenBCI Device.")

parser.add_argument('-P', '--publisher', default="pika",
help="The subscriber to use to get the data.\n"
"Possible options are pika, pipe.\n"
"The default is pika.")


opts = parser.parse_args()
if opts.device_name == "openbci" and opts.device_port is not None:
parser.error("You have to specify a port for the OpenBCI device!")
return opts
def validate_opts(opts):
"""
validate that we've got the right options
@param opts: (list) options to validate
@retun opts_valid: (bool) 1 if opts are valid. 0 otherwise.
"""
opts_valid = True
if (opts.device_name == "openbci") and (opts.device_port is None):
opts_valid = False
return opts_valid


def get_args_parser():
parser = argparse.ArgumentParser()

parser.add_argument('-i', '--device_id', required=True,
help="A unique ID to identify the device you are sending data from. "
"For example: 'octopicorn2015'")
parser.add_argument('-m', '--mock', action='store_true', required=False,
help="Use this flag to generate mock data for a "
"supported device name %s" % _SUPPORTED_DEVICES)
parser.add_argument('-n', '--device_name', required=True,
help="The name of the device your are sending data from. "
"Supported devices are: %s" % _SUPPORTED_DEVICES)
parser.add_argument('-c', '--cloudbrain', default=RABBITMQ_ADDRESS,
help="The address of the CloudBrain instance you are sending data to, for pika publisher.\n"
"Use " + RABBITMQ_ADDRESS + " to send data to our hosted service. \n"
"Otherwise use 'localhost' if running CloudBrain locally")
parser.add_argument('-o', '--output', default=None,
help="The named pipe you are sending data to (e.g. /tmp/eeg_pipe), for pipe publisher.\n"
"The publisher will create the pipe.\n"
"By default this is the standard output.")

parser.add_argument('-b', '--buffer_size', default=10,
help='Size of the buffer ')
parser.add_argument('-p', '--device_port', help="Port used for OpenBCI Device.")

parser.add_argument('-P', '--publisher', default="pika",
help="The subscriber to use to get the data.\n"
"Possible options are pika, pipe.\n"
"The default is pika.")

return parser


def get_opts():
parser = get_args_parser()
opts = parser.parse_args()
opts_valid = validate_opts(opts)
if not opts_valid:
parser.error("You have to speficy the OpenBCI port")
return opts


def main():
opts = parse_args()
opts = get_opts()
mock_data_enabled = opts.mock
device_name = opts.device_name
device_id = opts.device_id
Expand Down Expand Up @@ -84,7 +102,7 @@ def run(device_name='muse',
if mock_data_enabled:
from cloudbrain.connectors.MockConnector import MockConnector as Connector


if publisher_type not in ['pika', 'pipe']:
raise ValueError("'%s' is not a valid publisher type. Valid types are %s." % (publisher_type, "pika, pipe"))

Expand All @@ -93,7 +111,7 @@ def run(device_name='muse',
if publisher_type == 'pika':
publishers = {metric: PikaPublisher(device_name, device_id, cloudbrain_address, metric) for metric in metrics}
elif publisher_type == 'pipe':
publishers = {metric: PipePublisher(device_name, device_id, metric, pipe_name) for metric in metrics}
publishers = {metric: PipePublisher(device_name, device_id, metric, pipe_name) for metric in metrics}

for publisher in publishers.values():
publisher.connect()
Expand All @@ -116,6 +134,3 @@ def run(device_name='muse',
if __name__ == "__main__":
main()
#run('muse', False, 'marion', RABBITMQ_ADDRESS)



38 changes: 29 additions & 9 deletions cloudbrain/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,34 @@
import subprocess
import sys

import cloudbrain.publishers.sensor_publisher
from cloudbrain.publishers.sensor_publisher import get_args_parser, run

def publish(args):
sys.argv = args or ['-h']
cloudbrain.publishers.sensor_publisher.main()

def subscribe(args):
return NotImplemented
def publish(args):
parser = get_args_parser()

opts = parser.parse_args(args)

mock_data_enabled = opts.mock
device_name = opts.device_name
device_id = opts.device_id
cloudbrain_address = opts.cloudbrain
buffer_size = opts.buffer_size
device_port = opts.device_port
pipe_name = opts.output
publisher = opts.publisher

run(device_name,
mock_data_enabled,
device_id,
cloudbrain_address,
buffer_size,
device_port,
pipe_name,
publisher)

def subscribe():
raise NotImplemented("Subscribe is not implemented")

def parse_args():
parser = argparse.ArgumentParser()
Expand All @@ -23,11 +43,11 @@ def parse_args():
help="Subscribe to data stream - For example: cloudbrain subscribe -n muse -i octopicorn")
subscribe_parser.set_defaults(func=subscribe)

args, unknown = parser.parse_known_args()
args.func(unknown)
args, remaining_args = parser.parse_known_args()
args.func(remaining_args)

def main():
parse_args()
parse_args()

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-e [email protected]:marionleborgne/cloudbrain.git@01629005fda226b36dfe8d91f97cb821c72b739a#egg=cloudbrain-make-buildable
pika==0.9.14
pyliblo==0.9.2
pyserial==2.7
wheel==0.24.0
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def read(fname):


setup(name="cloudbrain",
version="0.2.0",
version="0.2.1",
description="Platform for real-time sensor data analysis and visualization.",
packages=find_packages(),
install_requires=['pika', 'pyliblo'],
install_requires=['pika', 'pyliblo', 'pyserial'],
include_package_data=True,
long_description=read("README.md"),
license='GNU Affero General Public License v3',
Expand Down

0 comments on commit 47b6239

Please sign in to comment.