コード例 #1
0
ファイル: rtwatch.py プロジェクト: win-katami/rtshell
def main(argv=None, tree=None):
    parser = argparse.ArgumentParser(prog='rtwatch', description='Watch a component event.')
    filterkind = filtermap.keys()
    filterkind.insert(0, 'ALL')
    parser.add_argument('-n', '--number', dest='number', action='store',
            type=int, default=-1,
            help='Number of events to capture. [Default: %(default)s]')
    parser.add_argument('-f', '--filter', dest='filters', action='append',
            type=str, choices=filterkind, default=[],
            help='Event source filters. [Default: ALL]')
    parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %(default)s]')
    parser.add_argument('path', metavar='path', type=str, nargs='+',
            help='Path to component.')

    if argv:
        sys.argv = [sys.argv[0]] + argv

    options = parser.parse_args()

    paths = [[p, path.cmd_path_to_full_path(p)] for p in options.path]

    try:
        print_logs(paths, options, tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #2
0
ファイル: rtcon.py プロジェクト: gbiggs/rtshell
def main(argv=None, tree=None):
    def property_callback(option, opt, option_value, parser):
        if option_value.count('=') != 1:
            raise optparse.OptionValueError('Bad property format: {0}'.format(
                option_value))
        key, equals, value = option_value.partition('=')
        if not getattr(parser.values, option.dest):
            setattr(parser.values, option.dest, {})
        if key in getattr(parser.values, option.dest):
            print('{0}: Warning: duplicate property: {1}'.format(sys.argv[0],
                option_value), file=sys.stderr)
        getattr(parser.values, option.dest)[key] = value

    usage = '''Usage: %prog [options] <path 1> <path 2> [<path 3> ...]
Connect two or more ports.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-d', '--no-duplicates', dest='no_dups',
            action='store_true', help='Prevent duplicate connections')
    parser.add_option('-i', '--id', dest='id', action='store', type='string',
            default='', help='ID of the connection. [Default: %default]')
    parser.add_option('-n', '--name', dest='name', action='store',
            type='string', default=None,
            help='Name of the connection. [Default: %default]')
    parser.add_option('-p', '--property', dest='properties', action='callback',
            callback=property_callback, type='string',
            help='Connection properties.')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if not getattr(options, 'properties'):
        setattr(options, 'properties', {})

    if not args:
        # If no paths given then can't do anything.
        print('{0}: No ports specified.'.format(os.path.basename(sys.argv[0])),
                file=sys.stderr)
        return 1
    paths = [(p, path.cmd_path_to_full_path(p)) for p in args]

    try:
        connect_ports(paths, options, tree=tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #3
0
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] <path1>:<port1> [<path2>:<port2>...]
Print the data being sent by one or more output ports.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-m', '--mod', dest='modules', action='append',
            type='string', default=[],
            help='Extra modules to import. If automatic module loading '\
            'struggles with your data types, try listing the modules here. '\
            'The module and its __POA partner will be imported.')
    parser.add_option('-n', '--number', dest='max', action='store',
            type='int', default='-1', help='Specify the number of times to '\
            'read from any ports. [Default: infinity]')
    parser.add_option(
        '-p',
        '--path',
        dest='paths',
        action='append',
        type='string',
        default=[],
        help='Extra module search paths to add to the PYTHONPATH.')
    parser.add_option('-r', '--rate', dest='rate', action='store',
            type='float', default=100.0, help='Specify the rate in Hertz at '\
            'which to read and print. [Default: %default]')
    parser.add_option('-t', '--timeout', dest='timeout', action='store',
            type='float', default=-1, help='Read data for this many seconds, '\
            'then stop. Specify -1 for no timeout. This option overrides '\
            '--number. [Default: %default]')
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      default=False,
                      help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if len(args) < 1:
        print(usage, file=sys.stderr)
        return 1

    try:
        read_from_ports([path.cmd_path_to_full_path(p) for p in args], options,
                        tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
              file=sys.stderr)
        return 1
    return 0
コード例 #4
0
ファイル: rtdel.py プロジェクト: win-katami/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] <path>
Delete an object from a name server.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      default=False,
                      help='Output verbose information. [Default: %default]')
    parser.add_option('-z',
                      '--zombies',
                      dest='zombies',
                      action='store_true',
                      default=False,
                      help='Delete only zombies. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    try:
        if not args:
            if not options.zombies:
                print('{0}: No path given.'.format(sys.argv[0]),
                      file=sys.stderr)
                return 1
            else:
                # If no path given, delete all zombies found
                delete_all_zombies(options, tree)
        elif len(args) == 1:
            full_path = path.cmd_path_to_full_path(args[0])
            # Some sanity checks
            if full_path == '/':
                print('{0}: Cannot delete the root directory.'.format(
                    sys.argv[0]),
                      file=sys.stderr)
                return 1
            delete_object_reference(args[0], full_path, options, tree)
        else:
            print(usage, file=sys.stderr)
            return 1
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
              file=sys.stderr)
        return 1
    return 0
コード例 #5
0
ファイル: rtvlog.py プロジェクト: gbiggs/rtshell
def main(argv=None, tree=None):
    usage = """Usage: %prog [options] <path 1> [path 2...]
View a component logs."""
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option(
        "-f",
        "--filter",
        dest="filters",
        action="append",
        type="string",
        default="ALL",
        help="Event source filters. [Default: %default]",
    )
    parser.add_option(
        "-l",
        "--level",
        dest="level",
        action="store",
        type="string",
        default="NORMAL",
        help="Log level. [Default: %default]",
    )
    parser.add_option(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="Output verbose information. [Default: %default]",
    )

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print("OptionError:", e, file=sys.stderr)
        return 1

    if not args:
        # If no paths given then can't do anything.
        print("{0}: No component specified.".format(os.path.basename(sys.argv[0])), file=sys.stderr)
        return 1
    paths = [[p, path.cmd_path_to_full_path(p)] for p in args]

    try:
        print_logs(paths, options, tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print("{0}: {1}".format(os.path.basename(sys.argv[0]), e), file=sys.stderr)
        return 1
    return 0
コード例 #6
0
ファイル: rtinject.py プロジェクト: aist-rslab/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] <path1>:<port1> [<path2>:<port2>...]
Write a constant value to one or more ports.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-c', '--const', dest='const', action='store',
            type='string', default='',
            help='The constant value to send, as a Python expression. If '
            'not specified, values will be read from standard in.')
    parser.add_option('-m', '--mod', dest='modules', action='append',
            type='string', default=[],
            help='Extra modules to import. If automatic module loading '
            'struggles with your data types, try listing the modules here. '
            'The module and its __POA partner will be imported.')
    parser.add_option('-n', '--number', dest='max', action='store',
            type='int', default='1',
            help='Specify the number of times to write to the port. '
            '[Default: %default]')
    parser.add_option('-p', '--path', dest='paths', action='append',
            type='string', default=[],
            help='Extra module search paths to add to the PYTHONPATH.')
    parser.add_option('-r', '--rate', dest='rate', action='store',
            type='float', default=1.0,
            help='Specify the rate in Hertz at which to emit data. '
            '[Default: %default]')
    parser.add_option('-t', '--timeout', dest='timeout', action='store',
            type='float', default=-1, help='Write data for this many seconds, '
            'then stop. This option overrides --number. [Default: %default]')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if len(args) < 1:
        print(usage, file=sys.stderr)
        return 1

    try:
        write_to_ports([path.cmd_path_to_full_path(p) \
                for p in args], options, tree=tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #7
0
ファイル: rtinject.py プロジェクト: n-kawauchi/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] <path1>:<port1> [<path2>:<port2>...]
Write a constant value to one or more ports.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-c', '--const', dest='const', action='store',
            type='string', default='',
            help='The constant value to send, as a Python expression. If '
            'not specified, values will be read from standard in.')
    parser.add_option('-m', '--mod', dest='modules', action='append',
            type='string', default=[],
            help='Extra modules to import. If automatic module loading '
            'struggles with your data types, try listing the modules here. '
            'The module and its __POA partner will be imported.')
    parser.add_option('-n', '--number', dest='max', action='store',
            type='int', default='1',
            help='Specify the number of times to write to the port. '
            '[Default: %default]')
    parser.add_option('-p', '--path', dest='paths', action='append',
            type='string', default=[],
            help='Extra module search paths to add to the PYTHONPATH.')
    parser.add_option('-r', '--rate', dest='rate', action='store',
            type='float', default=1.0,
            help='Specify the rate in Hertz at which to emit data. '
            '[Default: %default]')
    parser.add_option('-t', '--timeout', dest='timeout', action='store',
            type='float', default=-1, help='Write data for this many seconds, '
            'then stop. This option overrides --number. [Default: %default]')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if len(args) < 1:
        print(usage, file=sys.stderr)
        return 1

    try:
        write_to_ports([path.cmd_path_to_full_path(p) \
                for p in args], options, tree=tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #8
0
ファイル: rtls.py プロジェクト: n-kawauchi/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] [path]
List a name server, directory, manager or component.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-l',
                      dest='long',
                      action='store_true',
                      default=False,
                      help='Use a long listing format.')
    parser.add_option('-R',
                      '--recurse',
                      dest='recurse',
                      action='store_true',
                      default=False,
                      help='List recursively. [Default: %default]')
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      default=False,
                      help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if not args:
        cmd_path = ''
    elif len(args) == 1:
        cmd_path = args[0]
    else:
        print(usage, file=sys.stderr)
        return 1
    full_path = path.cmd_path_to_full_path(cmd_path)

    result = []
    try:
        result = list_target(cmd_path, full_path, options, tree)
        for l in result:
            print(l)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
              file=sys.stderr)
        return 1
    return 0
コード例 #9
0
ファイル: rtdis.py プロジェクト: win-katami/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] <source path> [destination path]
Remove connections.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-i', '--id', dest='id', action='store', type='string',
            default='', help='ID of the connection.')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    try:
        if len(args) == 1:
            # Disconnect all
            cmd_path = args[0]
            disconnect_all(cmd_path, path.cmd_path_to_full_path(cmd_path),
                                  options, tree)
        elif len(args) > 1:
            # Disconnect a set of ports
            paths = [(p, path.cmd_path_to_full_path(p)) for p in args]
            disconnect_ports(paths, options, tree)
        else:
            print(usage, file=sys.stderr)
            return 1
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #10
0
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] <path 1> [path 2...]
View a component logs.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-f',
                      '--filter',
                      dest='filters',
                      action='append',
                      type='string',
                      default='ALL',
                      help='Event source filters. [Default: %default]')
    parser.add_option('-l',
                      '--level',
                      dest='level',
                      action='store',
                      type='string',
                      default='NORMAL',
                      help='Log level. [Default: %default]')
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      default=False,
                      help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if not args:
        # If no paths given then can't do anything.
        print('{0}: No component specified.'.format(
            os.path.basename(sys.argv[0])),
              file=sys.stderr)
        return 1
    paths = [[p, path.cmd_path_to_full_path(p)] for p in args]

    try:
        print_logs(paths, options, tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
              file=sys.stderr)
        return 1
    return 0
コード例 #11
0
ファイル: rtfind.py プロジェクト: gbiggs/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog <search path> [options]
Find entries in the RTC tree matching given constraints.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-i', '--iname', dest='iname', action='append',
            type='string', default=[], help='Case-insensitive name pattern. '
            'This option can be specified multiple times.')
    parser.add_option('-m', '--maxdepth', dest='max_depth', action='store',
            type='int', default=0, help='Maximum depth to search down to in '
            'the tree. Set to 0 to disable. [Default: %default]')
    parser.add_option('-n', '--name', dest='name', action='append',
            type='string', default=[], help='Case-sensitive name pattern. '
            'This option can be specified multiple times.')
    parser.add_option('-t', '--type', dest='type', action='store',
            type='string', default='', help='Type of object: c (component), '
            'd (directory), m (manager), n (name server), z (zombie). '
            'Multiple types can be specified in a single entry, e.g. '
            '"--type=dmn".')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if len(args) == 1:
        cmd_path = args[0]
    else:
        print(usage, file=sys.stderr)
        return 1
    full_path = path.cmd_path_to_full_path(cmd_path)

    matches = []
    try:
        matches = search(cmd_path, full_path, options, tree)
        for m in matches:
            print(m)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #12
0
ファイル: rtdoc.py プロジェクト: gbiggs/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] <path>
Display component documentation.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-f', '--format', dest='format', type='choice',
            choices=('rst', 'html', 'latex'), default='html',
            help='Output format (one of "rst", "html" or "latex"). '
            '[Default: %default]')
    parser.add_option('-g', '--graph', dest='graph', action='store_true',
            default=False,
            help='Draw component graph. [Default: %default]')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if not args:
        # If no path given then can't do anything.
        print('{0}: No component specified.'.format(os.path.basename(sys.argv[0])),
                file=sys.stderr)
        return 1
    elif len(args) == 1:
        cmd_path = args[0]
    else:
        print >>sys.stderr, usage
        return 1
    full_path = path.cmd_path_to_full_path(cmd_path)

    try:
        docs = '\n'.join(get_docs(cmd_path, full_path, options, tree=tree))
        if options.format == 'rst':
            print(docs)
        else:
            print(docutils.core.publish_string(docs,
                writer_name=options.format))
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #13
0
ファイル: rtfind.py プロジェクト: n-kawauchi/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog <search path> [options]
Find entries in the RTC tree matching given constraints.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-i', '--iname', dest='iname', action='append',
            type='string', default=[], help='Case-insensitive name pattern. '
            'This option can be specified multiple times.')
    parser.add_option('-m', '--maxdepth', dest='max_depth', action='store',
            type='int', default=0, help='Maximum depth to search down to in '
            'the tree. Set to 0 to disable. [Default: %default]')
    parser.add_option('-n', '--name', dest='name', action='append',
            type='string', default=[], help='Case-sensitive name pattern. '
            'This option can be specified multiple times.')
    parser.add_option('-t', '--type', dest='type', action='store',
            type='string', default='', help='Type of object: c (component), '
            'd (directory), m (manager), n (name server), z (zombie). '
            'Multiple types can be specified in a single entry, e.g. '
            '"--type=dmn".')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if len(args) == 1:
        cmd_path = args[0]
    else:
        print(usage, file=sys.stderr)
        return 1
    full_path = path.cmd_path_to_full_path(cmd_path)

    matches = []
    try:
        matches = search(cmd_path, full_path, options, tree)
        for m in matches:
            print(m)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #14
0
ファイル: rtprint.py プロジェクト: gbiggs/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] <path1>:<port1> [<path2>:<port2>...]
Print the data being sent by one or more output ports.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-m', '--mod', dest='modules', action='append',
            type='string', default=[],
            help='Extra modules to import. If automatic module loading '\
            'struggles with your data types, try listing the modules here. '\
            'The module and its __POA partner will be imported.')
    parser.add_option('-n', '--number', dest='max', action='store',
            type='int', default='-1', help='Specify the number of times to '\
            'read from any ports. [Default: infinity]')
    parser.add_option('-p', '--path', dest='paths', action='append',
            type='string', default=[],
            help='Extra module search paths to add to the PYTHONPATH.')
    parser.add_option('-r', '--rate', dest='rate', action='store',
            type='float', default=100.0, help='Specify the rate in Hertz at '\
            'which to read and print. [Default: %default]')
    parser.add_option('-t', '--timeout', dest='timeout', action='store',
            type='float', default=-1, help='Read data for this many seconds, '\
            'then stop. Specify -1 for no timeout. This option overrides '\
            '--number. [Default: %default]')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if len(args) < 1:
        print(usage, file=sys.stderr)
        return 1

    try:
        read_from_ports(
                [path.cmd_path_to_full_path(p) for p in args], options, tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #15
0
ファイル: rtls.py プロジェクト: bchretien/rtshell
def main(argv=None, tree=None):
    usage = """Usage: %prog [options] [path]
List a name server, directory, manager or component."""
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option("-l", dest="long", action="store_true", default=False, help="Use a long listing format.")
    parser.add_option(
        "-R",
        "--recurse",
        dest="recurse",
        action="store_true",
        default=False,
        help="List recursively. [Default: %default]",
    )
    parser.add_option(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="Output verbose information. [Default: %default]",
    )

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print("OptionError:", e, file=sys.stderr)
        return 1, []

    if not args:
        cmd_path = ""
    elif len(args) == 1:
        cmd_path = args[0]
    else:
        print(usage, file=sys.stderr)
        return 1, []
    full_path = path.cmd_path_to_full_path(cmd_path)

    result = []
    try:
        result = list_target(cmd_path, full_path, options, tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print("{0}: {1}".format(os.path.basename(sys.argv[0]), e), file=sys.stderr)
        return 1, []
    return 0, result
コード例 #16
0
ファイル: rtwatch.py プロジェクト: gbiggs/rtshell
def main(argv=None, tree=None):
    parser = argparse.ArgumentParser(prog="rtwatch", description="Watch a component event.")
    filterkind = filtermap.keys()
    filterkind.insert(0, "ALL")
    parser.add_argument(
        "-n",
        "--number",
        dest="number",
        action="store",
        type=int,
        default=-1,
        help="Number of events to capture. [Default: %(default)s]",
    )
    parser.add_argument(
        "-f",
        "--filter",
        dest="filters",
        action="append",
        type=str,
        choices=filterkind,
        default=[],
        help="Event source filters. [Default: ALL]",
    )
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="Output verbose information. [Default: %(default)s]",
    )
    parser.add_argument("path", metavar="path", type=str, nargs="+", help="Path to component.")

    if argv:
        sys.argv = [sys.argv[0]] + argv

    options = parser.parse_args()

    paths = [[p, path.cmd_path_to_full_path(p)] for p in options.path]

    try:
        print_logs(paths, options, tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print("{0}: {1}".format(os.path.basename(sys.argv[0]), e), file=sys.stderr)
        return 1
    return 0
コード例 #17
0
ファイル: rtcat.py プロジェクト: win-katami/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] [path]
Display information about a manager or component.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-l', dest='long', action='count', default=0,
            help='Show more information. Specify multiple times for even '\
            'more information. [Default: False]')
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      default=False,
                      help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print >> sys.stderr, 'OptionError:', e
        return 1

    if not args:
        # If no path given then can't do anything.
        print('{0}: Cannot cat a directory.'.format(
            os.path.basename(sys.argv[0])),
              file=sys.stderr)
        return 1
    elif len(args) == 1:
        cmd_path = args[0]
    else:
        print(usage, file=sys.stderr)
        return 1
    full_path = path.cmd_path_to_full_path(cmd_path)

    try:
        output = cat_target(cmd_path, full_path, options, tree=tree)
        for l in output:
            print(l)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
              file=sys.stderr)
        return 1
    return 0
コード例 #18
0
ファイル: rtdel.py プロジェクト: gbiggs/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] <path>
Delete an object from a name server.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')
    parser.add_option('-z', '--zombies', dest='zombies', action='store_true',
            default=False, help='Delete only zombies. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    try:
        if not args:
            if not options.zombies:
                print('{0}: No path given.'.format(sys.argv[0]),
                        file=sys.stderr)
                return 1
            else:
                # If no path given, delete all zombies found
                delete_all_zombies(options, tree)
        elif len(args) == 1:
            full_path = path.cmd_path_to_full_path(args[0])
            # Some sanity checks
            if full_path == '/':
                print('{0}: Cannot delete the root directory.'.format(sys.argv[0]),
                        file=sys.stderr)
                return 1
            delete_object_reference(args[0], full_path, options, tree)
        else:
            print(usage, file=sys.stderr)
            return 1
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #19
0
ファイル: rtcat.py プロジェクト: yosuke/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] [path]
Display information about a manager or component.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-l', dest='long', action='count', default=0,
            help='Show more information. Specify multiple times for even '\
            'more information. [Default: False]')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print >>sys.stderr, 'OptionError:', e
        return 1

    if not args:
        # If no path given then can't do anything.
        print('{0}: Cannot cat a directory.'.format(
                os.path.basename(sys.argv[0])), file=sys.stderr)
        return 1
    elif len(args) == 1:
        cmd_path = args[0]
    else:
        print(usage, file=sys.stderr)
        return 1
    full_path = path.cmd_path_to_full_path(cmd_path)

    try:
        output = cat_target(cmd_path, full_path, options, tree=tree)
        for l in output:
            print(l)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #20
0
ファイル: rtexit.py プロジェクト: n-kawauchi/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] <path>
Make a component exit.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      default=False,
                      help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if not args:
        # If no path given then can't do anything.
        print('{0}: No component specified.'.format(
            os.path.basename(sys.argv[0])),
              file=sys.stderr)
        return 1
    elif len(args) == 1:
        cmd_path = args[0]
    else:
        print(usage, file=sys.stderr)
        return 1
    full_path = path.cmd_path_to_full_path(cmd_path)

    try:
        exit_target(cmd_path, full_path, options, tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
              file=sys.stderr)
        return 1
    return 0
コード例 #21
0
ファイル: rtls.py プロジェクト: gbiggs/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] [path]
List a name server, directory, manager or component.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-l', dest='long', action='store_true', default=False,
            help='Use a long listing format.')
    parser.add_option('-R', '--recurse', dest='recurse', action='store_true',
            default=False, help='List recursively. [Default: %default]')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if not args:
        cmd_path = ''
    elif len(args) == 1:
        cmd_path = args[0]
    else:
        print(usage, file=sys.stderr)
        return 1
    full_path = path.cmd_path_to_full_path(cmd_path)

    result = []
    try:
        result = list_target(cmd_path, full_path, options, tree)
        for l in result:
            print(l)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #22
0
def base_main(description, action, argv=None, tree=None):
    usage = '''Usage: %prog [options] <path> [<path> ...]
{0}'''.format(description)
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-e', '--exec_context', dest='ec_index', type='int',
            action='store', default=0, help='Index of the execution context '\
            'to change state in. [Default: %default]')
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      default=False,
                      help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if not args:
        # If no path given then can't do anything.
        print('{0}: No components specified.'.format(
            os.path.basename(sys.argv[0])),
              file=sys.stderr)
        return 1
    paths = [(p, path.cmd_path_to_full_path(p)) for p in args]

    try:
        alter_component_states(action, paths, options, tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
              file=sys.stderr)
        return 1
    return 0
コード例 #23
0
ファイル: rtexit.py プロジェクト: gbiggs/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] <path>
Make a component exit.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if not args:
        # If no path given then can't do anything.
        print('{0}: No component specified.'.format(
                os.path.basename(sys.argv[0])), file=sys.stderr)
        return 1
    elif len(args) == 1:
        cmd_path = args[0]
    else:
        print(usage, file=sys.stderr)
        return 1
    full_path = path.cmd_path_to_full_path(cmd_path)

    try:
        exit_target(cmd_path, full_path, options, tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #24
0
def base_main(description, action, argv=None, tree=None):
    usage = '''Usage: %prog [options] <path> [<path> ...]
{0}'''.format(description)
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-e', '--exec_context', dest='ec_index', type='int',
            action='store', default=0, help='Index of the execution context '\
            'to change state in. [Default: %default]')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if not args:
        # If no path given then can't do anything.
        print('{0}: No components specified.'.format(
                os.path.basename(sys.argv[0])), file=sys.stderr)
        return 1
    paths = [(p, path.cmd_path_to_full_path(p)) for p in args]

    try:
        alter_component_states(action, paths, options, tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #25
0
ファイル: rtlog.py プロジェクト: ysuga/rtshell
            '[Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >>sys.stderr, 'OptionError:', e
        return 1

    if len(args) < 1 and not options.display_info:
        print >>sys.stderr, usage
        return 1

    try:
        if options.display_info:
            display_info(options)
        elif options.play:
            play_log([path.cmd_path_to_full_path(p) for p in args],
                    options, tree)
        else:
            record_log([path.cmd_path_to_full_path(p) for p in args],
                    options, tree)
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >>sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]), e)
        return 1
    return 0

コード例 #26
0
ファイル: rtinject.py プロジェクト: gbiggs/rtshell
def main(argv=None, tree=None):
    usage = """Usage: %prog [options] <path1>:<port1> [<path2>:<port2>...]
Write a constant value to one or more ports."""
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option(
        "-c",
        "--const",
        dest="const",
        action="store",
        type="string",
        default="",
        help="The constant value to send, as a Python expression. If "
        "not specified, values will be read from standard in.",
    )
    parser.add_option(
        "-m",
        "--mod",
        dest="modules",
        action="append",
        type="string",
        default=[],
        help="Extra modules to import. If automatic module loading "
        "struggles with your data types, try listing the modules here. "
        "The module and its __POA partner will be imported.",
    )
    parser.add_option(
        "-n",
        "--number",
        dest="max",
        action="store",
        type="int",
        default="1",
        help="Specify the number of times to write to the port. " "[Default: %default]",
    )
    parser.add_option(
        "-p",
        "--path",
        dest="paths",
        action="append",
        type="string",
        default=[],
        help="Extra module search paths to add to the PYTHONPATH.",
    )
    parser.add_option(
        "-r",
        "--rate",
        dest="rate",
        action="store",
        type="float",
        default=1.0,
        help="Specify the rate in Hertz at which to emit data. " "[Default: %default]",
    )
    parser.add_option(
        "-t",
        "--timeout",
        dest="timeout",
        action="store",
        type="float",
        default=-1,
        help="Write data for this many seconds, " "then stop. This option overrides --number. [Default: %default]",
    )
    parser.add_option(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="Output verbose information. [Default: %default]",
    )

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print("OptionError:", e, file=sys.stderr)
        return 1

    if len(args) < 1:
        print(usage, file=sys.stderr)
        return 1

    try:
        write_to_ports([path.cmd_path_to_full_path(p) for p in args], options, tree=tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print("{0}: {1}".format(os.path.basename(sys.argv[0]), e), file=sys.stderr)
        return 1
    return 0
コード例 #27
0
            '[Default: %default]')
    parser.add_option('-t', '--timeout', dest='timeout', action='store',
            type='float', default=-1, help='Write data for this many seconds, '
            'then stop. This option overrides --number. [Default: %default]')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >>sys.stderr, 'OptionError:', e
        return 1

    if len(args) < 1:
        print >>sys.stderr, usage
        return 1

    try:
        write_to_ports([path.cmd_path_to_full_path(p) \
                for p in args], options, tree=tree)
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >>sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]), e)
        return 1
    return 0

コード例 #28
0
ファイル: rtlog.py プロジェクト: win-katami/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] <path1>:<port1> [<path2>:<port2>...]
Record data from output ports, or replay data into input ports.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option(
        '-a',
        '--absolute-times',
        dest='abs_times',
        action='store_true',
        default=False,
        help='Times from the logged data are sent as recorded during '
        'replay, rather than adjusted to the current timeframe. '
        '[Default: %default]')
    parser.add_option('-d',
                      '--display-info',
                      dest='display_info',
                      action='store_true',
                      default=False,
                      help='Display the log '
                      'information and exit.')
    parser.add_option(
        '-e',
        '--end',
        dest='end',
        action='store',
        type='float',
        default=None,
        help='Time or entry index to stop recording or playback. Must be '
        'within the bounds of the log. Specify -1 to record forever or '
        'replay to the end of the log. Use --index to specify that this '
        'value is an index. [Default: %default]')
    parser.add_option(
        '-f',
        '--filename',
        dest='filename',
        action='store',
        type='string',
        default='',
        help='File name of the log file to '
        'record to/playback from. If not specified for recording, a '
        'default will be created based on the current time. Must be '
        'specified for playback.')
    parser.add_option('--path',
                      dest='paths',
                      action='append',
                      type='string',
                      default=[],
                      help='Extra module search paths to add to the '
                      'PYTHONPATH.')
    parser.add_option('-i',
                      '--index',
                      dest='index',
                      action='store_true',
                      default=False,
                      help='Interpret the start and end values as entry '
                      'indices. [Default: %default]')
    parser.add_option(
        '-l',
        '--logger',
        dest='logger',
        action='store',
        type='string',
        default='simpkl',
        help='The type of logger to '
        'use. The default is the SimplePickle logger. Alternatively, '
        'the text logger (specify using "text") may be used. The text '
        'logger does not support playback.')
    parser.add_option(
        '-m',
        '--mod',
        dest='modules',
        action='append',
        type='string',
        default=[],
        help='Extra modules to import. If automatic module loading '
        'struggles with your data types, try listing the modules here. '
        'The module and its __POA partner will be imported.')
    parser.add_option(
        '-n',
        '--ignore-times',
        dest='ig_times',
        action='store_true',
        default=False,
        help='Ignore the log '
        'timestamps and play back a fixed number of entries per '
        'execution. Use --rate to change the number played back per '
        'execution. The value of --rate will be treated as an integer '
        'in this case.')
    parser.add_option('-p',
                      '--play',
                      dest='play',
                      action='store_true',
                      default=False,
                      help='Replay mode. [Default: %default]')
    parser.add_option(
        '-r',
        '--rate',
        dest='rate',
        action='store',
        type='float',
        default=1.0,
        help='Scale the playback speed of the log. [Default: %default]')
    parser.add_option(
        '-s',
        '--start',
        dest='start',
        action='store',
        type='float',
        default=None,
        help='Time or entry index to start playback from. Must be within '
        'the bounds of the log. Use --index to specify that this value '
        'is an index. [Default: %default]')
    parser.add_option('-t',
                      '--timeout',
                      dest='timeout',
                      action='store',
                      type='float',
                      default=None,
                      help='Record/replay data for this '
                      'many seconds. This option overrides --start/--end.')
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      default=False,
                      help='Output verbose information. [Default: %default]')
    parser.add_option(
        '-x',
        '--exec-rate',
        dest='exec_rate',
        action='store',
        type='float',
        default=100.0,
        help='Specify the rate in Hertz at which to run the component. '
        '[Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if len(args) < 1 and not options.display_info:
        print(usage, file=sys.stderr)
        return 1

    try:
        if options.display_info:
            display_info(options)
        elif options.play:
            play_log([path.cmd_path_to_full_path(p) for p in args], options,
                     tree)
        else:
            record_log([path.cmd_path_to_full_path(p) for p in args], options,
                       tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
              file=sys.stderr)
        return 1
    return 0
コード例 #29
0
def main(argv=None, tree=None):
    def property_callback(option, opt, option_value, parser):
        if option_value.count('=') != 1:
            raise optparse.OptionValueError(
                'Bad property format: {0}'.format(option_value))
        key, equals, value = option_value.partition('=')
        if not getattr(parser.values, option.dest):
            setattr(parser.values, option.dest, {})
        if key in getattr(parser.values, option.dest):
            print('{0}: Warning: duplicate property: {1}'.format(
                sys.argv[0], option_value),
                  file=sys.stderr)
        getattr(parser.values, option.dest)[key] = value

    usage = '''Usage: %prog [options] <path 1> <path 2> [<path 3> ...]
Connect two or more ports.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-d',
                      '--no-duplicates',
                      dest='no_dups',
                      action='store_true',
                      help='Prevent duplicate connections')
    parser.add_option('-i',
                      '--id',
                      dest='id',
                      action='store',
                      type='string',
                      default='',
                      help='ID of the connection. [Default: %default]')
    parser.add_option('-n',
                      '--name',
                      dest='name',
                      action='store',
                      type='string',
                      default=None,
                      help='Name of the connection. [Default: %default]')
    parser.add_option('-p',
                      '--property',
                      dest='properties',
                      action='callback',
                      callback=property_callback,
                      type='string',
                      help='Connection properties.')
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      default=False,
                      help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if not getattr(options, 'properties'):
        setattr(options, 'properties', {})

    if not args:
        # If no paths given then can't do anything.
        print('{0}: No ports specified.'.format(os.path.basename(sys.argv[0])),
              file=sys.stderr)
        return 1
    paths = [(p, path.cmd_path_to_full_path(p)) for p in args]

    try:
        connect_ports(paths, options, tree=tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
              file=sys.stderr)
        return 1
    return 0
