Esempio n. 1
0
def makeArgumentParser(description):
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument(
        '-i',
        '--input-file',
        dest='linknxConfig',
        help=
        'use LKNCONF as the source linknx configuration rather than reading from standard input.',
        metavar='LKNCONF')
    parser.add_argument(
        '-o',
        '--output-file',
        dest='outputFile',
        help=
        'write the modified linknx configuration to FILE rather than to standard output.',
        metavar='FILE')
    parser.add_argument(
        '-c',
        '--comm-addr',
        dest='communicatorAddress',
        help=
        'Address of the communicator. This argument must specify the hostname or the ip address followed by a colon and the port to listen on. Default is "localhost:1029"',
        default='localhost:1029')
    parser.add_argument(
        '-n',
        '--comm-name',
        dest='communicatorName',
        help=
        'Name of the communicator. Used to build the name of callback attributes on object definitions, to prefix name of rules generated by this script and to name the ioport service. Default is "pyknx" which leads to an ioport "pyknx" and callback attributes "pyknxcallback". This option is useful when several communicators have to connect to the same linknx instance without interfering with each other.',
        default='pyknx')
    parser.add_argument(
        '--clean',
        help=
        'Clean rules that were generated by this script but do not generate new rules.',
        action='store_true')
    parser.add_argument(
        '-v',
        '--verbose',
        dest='verbosityLevel',
        help='set verbosity level. Default is "warning".',
        metavar='LEVEL',
        choices=[l.lower() for l in logger.getLevelsToString()],
        default='warning')
    return parser
Esempio n. 2
0
def makeArgumentParser(description):
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('-c', '--comm-addr', dest='communicatorAddress', help='Address of the communicator. This argument must specify the hostname or the ip address followed by a colon and the port to listen on. Default is "localhost:1029"', default='localhost:1029')
    parser.add_argument('-l', '--linknx-addr', dest='linknxAddress', help='Address of the linknx server to bind to. This argument must specify the hostname or the ip address followed by a colon and the port. Default is "localhost:1028"', default='localhost:1028')
    parser.add_argument('userFile', help='use FILE as the user python script that implements callbacks functions declared in the linknx configuration (see the pyknxcallback attributes in XML).', metavar='FILE')
    parser.add_argument('--log-file', dest='logFile', help='write communicator\'s output to FILE rather than to standard output.', metavar='FILE', default=None)
    parser.add_argument('-d', '--daemonize', help='ask daemon to detach and run as a background daemon.', action='store_true', default=False)
    parser.add_argument('--pid-file', dest='pidFile', help='writes the PID of the daemon process to PIDFILE.', metavar='PIDFILE')
    parser.add_argument('-v', '--verbose', dest='verbosityLevel', help='set verbosity level. Default is "error".', metavar='LEVEL', choices=[l.lower() for l in logger.getLevelsToString()], default='error')
    return parser
Esempio n. 3
0
from homewatcher.configurator import Configurator
import argparse
import sys
import logging
import os
from pyknx import logger

__doc__ = __doc__.format(scriptname=os.path.basename(__file__))

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('linknxConfig', help='use LKNCONF as the source linknx configuration.', metavar='LKNCONF')
    parser.add_argument('-i', '--input-file', dest='homewatcherConfig', help='read homewatcher configuration from HWCONF rather than from standard input.', metavar='HWCONF')
    parser.add_argument('-o', '--output-file', dest='outputFile', help='write the modified linknx configuration to FILE rather than to standard output.', metavar='FILE')
    parser.add_argument('-v', '--verbose', dest='verbosityLevel', help='set verbosity level.', metavar='LEVEL', choices=[l.lower() for l in logger.getLevelsToString()], default='error')
    args = parser.parse_args()

    # Configure logger.
    logger.initLogger(None, args.verbosityLevel.upper())

    # Start configurator.
    configurator = Configurator(args.homewatcherConfig, args.linknxConfig, args.outputFile)

    # Generate config.
    try:
        configurator.cleanConfig()
        configurator.generateConfig()
        configurator.writeConfig()
    except:
        logger.reportException()
Esempio n. 4
0
        'read homewatcher configuration from HWCONF rather than from standard input.',
        metavar='HWCONF')
    parser.add_argument(
        '-o',
        '--output-file',
        dest='outputFile',
        help=
        'write the modified linknx configuration to FILE rather than to standard output.',
        metavar='FILE')
    parser.add_argument(
        '-v',
        '--verbose',
        dest='verbosityLevel',
        help='set verbosity level.',
        metavar='LEVEL',
        choices=[l.lower() for l in logger.getLevelsToString()],
        default='error')
    args = parser.parse_args()

    # Configure logger.
    logger.initLogger(None, args.verbosityLevel.upper())

    # Start configurator.
    configurator = Configurator(args.homewatcherConfig, args.linknxConfig,
                                args.outputFile)

    # Generate config.
    try:
        configurator.cleanConfig()
        configurator.generateConfig()
        configurator.writeConfig()
