Ejemplo n.º 1
0
def delete_all_zombies(options, tree=None):
    if not tree:
        tree = rtctree.tree.RTCTree()
    if not tree:
        return 1
    def del_zombie(node, args):
        try:
            node.parent.unbind(node.name)
        except Exception as e:
            if options.verbose:
                traceback.print_exc()
            print('{0}: {1}'.format(sys.argv[0], e), file=sys.stderr)
    tree.iterate(del_zombie, filter=['is_zombie'])
Ejemplo n.º 2
0
def delete_all_zombies(options, tree=None):
    if not tree:
        tree = rtctree.tree.RTCTree()
    if not tree:
        return 1

    def del_zombie(node, args):
        try:
            node.parent.unbind(node.name)
        except Exception as e:
            if options.verbose:
                traceback.print_exc()
            print('{0}: {1}'.format(sys.argv[0], e), file=sys.stderr)

    tree.iterate(del_zombie, filter=['is_zombie'])
Ejemplo n.º 3
0
def choose_name(base, tree):
    '''Choose a name for the component from a given base.

    The name is chosen such that it does not conflict with other possible
    instances of the base name by appending an index number.

    @param base The base name to append the index to.
    @param tree A populated RTCTree to search for other instances of the
                same type of component.

    '''
    def get_result(node, args):
        return int(regex.match(node.name).group(1))

    def is_gen_comp(node):
        if regex.match(node.name):
            return True
        return False

    regex = re.compile('{0}(\d+)0.rtc'.format(base))
    matches = tree.iterate(get_result, filter=['is_component', is_gen_comp])
    if not matches:
        return base + '0'
    matches.sort()
    return base + '{0}'.format(matches[-1] + 1)
Ejemplo n.º 4
0
def find_all_used_components(tree):
    # Finds all component nodes in the tree
    def get_node(node, args):
        return node
    def is_in_dir(node):
        if node.parent.is_manager:
            return False
        return True
    return [c for c in tree.iterate(get_node,
                                       filter=['is_component', is_in_dir]) \
              if c.connected_ports]
Ejemplo n.º 5
0
def find_all_used_components(tree):
    # Finds all component nodes in the tree
    def get_node(node, args):
        return node
    def is_in_dir(node):
        if node.parent.is_manager:
            return False
        return True
    return [c for c in tree.iterate(get_node,
                                       filter=['is_component', is_in_dir]) \
              if c.connected_ports]
Ejemplo n.º 6
0
def find_composite_comp(tree, member, inst_name):
    def get_fp(mgr, args):
        for c in mgr.components:
            if c.instance_name == inst_name:
                return c.full_path_str
        return None
    def is_correct_mgr(node):
        has_member = False
        has_inst_name = False
        for c in node.components:
            if c.instance_name == inst_name:
                has_inst_name = True
            elif c.instance_name == member.instance_name:
                has_member = True
        return has_member and has_inst_name
    return tree.iterate(get_fp, filter=['is_manager', is_correct_mgr])
Ejemplo n.º 7
0
def find_composite_comp(tree, member, inst_name):
    def get_fp(mgr, args):
        for c in mgr.components:
            if c.instance_name == inst_name:
                return c.full_path_str
        return None

    def is_correct_mgr(node):
        has_member = False
        has_inst_name = False
        for c in node.components:
            if c.instance_name == inst_name:
                has_inst_name = True
            elif c.instance_name == member.instance_name:
                has_member = True
        return has_member and has_inst_name

    return tree.iterate(get_fp, filter=['is_manager', is_correct_mgr])
Ejemplo n.º 8
0
def delete_all_zombies(hosts='localhost'):
    hostnames = hosts.split(',')

    tree = getRtcTree(servers=hostnames)

    if not tree:
        return False

    def del_zombie(node, args):
        try:
            name = node.name
            node.parent.unbind(node.name)
            return name
        except Exception as e:
            traceback.print_exc()
            print >> sys.stderr, '{0}: {1}'.format(sys.argv[0], e)

    return tree.iterate(del_zombie, filter=['is_zombie'])
Ejemplo n.º 9
0
def choose_name(base, tree):
    '''Choose a name for the component from a given base.

    The name is chosen such that it does not conflict with other possible
    instances of the base name by appending an index number.

    @param base The base name to append the index to.
    @param tree A populated RTCTree to search for other instances of the
                same type of component.

    '''
    def get_result(node, args):
        return int(regex.match(node.name).group(1))
    def is_gen_comp(node):
        if regex.match(node.name):
            return True
        return False
    regex = re.compile('{0}(\d+)0.rtc'.format(base))
    matches = tree.iterate(get_result, filter=['is_component', is_gen_comp])
    if not matches:
        return base + '0'
    matches.sort()
    return base + '{0}'.format(matches[-1] + 1)
Ejemplo n.º 10
0
def delete_all_zombies(options, tree=None):
    if not tree:
        tree = rtctree.tree.RTCTree()
    if not tree:
        return 1

    def del_zombie(node, args):
        try:
            node.parent.unbind(node.name)
        except Exception, e:
            if options.verbose:
                traceback.print_exc()
            print >> sys.stderr, '{0}: {1}'.format(sys.argv[0], e)

    tree.iterate(del_zombie, filter=['is_zombie'])


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',
Ejemplo n.º 11
0
    parent.unbind(path[-1])


def delete_all_zombies(options, tree=None):
    if not tree:
        tree = rtctree.tree.RTCTree()
    if not tree:
        return 1
    def del_zombie(node, args):
        try:
            node.parent.unbind(node.name)
        except Exception, e:
            if options.verbose:
                traceback.print_exc()
            print >>sys.stderr, '{0}: {1}'.format(sys.argv[0], e)
    tree.iterate(del_zombie, filter=['is_zombie'])


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