コード例 #30
0
ファイル: rtdoc.py プロジェクト: k-okada/rtshell
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >> sys.stderr, 'OptionError:', e
        return 1

    if not args:
        # If no path given then can't do anything.
        print >> sys.stderr, '{0}: No component specified.'.format(
            os.path.basename(sys.argv[0]))
        return 1
    elif len(args) == 1:
        cmd_path = args[0]
    else:
        print >> sys.stderr, usage
        return 1
    full_path = path.cmd_path_to_full_path(cmd_path)

    try:
        docs = '\n'.join(get_docs(cmd_path, full_path, options, tree=tree))
        if options.format == 'rst':
            print docs
        else:
            print docutils.core.publish_string(docs,
                                               writer_name=options.format)
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >> sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]),
                                               e)
        return 1
    return 0
コード例 #31
0
ファイル: rtvlog.py プロジェクト: ysuga/rtshell
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >>sys.stderr, 'OptionError:', e
        return 1

    if not args:
        # If no paths given then can't do anything.
        print >>sys.stderr, '{0}: No component specified.'.format(
                os.path.basename(sys.argv[0]))
        return 1
    paths = [[p, path.cmd_path_to_full_path(p)] for p in args]

    try:
        print_logs(paths, options, tree)
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >>sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]), e)
        return 1
    return 0