Esempio n. 5
0
def handleRequest(requestType, doc):
    logger.initLogger(None, logging.INFO, usesDetailedLogging=False)

    parser = argparse.ArgumentParser(description=doc)
    parser.add_argument(
        '-s',
        '--server',
        dest='host',
        help=
        'Hostname of the machine running the linknx daemon. Default is localhost.',
        default='localhost')
    parser.add_argument('-p',
                        '--port',
                        dest='port',
                        help='Port linknx listens on. Default is 1028.',
                        default=1028)
    if requestType == 'read':
        parser.add_argument(
            'objectIds',
            help='ID represents the identifier of the object to read.',
            metavar='ID',
            nargs='+')
        parser.add_argument(
            '-R',
            '--regex',
            action='store_true',
            help=
            'ID in the "object" argument is interpreted as a regex and used to find objects to read. The pattern must comply with the \'re\' python module.'
        )
        parser.add_argument(
            '--value-only',
            action='store_true',
            help=
            'Output the value of the queried object but do not prefix it with the object\'s id.'
        )
        parser.add_argument(
            '--expected-value',
            help=
            'Expected value of the object. This script will exit with a non-zero return code if the value is not the expected one. This is useful when using this script in a "if" test of a shell script.'
        )
    elif requestType == 'write':
        parser.add_argument(
            'object',
            help='ID represents the identifier of the object to write to.',
            metavar='ID')
        parser.add_argument(
            'value',
            help='Assigns VALUE to the object identified by ID.',
            metavar='VALUE')
    elif requestType == 'execute':
        parser.add_argument(
            '--action',
            help=
            'use the ACTION string as the XML representation of the action to execute rather than reading it from standard input.',
            metavar='ACTION')
    else:
        raise Exception('Unsupported request type "{0}".'.format(requestType))
    parser.add_argument(
        '-v',
        '--verbose',
        dest='verbosityLevel',
        help='Set verbosity level. Default is "error".',
        metavar='LEVEL',
        choices=[l.lower() for l in logger.getLevelsToString()],
        default='error')
    args = parser.parse_args()

    # Configure logger.
    logger.initLogger(None, args.verbosityLevel.upper())

    # Start linknx.
    linknx = Linknx(args.host, int(args.port))
    try:
        if requestType == 'read':
            objects = linknx.getObjects(
                objectIds=args.objectIds
            ) if not args.regex else linknx.getObjects(patterns=args.objectIds)

            # No object.
            if not objects:
                logger.reportWarning('No such object.')
                sys.exit(10)

            # Count tabs to align columns.
            report = objects.getValues()
            longestId = max([len(obj) for obj in report.keys()])
            succeeds = True
            for o in sorted(report):
                v = report[o]
                spaceCount = longestId - len(o)
                spaces = ''
                while spaceCount > 0:
                    spaces += ' '
                    spaceCount -= 1
                if args.value_only:
                    print('{0}'.format(v))
                else:
                    print('{0} {2} {1}'.format(o, v, spaces))

                if args.expected_value != None:
                    obj = linknx.getObject(o)
                    convertedExpectedValue = obj.convertValueToString(
                        args.expected_value)
                    convertedObjectValue = obj.convertValueToString(v)
                    succeeds = succeeds and convertedExpectedValue == convertedObjectValue

            if not succeeds: exit(100)

        elif requestType == 'write':
            linknx.getObject(args.object).value = args.value
        elif requestType == 'execute':
            if args.action == None:
                action = ''.join(sys.stdin.readlines())
            else:
                action = args.action
            linknx.executeAction(action)
        else:
            raise Exception('Unsupported request type.')

    except Exception as e:
        logger.reportException()
        sys.exit(3)
