diff --git a/.travis-ci.sh b/.travis-ci.sh index d9f6708c7f..5e97ef1b05 100755 --- a/.travis-ci.sh +++ b/.travis-ci.sh @@ -99,7 +99,7 @@ elif [[ $TASK = 'flake8' ]]; then # the following is a bit of a hack to build the files normally built during # the build, so they are present for flake8 to run against make builtfiles - flake8 --max-line-length 80 --exclude *_pb2.py,.git,__pycache --ignore E111,E121,E127,E129 data/rdm include/ola python scripts tools/ola_mon tools/rdm + flake8 --max-line-length 80 --exclude *_pb2.py,.git,__pycache --ignore E111,E114,E121,E127,E129 data/rdm include/ola python scripts tools/ola_mon tools/rdm else # Otherwise compile and check as normal export DISTCHECK_CONFIGURE_FLAGS='--enable-rdm-tests --enable-ja-rule' diff --git a/NEWS b/NEWS index 47d7e15830..e3ed4842b5 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,19 @@ +x/y/2016 ola-0.10.1 + Features: + * + + API: + * + + RDM Tests: + * + + Bugs: + * Check if a device exists before trying to acquire a UUCP lock file for it #1006 + + Internal: + * + 3/1/2016 ola-0.10.0 Features: * Add better logging for open() diff --git a/README.developer b/README.developer index 99dada2b4f..c45901e472 100644 --- a/README.developer +++ b/README.developer @@ -49,14 +49,15 @@ root ola directory is guaranteed to work). Branches, Versioning & Releases ------------------------------- -Version numbers take the form MAJOR.MINOR.PATCH. The release lifecycle is: +Version numbers take the form MAJOR.MINOR.PATCH based on http://semver.org/. +The release lifecycle is: - New feature work occurs on the master branch. - Once the new features are considered stable or enough time has passed, a new - minor release branch will be created, e.g. 0.9. + minor release branch will be created, e.g. 0.10. - The minor release branch will be stablized with bugfixes, these bug fixes will also be merged back into master. -- Once declared stable, a new patch branch 0 will be created e.g. 0.9.0 +- Once declared stable, a new patch branch 0 will be created e.g. 0.10.0 - Release specific changes like the version number, debian files etc. will be pushed to the patch branch. - The release will occur. diff --git a/common/io/Serial.cpp b/common/io/Serial.cpp index dd70953428..8edbb592f1 100644 --- a/common/io/Serial.cpp +++ b/common/io/Serial.cpp @@ -22,8 +22,8 @@ #include #include #include -#ifdef _WIN32 #include +#ifdef _WIN32 #include #include #else @@ -143,7 +143,14 @@ bool AcquireUUCPLockAndOpen(const std::string &path, int oflag, int *fd) { // If it was only a single process doing the locking we could use fnctl as // described in 55.6 of the Linux Programing Interface book. - // First, clean up a stale lockfile. + // First, check if the path exists, there's no point trying to open it if not + if (!FileExists(path)) { + OLA_INFO << "Device " << path << " doesn't exist, so there's no point " + "trying to acquire a lock"; + return false; + } + + // Second, clean up a stale lockfile. const string lock_file = GetLockFile(path); OLA_DEBUG << "Checking for " << lock_file; pid_t locked_pid; diff --git a/common/network/IPV4Address.cpp b/common/network/IPV4Address.cpp index f5706aafb7..0254c4edef 100644 --- a/common/network/IPV4Address.cpp +++ b/common/network/IPV4Address.cpp @@ -29,6 +29,9 @@ #endif #endif +#ifdef HAVE_SYS_SOCKET_H +#include // Required by FreeBSD +#endif #ifdef HAVE_ARPA_INET_H #include #endif diff --git a/common/network/NetworkUtils.cpp b/common/network/NetworkUtils.cpp index dc1d166a5d..38f1993b28 100644 --- a/common/network/NetworkUtils.cpp +++ b/common/network/NetworkUtils.cpp @@ -55,6 +55,7 @@ typedef uint32_t in_addr_t; // Do something else if we don't have Netlink/on Windows #endif +#include #include #include #include diff --git a/data/rdm/PidDataTest.py b/data/rdm/PidDataTest.py index 6499e25afc..138ba73aa9 100755 --- a/data/rdm/PidDataTest.py +++ b/data/rdm/PidDataTest.py @@ -18,12 +18,12 @@ """Test to check we can load the Pid data in Python.""" -__author__ = 'nomis52@gmail.com (Simon Newton)' - import os import unittest from ola import PidStore +__author__ = 'nomis52@gmail.com (Simon Newton)' + class PidDataTest(unittest.TestCase): # Implement assertIsNotNone for Python runtimes < 2.7 or < 3.1 diff --git a/plugins/spi/SPIWriter.cpp b/plugins/spi/SPIWriter.cpp index 36b66c5423..b50e5dc0ae 100644 --- a/plugins/spi/SPIWriter.cpp +++ b/plugins/spi/SPIWriter.cpp @@ -18,6 +18,7 @@ * Copyright (C) 2013 Simon Newton */ +#include #include #include #include diff --git a/python/examples/ola_artnet_params.py b/python/examples/ola_artnet_params.py index 49823b064a..dc7b401f0a 100755 --- a/python/examples/ola_artnet_params.py +++ b/python/examples/ola_artnet_params.py @@ -18,27 +18,40 @@ """Fetch some ArtNet parameters.""" -__author__ = 'nomis52@gmail.com (Simon Newton)' - +from __future__ import print_function from ola.ClientWrapper import ClientWrapper from ola import ArtNetConfigMessages_pb2 +import sys + +__author__ = 'nomis52@gmail.com (Simon Newton)' + + +def ArtNetConfigureReply(status, response): + if status.Succeeded(): + reply = ArtNetConfigMessages_pb2.Reply() + reply.ParseFromString(response) + print('Short Name: %s' % reply.options.short_name) + print('Long Name: %s' % reply.options.long_name) + print('Subnet: %d' % reply.options.subnet) + else: + print('Error: %s' % status.message, file=sys.stderr) + + global wrapper + if wrapper: + wrapper.Stop() + +def main(): + # Set this appropriately + device_alias = 1 + global wrapper + wrapper = ClientWrapper() + client = wrapper.Client() + artnet_request = ArtNetConfigMessages_pb2.Request() + artnet_request.type = artnet_request.ARTNET_OPTIONS_REQUEST + client.ConfigureDevice(device_alias, artnet_request.SerializeToString(), + ArtNetConfigureReply) + wrapper.Run() -def ArtNetConfigureReply(state, response): - reply = ArtNetConfigMessages_pb2.Reply() - reply.ParseFromString(response) - print('Short Name: %s' % reply.options.short_name) - print('Long Name: %s' % reply.options.long_name) - print('Subnet: %d' % reply.options.subnet) - wrapper.Stop() - - -# Set this appropriately -device_alias = 1 -wrapper = ClientWrapper() -client = wrapper.Client() -artnet_request = ArtNetConfigMessages_pb2.Request() -artnet_request.type = artnet_request.ARTNET_OPTIONS_REQUEST -client.ConfigureDevice(device_alias, artnet_request.SerializeToString(), - ArtNetConfigureReply) -wrapper.Run() +if __name__ == '__main__': + main() diff --git a/python/examples/ola_candidate_ports.py b/python/examples/ola_candidate_ports.py index dd2050c2f9..99337634a1 100755 --- a/python/examples/ola_candidate_ports.py +++ b/python/examples/ola_candidate_ports.py @@ -50,8 +50,7 @@ def GetCandidatePortsCallback(status, devices): '{p.supports_rdm}' print(s.format(p=port)) else: - print('Error: {}'.format(status.message), file=sys.stderr) - wrapper.Stop() + print('Error: %s' % status.message, file=sys.stderr) args = ParseArgs() diff --git a/python/examples/ola_devices.py b/python/examples/ola_devices.py index f501a86881..f184ce79e7 100755 --- a/python/examples/ola_devices.py +++ b/python/examples/ola_devices.py @@ -18,9 +18,13 @@ """Lists the devices / ports.""" +from __future__ import print_function +from ola.ClientWrapper import ClientWrapper +import sys + __author__ = 'nomis52@gmail.com (Simon Newton)' -from ola.ClientWrapper import ClientWrapper +wrapper = None def RDMString(port): @@ -29,19 +33,27 @@ def RDMString(port): return '' -def Devices(state, devices): - for device in sorted(devices): - print('Device %d: %s' % (device.alias, device.name)) - print('Input ports:') - for port in device.input_ports: - print(' port %d, %s %s' % (port.id, port.description, RDMString(port))) - print('Output ports:') - for port in device.output_ports: - print(' port %d, %s %s' % (port.id, port.description, RDMString(port))) - wrapper.Stop() - - -wrapper = ClientWrapper() -client = wrapper.Client() -client.FetchDevices(Devices) -wrapper.Run() +def Devices(status, devices): + if status.Succeeded(): + for device in sorted(devices): + print('Device %d: %s' % (device.alias, device.name)) + print('Input ports:') + for port in device.input_ports: + print(' port %d, %s%s' % (port.id, port.description, RDMString(port))) + print('Output ports:') + for port in device.output_ports: + print(' port %d, %s%s' % (port.id, port.description, RDMString(port))) + else: + print('Error: %s' % status.message, file=sys.stderr) + + global wrapper + if wrapper: + wrapper.Stop() + + +def main(): + global wrapper + wrapper = ClientWrapper() + client = wrapper.Client() + client.FetchDevices(Devices) + wrapper.Run() diff --git a/python/examples/ola_patch_unpatch.py b/python/examples/ola_patch_unpatch.py index 716c3e19bd..a2a9ec4ff6 100755 --- a/python/examples/ola_patch_unpatch.py +++ b/python/examples/ola_patch_unpatch.py @@ -22,9 +22,12 @@ 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.' @@ -55,18 +58,25 @@ def PatchPortCallback(status): if status.Succeeded(): print('Success!') else: - print('Oops: {}'.format(status.message)) + print('Error: %s' % status.message, file=sys.stderr) 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 +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() + -wrapper = ClientWrapper() -client = wrapper.Client() -client.PatchPort(device, port, is_output, action, universe, PatchPortCallback) -wrapper.Run() +if __name__ == '__main__': + main() diff --git a/python/examples/ola_plugin_info.py b/python/examples/ola_plugin_info.py index 7ccfc4cb87..b85506f96f 100755 --- a/python/examples/ola_plugin_info.py +++ b/python/examples/ola_plugin_info.py @@ -18,12 +18,15 @@ """Lists the loaded plugins.""" -__author__ = 'nomis52@gmail.com (Simon Newton)' - +from __future__ import print_function +from ola.ClientWrapper import ClientWrapper import getopt import textwrap import sys -from ola.ClientWrapper import ClientWrapper + +__author__ = 'nomis52@gmail.com (Simon Newton)' + +wrapper = None def Usage(): @@ -36,16 +39,30 @@ def Usage(): -p, --plugin Plugin ID number.""")) -def main(): - def Plugins(state, plugins): +def Plugins(status, plugins): + if status.Succeeded(): for plugin in plugins: print('%d %s' % (plugin.id, plugin.name)) + else: + print('Error: %s' % status.message, file=sys.stderr) + + global wrapper + if wrapper: wrapper.Stop() - def PluginDescription(state, description): + +def PluginDescription(status, description): + if status.Succeeded(): print(description) + else: + print('Error: %s' % status.message, file=sys.stderr) + + global wrapper + if wrapper: wrapper.Stop() + +def main(): try: opts, args = getopt.getopt(sys.argv[1:], "hp:", ["help", "plugin="]) except getopt.GetoptError as err: @@ -61,6 +78,7 @@ def PluginDescription(state, description): elif o in ("-p", "--plugin"): plugin = int(a) + global wrapper wrapper = ClientWrapper() client = wrapper.Client() diff --git a/python/examples/ola_rdm_discover.py b/python/examples/ola_rdm_discover.py index 38f556feb5..132e529cb4 100755 --- a/python/examples/ola_rdm_discover.py +++ b/python/examples/ola_rdm_discover.py @@ -18,13 +18,13 @@ '''Show the UIDs for a universe.''' -__author__ = 'nomis52@gmail.com (Simon Newton)' - import getopt import textwrap import sys from ola.ClientWrapper import ClientWrapper +__author__ = 'nomis52@gmail.com (Simon Newton)' + def Usage(): print(textwrap.dedent("""\ diff --git a/python/examples/ola_rdm_get.py b/python/examples/ola_rdm_get.py index 9645f0dbf4..b97ef39814 100755 --- a/python/examples/ola_rdm_get.py +++ b/python/examples/ola_rdm_get.py @@ -18,9 +18,6 @@ '''Get a PID from a UID.''' -__author__ = 'nomis52@gmail.com (Simon Newton)' - - import cmd import getopt import os.path @@ -33,6 +30,8 @@ from ola.RDMAPI import RDMAPI from ola.UID import UID +__author__ = 'nomis52@gmail.com (Simon Newton)' + def Usage(): print(textwrap.dedent("""\ diff --git a/python/examples/ola_recv_dmx.py b/python/examples/ola_recv_dmx.py index 5c70ff76b1..6f1abdf100 100755 --- a/python/examples/ola_recv_dmx.py +++ b/python/examples/ola_recv_dmx.py @@ -18,13 +18,13 @@ """Receive DMX data.""" -__author__ = 'nomis52@gmail.com (Simon Newton)' - import getopt import textwrap import sys from ola.ClientWrapper import ClientWrapper +__author__ = 'nomis52@gmail.com (Simon Newton)' + def NewData(data): print(data) diff --git a/python/examples/ola_send_dmx.py b/python/examples/ola_send_dmx.py index fd59106a34..3adeb0ec78 100755 --- a/python/examples/ola_send_dmx.py +++ b/python/examples/ola_send_dmx.py @@ -18,26 +18,44 @@ """Send some DMX data.""" +from __future__ import print_function +from ola.ClientWrapper import ClientWrapper +import array +import sys + __author__ = 'nomis52@gmail.com (Simon Newton)' -import array -from ola.ClientWrapper import ClientWrapper +wrapper = None + + +def DmxSent(status): + if status.Succeeded(): + print('Success!') + else: + print('Error: %s' % status.message, file=sys.stderr) + + global wrapper + if wrapper: + wrapper.Stop() + +def main(): + universe = 1 + data = array.array('B') + # append first dmx-value + data.append(10) + # append second dmx-value + data.append(50) + # append third dmx-value + data.append(255) -def DmxSent(state): - wrapper.Stop() + global wrapper + wrapper = ClientWrapper() + client = wrapper.Client() + # send 1 dmx frame with values for channels 1-3 + client.SendDmx(universe, data, DmxSent) + wrapper.Run() -universe = 1 -data = array.array('B') -# append first dmx-value -data.append(10) -# append second dmx-value -data.append(50) -# append third dmx-value -data.append(255) -wrapper = ClientWrapper() -client = wrapper.Client() -# send 1 dmx frame with values for channels 1-3 -client.SendDmx(universe, data, DmxSent) -wrapper.Run() +if __name__ == '__main__': + main() diff --git a/python/examples/ola_simple_fade.py b/python/examples/ola_simple_fade.py index cae3551d88..4f317d549a 100755 --- a/python/examples/ola_simple_fade.py +++ b/python/examples/ola_simple_fade.py @@ -16,6 +16,11 @@ # ola_simple_fade.py # Copyright (C) 2014 Sean Sill +from array import array +from ola.ClientWrapper import ClientWrapper +from ola.DMXConstants import DMX_MIN_SLOT_VALUE, DMX_MAX_SLOT_VALUE, \ + DMX_UNIVERSE_SIZE + __author__ = 'Sean Sill' """ @@ -26,10 +31,6 @@ universe """ -from array import array -from ola.ClientWrapper import ClientWrapper -from ola.DMXConstants import DMX_MIN_SLOT_VALUE, DMX_MAX_SLOT_VALUE, \ - DMX_UNIVERSE_SIZE UPDATE_INTERVAL = 25 # In ms, this comes about to ~40 frames a second SHUTDOWN_INTERVAL = 10000 # in ms, This is 10 seconds diff --git a/python/examples/ola_universe_info.py b/python/examples/ola_universe_info.py index 4dbf511e20..cc62175e53 100755 --- a/python/examples/ola_universe_info.py +++ b/python/examples/ola_universe_info.py @@ -18,32 +18,48 @@ """Lists the active universes.""" -__author__ = 'nomis52@gmail.com (Simon Newton)' - +from __future__ import print_function from ola.ClientWrapper import ClientWrapper from ola.OlaClient import Universe +import sys + +__author__ = 'nomis52@gmail.com (Simon Newton)' + +wrapper = None + + +def Universes(status, universes): + if status.Succeeded(): + for uni in universes: + print('Universe %d' % uni.id) + print(' - Name: %s' % uni.name) + print(' - Merge mode: %s' % ( + ('LTP' if uni.merge_mode == Universe.LTP else 'HTP'))) + + if len(uni.input_ports) > 0: + print(' - Input ports:') + for p in uni.input_ports: + print(' - %s' % p) + if len(uni.output_ports) > 0: + print(' - Output ports:') + for p in uni.output_ports: + print(' - %s' % p) + else: + print('Error: %s' % status.message, file=sys.stderr) -def Universes(state, universes): - for uni in universes: - print('Universe {}'.format(uni.id)) - print(' - Name: {}'.format(uni.name)) - print(' - Merge mode: {}'.format( - 'LTP' if uni.merge_mode == Universe.LTP else 'HTP')) + global wrapper + if wrapper: + wrapper.Stop() - if len(uni.input_ports) > 0: - print(' - Input ports:') - for p in uni.input_ports: - print(' - {}'.format(p)) - if len(uni.output_ports) > 0: - print(' - Output ports:') - for p in uni.output_ports: - print(' - {}'.format(p)) +def main(): + global wrapper + wrapper = ClientWrapper() + client = wrapper.Client() + client.FetchUniverses(Universes) + wrapper.Run() - wrapper.Stop() -wrapper = ClientWrapper() -client = wrapper.Client() -client.FetchUniverses(Universes) -wrapper.Run() +if __name__ == '__main__': + main() diff --git a/python/examples/rdm_compare.py b/python/examples/rdm_compare.py index 2936448a92..6aba073be0 100755 --- a/python/examples/rdm_compare.py +++ b/python/examples/rdm_compare.py @@ -16,11 +16,6 @@ # rdm_compare.py # Copyright (C) 2012 Simon Newton -'''Compare the RDM configurations saves with rdm_snapshot.py''' - -__author__ = 'nomis52@gmail.com (Simon Newton)' - - import getopt import os import pickle @@ -30,6 +25,10 @@ import webbrowser from ola.UID import UID +'''Compare the RDM configurations saves with rdm_snapshot.py''' + +__author__ = 'nomis52@gmail.com (Simon Newton)' + class Error(Exception): """Base exception class.""" diff --git a/python/examples/rdm_snapshot.py b/python/examples/rdm_snapshot.py index f167e21641..ecbd809482 100755 --- a/python/examples/rdm_snapshot.py +++ b/python/examples/rdm_snapshot.py @@ -16,11 +16,6 @@ # rdm_snapshot.py # Copyright (C) 2012 Simon Newton -'''Quick script to collect the settings from a rig.''' - -__author__ = 'nomis52@gmail.com (Simon Newton)' - - import getopt import logging import pickle @@ -33,6 +28,10 @@ from ola.RDMAPI import RDMAPI from ola.UID import UID +'''Quick script to collect the settings from a rig.''' + +__author__ = 'nomis52@gmail.com (Simon Newton)' + class Error(Exception): """Base exception class.""" diff --git a/python/ola/ClientWrapper.py b/python/ola/ClientWrapper.py index 313d9c9e5f..53d20d173f 100644 --- a/python/ola/ClientWrapper.py +++ b/python/ola/ClientWrapper.py @@ -15,10 +15,6 @@ # ClientWrapper.py # Copyright (C) 2005 Simon Newton -"""A simple client wrapper for the OlaClient.""" - -__author__ = 'nomis52@gmail.com (Simon Newton)' - import array import datetime import fcntl @@ -31,6 +27,10 @@ import traceback from ola.OlaClient import OlaClient +"""A simple client wrapper for the OlaClient.""" + +__author__ = 'nomis52@gmail.com (Simon Newton)' + class _Event(object): """An _Event represents a timer scheduled to expire in the future. diff --git a/python/ola/DUBDecoder.py b/python/ola/DUBDecoder.py index fafed8d7be..28f78e0819 100644 --- a/python/ola/DUBDecoder.py +++ b/python/ola/DUBDecoder.py @@ -15,15 +15,14 @@ # DUBDecoder.py # Copyright (C) 2012 Simon Newton +import itertools +from ola.UID import UID + """Decodes a DUB response.""" __author__ = 'nomis52@gmail.com (Simon Newton)' -import itertools -from ola.UID import UID - - def DecodeResponse(data): """Decode a DUB response. diff --git a/python/ola/DUBDecoderTest.py b/python/ola/DUBDecoderTest.py index be37146c5a..13d47ac656 100755 --- a/python/ola/DUBDecoderTest.py +++ b/python/ola/DUBDecoderTest.py @@ -16,13 +16,13 @@ # DUBDecoderTest.py # Copyright (C) Simon Newton +import unittest +from ola.DUBDecoder import DecodeResponse + """Test cases for the DUBDecoder class.""" __author__ = 'nomis52@gmail.com (Simon Newton)' -import unittest -from ola.DUBDecoder import DecodeResponse - class UIDTest(unittest.TestCase): TEST_DATA = [ diff --git a/python/ola/MACAddressTest.py b/python/ola/MACAddressTest.py index c6218a4af6..da9aba7078 100755 --- a/python/ola/MACAddressTest.py +++ b/python/ola/MACAddressTest.py @@ -16,14 +16,14 @@ # MACAddressTest.py # Copyright (C) 2013 Peter Newman -"""Test cases for the MACAddress class.""" - -__author__ = 'nomis52@gmail.com (Simon Newton)' - import sys import unittest from ola.MACAddress import MACAddress +"""Test cases for the MACAddress class.""" + +__author__ = 'nomis52@gmail.com (Simon Newton)' + class MACAddressTest(unittest.TestCase): diff --git a/python/ola/OlaClient.py b/python/ola/OlaClient.py index 4b2798d7e5..724d36a8f1 100644 --- a/python/ola/OlaClient.py +++ b/python/ola/OlaClient.py @@ -15,10 +15,6 @@ # OlaClient.py # Copyright (C) 2005 Simon Newton -"""The client used to communicate with the Ola Server.""" - -__author__ = 'nomis52@gmail.com (Simon Newton)' - import array import socket import struct @@ -27,6 +23,10 @@ from ola import Ola_pb2 from ola.UID import UID +"""The client used to communicate with the Ola Server.""" + +__author__ = 'nomis52@gmail.com (Simon Newton)' + """The port that the OLA server listens on.""" OLA_PORT = 9010 @@ -756,9 +756,10 @@ def FetchPlugins(self, callback): controller = SimpleRpcController() request = Ola_pb2.PluginListRequest() - done = lambda x, y: self._GetPluginsComplete(callback, x, y) try: - self._stub.GetPlugins(controller, request, done) + self._stub.GetPlugins( + controller, request, + lambda x, y: self._GetPluginsComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True @@ -780,9 +781,10 @@ def PluginDescription(self, callback, plugin_id): controller = SimpleRpcController() request = Ola_pb2.PluginDescriptionRequest() request.plugin_id = plugin_id - done = lambda x, y: self._PluginDescriptionComplete(callback, x, y) try: - self._stub.GetPluginDescription(controller, request, done) + self._stub.GetPluginDescription( + controller, request, + lambda x, y: self._PluginDescriptionComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True @@ -804,9 +806,10 @@ def FetchDevices(self, callback, plugin_filter=Plugin.OLA_PLUGIN_ALL): controller = SimpleRpcController() request = Ola_pb2.DeviceInfoRequest() request.plugin_id = plugin_filter - done = lambda x, y: self._DeviceInfoComplete(callback, x, y) try: - self._stub.GetDeviceInfo(controller, request, done) + self._stub.GetDeviceInfo( + controller, request, + lambda x, y: self._DeviceInfoComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True @@ -826,9 +829,10 @@ def FetchUniverses(self, callback): controller = SimpleRpcController() request = Ola_pb2.OptionalUniverseRequest() - done = lambda x, y: self._UniverseInfoComplete(callback, x, y) try: - self._stub.GetUniverseInfo(controller, request, done) + self._stub.GetUniverseInfo( + controller, request, + lambda x, y: self._UniverseInfoComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True @@ -850,9 +854,9 @@ def FetchDmx(self, universe, callback): controller = SimpleRpcController() request = Ola_pb2.UniverseRequest() request.universe = universe - done = lambda x, y: self._GetDmxComplete(callback, x, y) try: - self._stub.GetDmx(controller, request, done) + self._stub.GetDmx(controller, request, + lambda x, y: self._GetDmxComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True @@ -876,9 +880,10 @@ def SendDmx(self, universe, data, callback=None): request = Ola_pb2.DmxData() request.universe = universe request.data = data.tostring() - done = lambda x, y: self._AckMessageComplete(callback, x, y) try: - self._stub.UpdateDmxData(controller, request, done) + self._stub.UpdateDmxData( + controller, request, + lambda x, y: self._AckMessageComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True @@ -902,9 +907,10 @@ def SetUniverseName(self, universe, name, callback=None): request = Ola_pb2.UniverseNameRequest() request.universe = universe request.name = name - done = lambda x, y: self._AckMessageComplete(callback, x, y) try: - self._stub.SetUniverseName(controller, request, done) + self._stub.SetUniverseName( + controller, request, + lambda x, y: self._AckMessageComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True @@ -928,9 +934,10 @@ def SetUniverseMergeMode(self, universe, merge_mode, callback=None): request = Ola_pb2.MergeModeRequest() request.universe = universe request.merge_mode = merge_mode - done = lambda x, y: self._AckMessageComplete(callback, x, y) try: - self._stub.SetMergeMode(controller, request, done) + self._stub.SetMergeMode( + controller, request, + lambda x, y: self._AckMessageComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True @@ -956,9 +963,10 @@ def RegisterUniverse(self, universe, action, data_callback, callback=None): request = Ola_pb2.RegisterDmxRequest() request.universe = universe request.action = action - done = lambda x, y: self._AckMessageComplete(callback, x, y) try: - self._stub.RegisterForDmx(controller, request, done) + self._stub.RegisterForDmx( + controller, request, + lambda x, y: self._AckMessageComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() if action == self.PATCH: @@ -993,9 +1001,10 @@ def PatchPort(self, device_alias, port, is_output, action, universe, request.action = action request.is_output = is_output request.universe = universe - done = lambda x, y: self._AckMessageComplete(callback, x, y) try: - self._stub.PatchPort(controller, request, done) + self._stub.PatchPort( + controller, request, + lambda x, y: self._AckMessageComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True @@ -1019,9 +1028,10 @@ def ConfigureDevice(self, device_alias, request_data, callback): request = Ola_pb2.DeviceConfigRequest() request.device_alias = device_alias request.data = request_data - done = lambda x, y: self._ConfigureDeviceComplete(callback, x, y) try: - self._stub.ConfigureDevice(controller, request, done) + self._stub.ConfigureDevice( + controller, request, + lambda x, y: self._ConfigureDeviceComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True @@ -1058,9 +1068,10 @@ def SendTimeCode(self, request.minutes = minutes request.seconds = seconds request.frames = frames - done = lambda x, y: self._AckMessageComplete(callback, x, y) try: - self._stub.SendTimeCode(controller, request, done) + self._stub.SendTimeCode( + controller, request, + lambda x, y: self._AckMessageComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True @@ -1104,9 +1115,9 @@ def FetchUIDList(self, universe, callback): controller = SimpleRpcController() request = Ola_pb2.UniverseRequest() request.universe = universe - done = lambda x, y: self._FetchUIDsComplete(callback, x, y) try: - self._stub.GetUIDs(controller, request, done) + self._stub.GetUIDs(controller, request, + lambda x, y: self._FetchUIDsComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True @@ -1130,9 +1141,10 @@ def RunRDMDiscovery(self, universe, full, callback): request = Ola_pb2.DiscoveryRequest() request.universe = universe request.full = full - done = lambda x, y: self._FetchUIDsComplete(callback, x, y) try: - self._stub.ForceDiscovery(controller, request, done) + self._stub.ForceDiscovery( + controller, request, + lambda x, y: self._FetchUIDsComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True @@ -1217,9 +1229,10 @@ def SendRawRDMDiscovery(self, request.data = data request.include_raw_response = True request.include_raw_response = include_frames - done = lambda x, y: self._RDMCommandComplete(callback, x, y) try: - self._stub.RDMDiscoveryCommand(controller, request, done) + self._stub.RDMDiscoveryCommand( + controller, request, + lambda x, y: self._RDMCommandComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True @@ -1249,11 +1262,12 @@ def GetCandidatePorts(self, callback, universe=None): if universe is not None: request.universe = universe - # GetCandidatePorts works very much like GetDeviceInfo, so we can re-use - # its complete method. - done = lambda x, y: self._DeviceInfoComplete(callback, x, y) try: - self._stub.GetCandidatePorts(controller, request, done) + # GetCandidatePorts works very much like GetDeviceInfo, so we can re-use + # its complete method. + self._stub.GetCandidatePorts( + controller, request, + lambda x, y: self._DeviceInfoComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() @@ -1271,9 +1285,10 @@ def _RDMMessage(self, universe, uid, sub_device, param_id, callback, data, request.data = data request.is_set = set request.include_raw_response = include_frames - done = lambda x, y: self._RDMCommandComplete(callback, x, y) try: - self._stub.RDMCommand(controller, request, done) + self._stub.RDMCommand( + controller, request, + lambda x, y: self._RDMCommandComplete(callback, x, y)) except socket.error: raise OLADNotRunningException() return True diff --git a/python/ola/PidStore.py b/python/ola/PidStore.py index 8f291e71d7..a2ab57b6bc 100644 --- a/python/ola/PidStore.py +++ b/python/ola/PidStore.py @@ -16,12 +16,7 @@ # Copyright (C) 2010 Simon Newton # Holds all the information about RDM PIDs -"""The PID Store.""" - from __future__ import print_function - -__author__ = 'nomis52@gmail.com (Simon Newton)' - import binascii import math import ola.RDMConstants @@ -35,6 +30,10 @@ from ola.MACAddress import MACAddress from ola.UID import UID +"""The PID Store.""" + +__author__ = 'nomis52@gmail.com (Simon Newton)' + # Various sub device enums ROOT_DEVICE = 0 diff --git a/python/ola/RDMAPI.py b/python/ola/RDMAPI.py index 3e4f66a689..2686dcacb8 100644 --- a/python/ola/RDMAPI.py +++ b/python/ola/RDMAPI.py @@ -15,16 +15,15 @@ # RDMAPI.py # Copyright (C) 2010 Simon Newton -"""The Python RDM API.""" - from __future__ import print_function - -__author__ = 'nomis52@gmail.com (Simon Newton)' - import sys from ola.OlaClient import OlaClient from ola import PidStore +"""The Python RDM API.""" + +__author__ = 'nomis52@gmail.com (Simon Newton)' + class RDMAPI(object): """The RDM API. diff --git a/python/ola/UIDTest.py b/python/ola/UIDTest.py index 0843fdb6ea..cae43c51a4 100755 --- a/python/ola/UIDTest.py +++ b/python/ola/UIDTest.py @@ -16,14 +16,14 @@ # UIDTest.py # Copyright (C) 2005 Simon Newton -"""Test cases for the UID class.""" - -__author__ = 'nomis52@gmail.com (Simon Newton)' - import sys import unittest from ola.UID import UID, UIDOutOfRangeException +"""Test cases for the UID class.""" + +__author__ = 'nomis52@gmail.com (Simon Newton)' + class UIDTest(unittest.TestCase): diff --git a/python/ola/rpc/SimpleRpcController.py b/python/ola/rpc/SimpleRpcController.py index 771a099713..8199023838 100644 --- a/python/ola/rpc/SimpleRpcController.py +++ b/python/ola/rpc/SimpleRpcController.py @@ -15,12 +15,12 @@ # SimpleRpcController.py # Copyright (C) 2005 Simon Newton +from google.protobuf import service + """An implementation of the RpcController interface.""" __author__ = 'nomis52@gmail.com (Simon Newton)' -from google.protobuf import service - class SimpleRpcController(service.RpcController): """See google.protobuf.service.RpcController for documentation.""" diff --git a/python/ola/rpc/SimpleRpcControllerTest.py b/python/ola/rpc/SimpleRpcControllerTest.py index 858dd4839a..31609d9dfa 100755 --- a/python/ola/rpc/SimpleRpcControllerTest.py +++ b/python/ola/rpc/SimpleRpcControllerTest.py @@ -16,13 +16,13 @@ # SimpleRpcControllerTest.py # Copyright (C) 2005 Simon Newton +import unittest +from SimpleRpcController import SimpleRpcController + """Test cases for the SimpleRpcController.""" __author__ = 'nomis52@gmail.com (Simon Newton)' -import unittest -from SimpleRpcController import SimpleRpcController - class SimpleRpcControllerTest(unittest.TestCase): diff --git a/python/ola/rpc/StreamRpcChannel.py b/python/ola/rpc/StreamRpcChannel.py index 34626fdc51..8d1aeb8c03 100644 --- a/python/ola/rpc/StreamRpcChannel.py +++ b/python/ola/rpc/StreamRpcChannel.py @@ -15,16 +15,16 @@ # StreamRpcChannel.py # Copyright (C) 2005 Simon Newton -"""A RpcChannel that works over a TCP socket.""" - -__author__ = 'nomis52@gmail.com (Simon Newton)' - import logging import struct from google.protobuf import service from ola.rpc import Rpc_pb2 from ola.rpc.SimpleRpcController import SimpleRpcController +"""A RpcChannel that works over a TCP socket.""" + +__author__ = 'nomis52@gmail.com (Simon Newton)' + class OutstandingRequest(object): """These represent requests on the server side that haven't completed yet.""" @@ -300,8 +300,8 @@ def _HandleRequest(self, message): self._SendRequestFailed(message.id) self._outstanding_requests[message.id] = request - callback = lambda x: self.RequestComplete(request, x) - self._service.CallMethod(method, request.controller, request_pb, callback) + self._service.CallMethod(method, request.controller, request_pb, + lambda x: self.RequestComplete(request, x)) def _HandleResponse(self, message): """Handle a Response message. diff --git a/tools/rdm/DMXSender.py b/tools/rdm/DMXSender.py index 1eb3308e8e..16c822d00f 100644 --- a/tools/rdm/DMXSender.py +++ b/tools/rdm/DMXSender.py @@ -15,11 +15,11 @@ # DMXSender.py # Copyright (C) 2011 Simon Newton -__author__ = 'nomis52@gmail.com (Simon Newton)' - import array import logging +__author__ = 'nomis52@gmail.com (Simon Newton)' + class DMXSender(object): def __init__(self, ola_wrapper, universe, frame_rate, slot_count): diff --git a/tools/rdm/ModelCollector.py b/tools/rdm/ModelCollector.py index fe356b0be5..583d109092 100644 --- a/tools/rdm/ModelCollector.py +++ b/tools/rdm/ModelCollector.py @@ -15,17 +15,17 @@ # ModelCollector.py # Copyright (C) 2011 Simon Newton -'''Quick script to collect information about responders.''' - -__author__ = 'nomis52@gmail.com (Simon Newton)' - - import logging import ola.RDMConstants from ola import PidStore from ola.OlaClient import OlaClient, RDMNack from ola.RDMAPI import RDMAPI +'''Quick script to collect information about responders.''' + +__author__ = 'nomis52@gmail.com (Simon Newton)' + + DEFAULT_LANGUAGE = "en" @@ -209,9 +209,10 @@ def _HandleSupportedParams(self, data): this_version = self._GetVersion() for param_info in data['params']: this_version['supported_parameters'].append(param_info['param_id']) - if (param_info['param_id'] >= ola.RDMConstants.RDM_MANUFACTURER_PID_MIN - and param_info['param_id'] <= - ola.RDMConstants.RDM_MANUFACTURER_PID_MAX): + if (param_info['param_id'] >= + ola.RDMConstants.RDM_MANUFACTURER_PID_MIN and + param_info['param_id'] <= + ola.RDMConstants.RDM_MANUFACTURER_PID_MAX): self.manufacturer_pids.append(param_info['param_id']) self._NextState() diff --git a/tools/rdm/ResponderTest.py b/tools/rdm/ResponderTest.py index 62aa8c9706..65bb8f15a7 100644 --- a/tools/rdm/ResponderTest.py +++ b/tools/rdm/ResponderTest.py @@ -24,10 +24,6 @@ # result based on the output of # SUPPORTED_PARAMETERS -'''Automated testing for RDM responders.''' - -__author__ = 'nomis52@gmail.com (Simon Newton)' - import logging import time from ExpectedResults import (AckDiscoveryResult, AckGetResult, AckSetResult, @@ -38,6 +34,10 @@ from ola import PidStore from ola.OlaClient import OlaClient, RDMNack +'''Automated testing for RDM responders.''' + +__author__ = 'nomis52@gmail.com (Simon Newton)' + class Error(Exception): """The base error class.""" diff --git a/tools/rdm/TestDefinitions.py b/tools/rdm/TestDefinitions.py index 33229ba8a9..17117f4314 100644 --- a/tools/rdm/TestDefinitions.py +++ b/tools/rdm/TestDefinitions.py @@ -15,10 +15,6 @@ # TestDefinitions.py # Copyright (C) 2010 Simon Newton -'''This defines all the tests for RDM responders.''' - -__author__ = 'nomis52@gmail.com (Simon Newton)' - import datetime import operator import struct @@ -45,6 +41,11 @@ import TestMixins from TestMixins import MAX_DMX_ADDRESS +'''This defines all the tests for RDM responders.''' + +__author__ = 'nomis52@gmail.com (Simon Newton)' + + MAX_PERSONALITY_NUMBER = 255 @@ -2216,9 +2217,10 @@ def VerifyResult(self, response, fields): if slot['slot_type'] == RDMConstants.SLOT_TYPES['ST_PRIMARY']: # slot_label_id must be valid - if ((slot['slot_label_id'] not in RDMConstants.SLOT_DEFINITION_TO_NAME) - and (slot['slot_label_id'] < RDM_MANUFACTURER_SD_MIN or - slot['slot_label_id'] > RDM_MANUFACTURER_SD_MAX)): + if ((slot['slot_label_id'] not in + RDMConstants.SLOT_DEFINITION_TO_NAME) and + (slot['slot_label_id'] < RDM_MANUFACTURER_SD_MIN or + slot['slot_label_id'] > RDM_MANUFACTURER_SD_MAX)): self.AddWarning('Unknown slot id %d for slot %d' % (slot['slot_label_id'], slot['slot_offset'])) if (slot['slot_label_id'] == diff --git a/tools/rdm/TestMixins.py b/tools/rdm/TestMixins.py index f7e0f7b72d..385e854d4b 100644 --- a/tools/rdm/TestMixins.py +++ b/tools/rdm/TestMixins.py @@ -15,14 +15,6 @@ # TestMixins.py # Copyright (C) 2010 Simon Newton -'''Mixins used by the test definitions. - -This module contains classes which can be inherited from to simplify writing -test definitions. -''' - -__author__ = 'nomis52@gmail.com (Simon Newton)' - import struct from ExpectedResults import (AckGetResult, AckDiscoveryResult, BroadcastResult, DUBResult, NackSetResult, TimeoutResult, @@ -38,6 +30,15 @@ from ola.RDMConstants import RDM_MAX_STRING_LENGTH from ola.UID import UID +'''Mixins used by the test definitions. + +This module contains classes which can be inherited from to simplify writing +test definitions. +''' + +__author__ = 'nomis52@gmail.com (Simon Newton)' + + MAX_DMX_ADDRESS = DMX_UNIVERSE_SIZE diff --git a/tools/rdm/TestRunner.py b/tools/rdm/TestRunner.py index 1c4047abd0..628cb2ffe4 100644 --- a/tools/rdm/TestRunner.py +++ b/tools/rdm/TestRunner.py @@ -15,8 +15,6 @@ # TestRunner.py # Copyright (C) 2011 Simon Newton -__author__ = 'nomis52@gmail.com (Simon Newton)' - import datetime import inspect import logging @@ -27,6 +25,8 @@ from ola.RDMAPI import RDMAPI from ola.testing.rdm import ResponderTest +__author__ = 'nomis52@gmail.com (Simon Newton)' + class Error(Exception): """The base error class.""" diff --git a/tools/rdm/TimingStats.py b/tools/rdm/TimingStats.py index 3273c2ad7b..1fcc0bbf42 100644 --- a/tools/rdm/TimingStats.py +++ b/tools/rdm/TimingStats.py @@ -15,12 +15,12 @@ # TimingStats.py # Copyright (C) 2015 Simon Newton -__author__ = 'nomis52@gmail.com (Simon Newton)' - import logging import numpy from ola.OlaClient import OlaClient +__author__ = 'nomis52@gmail.com (Simon Newton)' + class FrameTypeStats(object): """Holds timing stats for a particular class of response.""" diff --git a/tools/rdm/launch_tests.py b/tools/rdm/launch_tests.py index 2dfab51f04..304fd48a42 100755 --- a/tools/rdm/launch_tests.py +++ b/tools/rdm/launch_tests.py @@ -16,19 +16,6 @@ # launch_tests.py # Copyright (C) 2012 Simon Newton -""" -Launch the OLA RDM test environment. - -Under the hood this does the following: - - creates a new temp directory for the configs - - copies in the skeleton configs files from the skel directory - - starts olad pointing at the config directory - - runs the auto-patching script to setup the port / universe patchings -""" - -__author__ = 'nomis52@gmail.com (Simon Newton)' - - from optparse import OptionParser import logging import os @@ -41,6 +28,18 @@ import textwrap import time +""" +Launch the OLA RDM test environment. + +Under the hood this does the following: + - creates a new temp directory for the configs + - copies in the skeleton configs files from the skel directory + - starts olad pointing at the config directory + - runs the auto-patching script to setup the port / universe patchings +""" + +__author__ = 'nomis52@gmail.com (Simon Newton)' + olad_process = None diff --git a/tools/rdm/rdm_model_collector.py b/tools/rdm/rdm_model_collector.py index 0077784dd5..c3b89bff8b 100755 --- a/tools/rdm/rdm_model_collector.py +++ b/tools/rdm/rdm_model_collector.py @@ -16,11 +16,6 @@ # rdm_model_collector.py # Copyright (C) 2011 Simon Newton -'''Quick script to collect information about responders.''' - -__author__ = 'nomis52@gmail.com (Simon Newton)' - - import getopt import logging import pprint @@ -30,6 +25,10 @@ from ola.testing.rdm.ModelCollector import ModelCollector from ola.ClientWrapper import ClientWrapper +'''Quick script to collect information about responders.''' + +__author__ = 'nomis52@gmail.com (Simon Newton)' + def Usage(): print textwrap.dedent("""\ diff --git a/tools/rdm/rdm_responder_test.py b/tools/rdm/rdm_responder_test.py index 6ec688e5b2..cffe8b860e 100755 --- a/tools/rdm/rdm_responder_test.py +++ b/tools/rdm/rdm_responder_test.py @@ -16,10 +16,6 @@ # rdm_responder_test.py # Copyright (C) 2010 Simon Newton -'''Automated testing for RDM responders.''' - -__author__ = 'nomis52@gmail.com (Simon Newton)' - from ola.testing.rdm import TestDefinitions, TestRunner from ola.testing.rdm.DMXSender import DMXSender from ola.testing.rdm.TestState import TestState @@ -36,6 +32,10 @@ from ola.UID import UID from optparse import OptionParser +'''Automated testing for RDM responders.''' + +__author__ = 'nomis52@gmail.com (Simon Newton)' + def ParseOptions(): usage = 'Usage: %prog [options] ' diff --git a/tools/rdm/setup_patch.py b/tools/rdm/setup_patch.py index 0178d785d5..3fcca87ca3 100755 --- a/tools/rdm/setup_patch.py +++ b/tools/rdm/setup_patch.py @@ -16,6 +16,10 @@ # setup_patch.py # Copyright (C) 2012 Simon Newton +import logging +from ola.ClientWrapper import ClientWrapper +from ola.OlaClient import OlaClient, Plugin + """A simple script to find all RDM enabled ports and auto-patch them to universes. """ @@ -23,11 +27,6 @@ __author__ = 'nomis52@gmail.com (Simon Newton)' -import logging -from ola.ClientWrapper import ClientWrapper -from ola.OlaClient import OlaClient, Plugin - - class AutoPatcher(object): """A class that patches RDM enabled Output Ports to universes.""" def __init__(self, wrapper, callback, force=False):