# vim: tw=79

コード例 #32
0
ファイル: state_control_base.py プロジェクト: k-okada/rtshell
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >>sys.stderr, 'OptionError:', e
        return 1

    if not args:
        # If no path given then can't do anything.
        print >>sys.stderr, '{0}: No components specified.'.format(
                os.path.basename(sys.argv[0]))
        return 1
    paths = [(p, path.cmd_path_to_full_path(p)) for p in args]

    try:
        alter_component_states(action, paths, options, tree)
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >>sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]), e)
        return 1
    return 0


# vim: tw=79

コード例 #33
0
ファイル: rtlog.py プロジェクト: gbiggs/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] <path1>:<port1> [<path2>:<port2>...]
Record data from output ports, or replay data into input ports.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-a', '--absolute-times', dest='abs_times',
            action='store_true', default=False,
            help='Times from the logged data are sent as recorded during '
            'replay, rather than adjusted to the current timeframe. '
            '[Default: %default]')
    parser.add_option('-d', '--display-info', dest='display_info',
            action='store_true', default=False, help='Display the log '
            'information and exit.')
    parser.add_option('-e', '--end', dest='end', action='store', type='float',
            default=None,
            help='Time or entry index to stop recording or playback. Must be '
            'within the bounds of the log. Specify -1 to record forever or '
            'replay to the end of the log. Use --index to specify that this '
            'value is an index. [Default: %default]')
    parser.add_option('-f', '--filename', dest='filename', action='store',
            type='string', default='', help='File name of the log file to '
            'record to/playback from. If not specified for recording, a '
            'default will be created based on the current time. Must be '
            'specified for playback.')
    parser.add_option('--path', dest='paths', action='append', type='string',
            default=[], help='Extra module search paths to add to the '
            'PYTHONPATH.')
    parser.add_option('-i', '--index', dest='index', action='store_true',
            default=False, help='Interpret the start and end values as entry '
            'indices. [Default: %default]')
    parser.add_option('-l', '--logger', dest='logger', action='store',
            type='string', default='simpkl', help='The type of logger to '
            'use. The default is the SimplePickle logger. Alternatively, '
            'the text logger (specify using "text") may be used. The text '
            'logger does not support playback.')
    parser.add_option('-m', '--mod', dest='modules', action='append',
            type='string', default=[],
            help='Extra modules to import. If automatic module loading '
            'struggles with your data types, try listing the modules here. '
            'The module and its __POA partner will be imported.')
    parser.add_option('-n', '--ignore-times', dest='ig_times',
            action='store_true', default=False, help='Ignore the log '
            'timestamps and play back a fixed number of entries per '
            'execution. Use --rate to change the number played back per '
            'execution. The value of --rate will be treated as an integer '
            'in this case.')
    parser.add_option('-p', '--play', dest='play', action='store_true',
            default=False, help='Replay mode. [Default: %default]')
    parser.add_option('-r', '--rate', dest='rate', action='store',
            type='float', default=1.0,
            help='Scale the playback speed of the log. [Default: %default]')
    parser.add_option('-s', '--start', dest='start', action='store',
            type='float', default=None,
            help='Time or entry index to start playback from. Must be within '
            'the bounds of the log. Use --index to specify that this value '
            'is an index. [Default: %default]')
    parser.add_option('-t', '--timeout', dest='timeout', action='store',
            type='float', default=None, help='Record/replay data for this '
            'many seconds. This option overrides --start/--end.')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')
    parser.add_option('-x', '--exec-rate', dest='exec_rate', action='store',
            type='float', default=100.0,
            help='Specify the rate in Hertz at which to run the component. '
            '[Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if len(args) < 1 and not options.display_info:
        print(usage, file=sys.stderr)
        return 1

    try:
        if options.display_info:
            display_info(options)
        elif options.play:
            play_log([path.cmd_path_to_full_path(p) for p in args],
                    options, tree)
        else:
            record_log([path.cmd_path_to_full_path(p) for p in args],
                    options, tree)
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    return 0
コード例 #34
0
ファイル: rtls.py プロジェクト: ysuga/rtshell
    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >>sys.stderr, 'OptionError:', e
        return 1, []

    if not args:
        cmd_path = ''
    elif len(args) == 1:
        cmd_path = args[0]
    else:
        print >>sys.stderr, usage
        return 1, []
    full_path = path.cmd_path_to_full_path(cmd_path)

    result = []
    try:
        result = list_target(cmd_path, full_path, options, tree)
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >>sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]), e)
        return 1, []
    return 0, result