Esempio n. 6
0
def handleRequest(requestType, doc):
    logger.initLogger(None, logging.INFO, usesDetailedLogging=False)

    parser = argparse.ArgumentParser(description=doc)
    parser.add_argument('-s', '--server', dest='host', help='Hostname of the machine running the linknx daemon. Default is localhost.', default='localhost')
    parser.add_argument('-p', '--port', dest='port', help='Port linknx listens on. Default is 1028.', default=1028)
    if requestType == 'read':
        parser.add_argument('objectIds', help='ID represents the identifier of the object to read.', metavar='ID', nargs='+')
        parser.add_argument('-R', '--regex', action='store_true', help='ID in the "object" argument is interpreted as a regex and used to find objects to read. The pattern must comply with the \'re\' python module.')
        parser.add_argument('--value-only', action='store_true', help='Output the value of the queried object but do not prefix it with the object\'s id.')
        parser.add_argument('--expected-value', help='Expected value of the object. This script will exit with a non-zero return code if the value is not the expected one. This is useful when using this script in a "if" test of a shell script.')
    elif requestType == 'write':
        parser.add_argument('object', help='ID represents the identifier of the object to write to.', metavar='ID')
        parser.add_argument('value', help='Assigns VALUE to the object identified by ID.', metavar='VALUE')
    elif requestType == 'execute':
        parser.add_argument('--action', help='use the ACTION string as the XML representation of the action to execute rather than reading it from standard input.', metavar='ACTION')
    else:
        raise Exception('Unsupported request type "{0}".'.format(requestType))
    parser.add_argument('-v', '--verbose', dest='verbosityLevel', help='Set verbosity level. Default is "error".', metavar='LEVEL', choices=[l.lower() for l in logger.getLevelsToString()], default='error')
    args = parser.parse_args()

    # Configure logger.
    logger.initLogger(None, args.verbosityLevel.upper())

    # Start linknx.
    linknx = Linknx(args.host, int(args.port))
    try:
        if requestType == 'read':
            objects = linknx.getObjects(objectIds=args.objectIds) if not args.regex else linknx.getObjects(patterns=args.objectIds)

            # No object.
            if not objects:
                logger.reportWarning('No such object.')
                sys.exit(10)

            # Count tabs to align columns.
            report = objects.getValues()
            longestId = max([len(obj) for obj in report.keys()])
            succeeds = True
            for o in sorted(report):
                v = report[o]
                spaceCount = longestId - len(o)
                spaces=''
                while spaceCount > 0:
                    spaces+=' '
                    spaceCount -= 1
                if args.value_only:
                    print('{0}'.format(v))
                else:
                    print('{0} {2} {1}'.format(o, v, spaces))

                if args.expected_value != None:
                    obj = linknx.getObject(o)
                    convertedExpectedValue = obj.convertValueToString(args.expected_value)
                    convertedObjectValue = obj.convertValueToString(v)
                    succeeds = succeeds and convertedExpectedValue == convertedObjectValue

            if not succeeds: exit(100)

        elif requestType == 'write':
            linknx.getObject(args.object).value = args.value
        elif requestType == 'execute':
            if args.action == None:
                action = ''.join(sys.stdin.readlines())
            else:
                action = args.action
            linknx.executeAction(action)
        else:
            raise Exception('Unsupported request type.')

    except Exception as e:
        logger.reportException()
        sys.exit(3)
Esempio n. 7
0
def makeArgumentParser(description):
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('-i', '--input-file', dest='linknxConfig', help='use LKNCONF as the source linknx configuration rather than reading from standard input.', metavar='LKNCONF')
    parser.add_argument('-o', '--output-file', dest='outputFile', help='write the modified linknx configuration to FILE rather than to standard output.', metavar='FILE')
    parser.add_argument('-c', '--comm-addr', dest='communicatorAddress', help='Address of the communicator. This argument must specify the hostname or the ip address followed by a colon and the port to listen on. Default is "localhost:1029"', default='localhost:1029')
    parser.add_argument('-n', '--comm-name', dest='communicatorName', help='Name of the communicator. Used to build the name of callback attributes on object definitions, to prefix name of rules generated by this script and to name the ioport service. Default is "pyknx" which leads to an ioport "pyknx" and callback attributes "pyknxcallback". This option is useful when several communicators have to connect to the same linknx instance without interfering with each other.', default='pyknx')
    parser.add_argument('--clean', help='Clean rules that were generated by this script but do not generate new rules.', action='store_true')
    parser.add_argument('-v', '--verbose', dest='verbosityLevel', help='set verbosity level. Default is "warning".', metavar='LEVEL', choices=[l.lower() for l in logger.getLevelsToString()], default='warning')
    return parser
Esempio n. 8
0
def makeArgumentParser(description):
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('-c', '--comm-addr', dest='communicatorAddress', help='Address of the communicator. This argument must specify the hostname or the ip address followed by a colon and the port to listen on. Default is "localhost:1029"', default='localhost:1029')
    parser.add_argument('-l', '--linknx-addr', dest='linknxAddress', help='Address of the linknx server to bind to. This argument must specify the hostname or the ip address followed by a colon and the port. Default is "localhost:1028"', default='localhost:1028')
    parser.add_argument('userFile', help='use FILE as the user python script that implements callbacks functions declared in the linknx configuration (see the pyknxcallback attributes in XML).', metavar='FILE')
    parser.add_argument('--log-file', dest='logFile', help='write communicator\'s output to FILE rather than to standard output.', metavar='FILE', default=None)
    parser.add_argument('-d', '--daemonize', help='ask daemon to detach and run as a background daemon.', action='store_true', default=False)
    parser.add_argument('--pid-file', dest='pidFile', help='writes the PID of the daemon process to PIDFILE.', metavar='PIDFILE')
    parser.add_argument('-v', '--verbose', dest='verbosityLevel', help='set verbosity level. Default is "error".', metavar='LEVEL', choices=[l.lower() for l in logger.getLevelsToString()], default='error')
    return parser