1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#!/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
import sys
__author__ = 'simon.marchi@polymtl.ca (Simon Marchi)'
wrapper = None
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('Error: %s' % status.message, file=sys.stderr)
wrapper.Stop()
def main():
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
global wrapper
wrapper = ClientWrapper()
client = wrapper.Client()
client.PatchPort(device, port, is_output, action, universe, PatchPortCallback)
wrapper.Run()
if __name__ == '__main__':
main()
|