# vim: tw=79

コード例 #35
0
        '[Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >> sys.stderr, 'OptionError:', e
        return 1

    if len(args) < 1 and not options.display_info:
        print >> sys.stderr, usage
        return 1

    try:
        if options.display_info:
            display_info(options)
        elif options.play:
            play_log([path.cmd_path_to_full_path(p) for p in args], options,
                     tree)
        else:
            record_log([path.cmd_path_to_full_path(p) for p in args], options,
                       tree)
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >> sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]),
                                               e)
        return 1
    return 0
コード例 #36
0
ファイル: rtprint.py プロジェクト: tnaka/rtshell
            '--number. [Default: %default]')
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      default=False,
                      help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >> sys.stderr, 'OptionError:', e
        return 1

    if len(args) < 1:
        print >> sys.stderr, usage
        return 1

    try:
        read_from_ports([path.cmd_path_to_full_path(p) for p in args], options,
                        tree)
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >> sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]),
                                               e)
        return 1
    return 0
コード例 #37
0
ファイル: rtdis.py プロジェクト: tnaka/rtshell
                      default=False,
                      help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >> sys.stderr, 'OptionError:', e
        return 1

    try:
        if len(args) == 1:
            # Disconnect all
            cmd_path = args[0]
            disconnect_all(cmd_path, path.cmd_path_to_full_path(cmd_path),
                           options, tree)
        elif len(args) > 1:
            # Disconnect a set of ports
            paths = [(p, path.cmd_path_to_full_path(p)) for p in args]
            disconnect_ports(paths, options, tree)
        else:
            print >> sys.stderr, usage
            return 1
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >> sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]),
                                               e)
        return 1
    return 0
