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

Add a patch/unpatch example for the Python API #671

Merged
merged 4 commits into from
Mar 15, 2015
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
1 change: 1 addition & 0 deletions python/examples/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
dist_noinst_SCRIPTS += \
python/examples/ola_artnet_params.py \
python/examples/ola_devices.py \
python/examples/ola_patch_unpatch.py \
python/examples/ola_plugin_info.py \
python/examples/ola_rdm_discover.py \
python/examples/ola_rdm_get.py \
Expand Down
72 changes: 72 additions & 0 deletions python/examples/ola_patch_unpatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# ola_patch_unpatch.py
# Copyright (C) 2015 Simon Marchi

"""Patch and unpatch ports."""

from __future__ import print_function
from ola.ClientWrapper import ClientWrapper
from ola.OlaClient import OlaClient
import argparse

__author__ = 'simon.marchi@polymtl.ca (Simon Marchi)'


def ParseArgs():
description = 'Patch or unpatch an OLA port.'
argparser = argparse.ArgumentParser(description=description)
argparser.add_argument('--device', '-d',
metavar='DEV',
type=int,
required=True)
argparser.add_argument('--port', '-p',
metavar='PORT',
type=int,
required=True)
argparser.add_argument('--universe', '-u',
metavar='UNI',
type=int,
required=True)
argparser.add_argument('--mode', '-m',
choices=['input', 'output'],
required=True)
argparser.add_argument('--action', '-a',
choices=['patch', 'unpatch'],
required=True)

return argparser.parse_args()


def PatchPortCallback(status):
if status.Succeeded():
print('Success!')
else:
print('Oops: {}'.format(status.message))
wrapper.Stop()

args = ParseArgs()

device = args.device
port = args.port
is_output = args.mode == 'output'
action = OlaClient.PATCH if args.action == 'patch' else OlaClient.UNPATCH
universe = args.universe

wrapper = ClientWrapper()
client = wrapper.Client()
client.PatchPort(device, port, is_output, action, universe, PatchPortCallback)
wrapper.Run()
2 changes: 1 addition & 1 deletion python/ola/OlaClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def PatchPort(self, device_alias, port, is_output, action, universe,
device_alias: the alias of the device of which to patch a port
port: the id of the port
is_output: select the input or output port
action: OlaClient.PATCH or OlcClient.UNPATCH
action: OlaClient.PATCH or OlaClient.UNPATCH
universe: the universe to set the name of
callback: The function to call once complete, takes one argument, a
RequestStatus object.
Expand Down