コード例 #38
0
ファイル: rtprint.py プロジェクト: gitter-badger/rtshell
    parser.add_option('-t', '--timeout', dest='timeout', action='store',
            type='float', default=-1, help='Read data for this many seconds, '\
            'then stop. Specify -1 for no timeout. This option overrides '\
            '--number. [Default: %default]')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >>sys.stderr, 'OptionError:', e
        return 1

    if len(args) < 1:
        print >>sys.stderr, usage
        return 1

    try:
        read_from_ports(
                [path.cmd_path_to_full_path(p) for p in args], options, tree)
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >>sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]), e)
        return 1
    return 0

コード例 #39
0
ファイル: rtprint.py プロジェクト: ysuga/rtshell
    parser.add_option('-t', '--timeout', dest='timeout', action='store',
            type='float', default=-1, help='Read data for this many seconds, '\
            'then stop. Specify -1 for no timeout. This option overrides '\
            '--number. [Default: %default]')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >>sys.stderr, 'OptionError:', e
        return 1

    if len(args) < 1:
        print >>sys.stderr, usage
        return 1

    try:
        read_from_ports(
                [path.cmd_path_to_full_path(p) for p in args], options, tree)
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >>sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]), e)
        return 1
    return 0

コード例 #40
0
ファイル: rtdel.py プロジェクト: k-okada/rtshell
    try:
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >>sys.stderr, 'OptionError:', e
        return 1

    try:
        if not args:
            if not options.zombies:
                print >>sys.stderr, '{0}: No path given.'.format(sys.argv[0])
                return 1
            else:
                # If no path given, delete all zombies found
                delete_all_zombies(options, tree)
        elif len(args) == 1:
            full_path = path.cmd_path_to_full_path(args[0])
            # Some sanity checks
            if full_path == '/':
                print >>sys.stderr, '{0}: Cannot delete the root '\
                        'directory.'.format(sys.argv[0])
                return 1
            delete_object_reference(args[0], full_path, options, tree)
        else:
            print >>sys.stderr, usage
            return 1
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >>sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]), e)
        return 1
    return 0
コード例 #41
0
ファイル: rtconf.py プロジェクト: bchretien/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog <path> [options] [command] [args]
Display and edit configuration parameters and sets.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-a', '--all', dest='all', action='store_true',
            default=False,
            help='Do not ignore hidden sets. [Default: %default]')
    parser.add_option('-l', dest='long', action='store_true', default=False,
            help='Show more information. [Default: %default]')
    parser.add_option('-s', '--set', dest='set_name', action='store',
            default='', help='Choose the configuration set to manipulate. '\
            '[Default: %default]')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1, []

    if not args:
        print(usage, file=sys.stderr)
        return 1, []
    elif len(args) == 1:
        cmd_path = args[0]
        cmd = 'list'
        args = args[1:]
    else:
        cmd_path = args[0]
        cmd = args[1]
        args = args[2:]
    full_path = path.cmd_path_to_full_path(cmd_path)

    result = []
    try:
        if cmd == 'list':
            # Print the configuration sets
            result = print_conf_sets(cmd_path, full_path, options, tree)
        elif cmd == 'set':
            # Need to get more arguments
            if len(args) == 2:
                param = args[0]
                new_value = args[1]
            else:
                print(usage, file=sys.stderr)
                return 1, []
            set_conf_value(param, new_value, cmd_path, full_path, options,
                    tree)
        elif cmd == 'get':
            #Need to get more arguments
            if len(args) == 1:
                param = args[0]
            else:
                print(usage, file=sys.stderr)
                return 1, []
            result = get_conf_value(param, cmd_path, full_path, options, tree)
        elif cmd == 'act':
            if len(args) != 0 or options.set_name == '':
                print(usage, file=sys.stderr)
                return 1, []
            activate_set(cmd_path, full_path, options, tree)
        else:
            print(usage, file=sys.stderr)
            return 1, []
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1, []
    return 0, result
コード例 #42
0
ファイル: rtdoc.py プロジェクト: win-katami/rtshell
def main(argv=None, tree=None):
    usage = '''Usage: %prog [options] <path>
Display component documentation.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-f',
                      '--format',
                      dest='format',
                      type='choice',
                      choices=('rst', 'html', 'latex'),
                      default='html',
                      help='Output format (one of "rst", "html" or "latex"). '
                      '[Default: %default]')
    parser.add_option('-g',
                      '--graph',
                      dest='graph',
                      action='store_true',
                      default=False,
                      help='Draw component graph. [Default: %default]')
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      default=False,
                      help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if not args:
        # If no path given then can't do anything.
        print('{0}: No component specified.'.format(
            os.path.basename(sys.argv[0])),
              file=sys.stderr)
        return 1
    elif len(args) == 1:
        cmd_path = args[0]
    else:
        print >> sys.stderr, usage
        return 1
    full_path = path.cmd_path_to_full_path(cmd_path)

    try:
        docs = '\n'.join(get_docs(cmd_path, full_path, options, tree=tree))
        if options.format == 'rst':
            print(docs)
        else:
            print(
                docutils.core.publish_string(docs, writer_name=options.format))
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
              file=sys.stderr)
        return 1
    return 0
コード例 #43
0
    try:
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >> sys.stderr, 'OptionError:', e
        return 1

    try:
        if not args:
            if not options.zombies:
                print >> sys.stderr, '{0}: No path given.'.format(sys.argv[0])
                return 1
            else:
                # If no path given, delete all zombies found
                delete_all_zombies(options, tree)
        elif len(args) == 1:
            full_path = path.cmd_path_to_full_path(args[0])
            # Some sanity checks
            if full_path == '/':
                print >>sys.stderr, '{0}: Cannot delete the root '\
                        'directory.'.format(sys.argv[0])
                return 1
            delete_object_reference(args[0], full_path, options, tree)
        else:
            print >> sys.stderr, usage
            return 1
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >> sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]),
                                               e)
        return 1
コード例 #44
0
def main(argv=None, tree=None):
    usage = '''Usage: %prog <path> [options] [command] [args]
Display and edit configuration parameters and sets.'''
    version = rtshell.RTSH_VERSION
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option('-a', '--all', dest='all', action='store_true',
            default=False,
            help='Do not ignore hidden sets. [Default: %default]')
    parser.add_option('-l', dest='long', action='store_true', default=False,
            help='Show more information. [Default: %default]')
    parser.add_option('-s', '--set', dest='set_name', action='store',
            default='', help='Choose the configuration set to manipulate. '\
            '[Default: %default]')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError as e:
        print('OptionError:', e, file=sys.stderr)
        return 1

    if not args:
        print(usage, file=sys.stderr)
        return 1
    elif len(args) == 1:
        cmd_path = args[0]
        cmd = 'list'
        args = args[1:]
    else:
        cmd_path = args[0]
        cmd = args[1]
        args = args[2:]
    full_path = path.cmd_path_to_full_path(cmd_path)

    result = []
    try:
        if cmd == 'list':
            # Print the configuration sets
            result = print_conf_sets(cmd_path, full_path, options, tree)
        elif cmd == 'set':
            # Need to get more arguments
            if len(args) == 2:
                param = args[0]
                new_value = args[1]
            else:
                print(usage, file=sys.stderr)
                return 1
            set_conf_value(param, new_value, cmd_path, full_path, options,
                    tree)
        elif cmd == 'get':
            #Need to get more arguments
            if len(args) == 1:
                param = args[0]
            else:
                print(usage, file=sys.stderr)
                return 1
            result = get_conf_value(param, cmd_path, full_path, options, tree)
        elif cmd == 'act':
            if len(args) != 0 or options.set_name == '':
                print(usage, file=sys.stderr)
                return 1
            activate_set(cmd_path, full_path, options, tree)
        else:
            print(usage, file=sys.stderr)
            return 1
    except Exception as e:
        if options.verbose:
            traceback.print_exc()
        print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e),
                file=sys.stderr)
        return 1
    for l in result:
        print(l)
    return 0
コード例 #45
0
                      default=False,
                      help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >> sys.stderr, 'OptionError:', e
        return 1

    if not args:
        # If no paths given then can't do anything.
        print >> sys.stderr, '{0}: No component specified.'.format(
            os.path.basename(sys.argv[0]))
        return 1
    paths = [[p, path.cmd_path_to_full_path(p)] for p in args]

    try:
        print_logs(paths, options, tree)
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >> sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]),
                                               e)
        return 1
    return 0


# vim: tw=79
コード例 #46
0
ファイル: rtdis.py プロジェクト: gitter-badger/rtshell
            default=False,
            help='Output verbose information. [Default: %default]')

    if argv:
        sys.argv = [sys.argv[0]] + argv
    try:
        options, args = parser.parse_args()
    except optparse.OptionError, e:
        print >>sys.stderr, 'OptionError:', e
        return 1

    try:
        if len(args) == 1:
            # Disconnect all
            cmd_path = args[0]
            disconnect_all(cmd_path, path.cmd_path_to_full_path(cmd_path),
                                  options, tree)
        elif len(args) > 1:
            # Disconnect a set of ports
            paths = [(p, path.cmd_path_to_full_path(p)) for p in args]
            disconnect_ports(paths, options, tree)
        else:
            print >>sys.stderr, usage
            return 1
    except Exception, e:
        if options.verbose:
            traceback.print_exc()
        print >>sys.stderr, '{0}: {1}'.format(os.path.basename(sys.argv[0]), e)
        return 1
    return 0