Ejemplo n.º 1
0
def format_nsview_json(tree, node):
    result = ""
    res = []
    try:
        chnode = node.children
        count = 0
        for x in chnode:
            if count > 0:
                result += ","
            path, port = rtctree.path.parse_path(x.full_path_str)
            res.append(x)
            if tree.is_directory(path):
                val = format_context(x)
                val2 = format_nsview_json(tree, x)
                result += """{ %s, "components" : [ %s]}""" % (val, val2)
            else:
                flag = 0
                if tree.is_zombie(path): flag = 1
                if tree.is_unknown(path): flag = 2
                val = format_node(x, flag)
                result += val
            count += 1
    except:
        pass

    return result
Ejemplo n.º 2
0
def format_nsview_json(tree, node):
  result = ""
  res = []
  try:
    chnode = node.children
    count = 0
    for x in chnode :
      if count > 0:
        result += ","
      path, port = rtctree.path.parse_path(x.full_path_str)
      res.append(x)
      if tree.is_directory(path) :
        val = format_context(x)
        val2 = format_nsview_json(tree,x)
        result += """{ %s, "components" : [ %s]}""" % (val, val2)
      else:
        flag = 0
        if tree.is_zombie(path) : flag = 1
        if tree.is_unknown(path) : flag = 2
        val = format_node(x, flag)
        result += val
      count += 1
  except:
    pass

  return result
Ejemplo n.º 3
0
def cd(cmd_path, full_path):
    path, port = rtctree.path.parse_path(full_path)
    if port:
        raise rts_exceptions.NotADirectoryError(cmd_path)
    if not path[-1]:
        # Remove trailing slash part
        path = path[:-1]
    tree = rtctree.tree.RTCTree(paths=path)
    if not tree.has_path(path):
        raise rts_exceptions.NotADirectoryError(cmd_path)
    if not tree.is_directory(path):
        raise rts_exceptions.NotADirectoryError(cmd_path)
    return make_cmd_line(full_path)
Ejemplo n.º 4
0
def cd(cmd_path, full_path):
    path, port = rtctree.path.parse_path(full_path)
    if port:
        raise rts_exceptions.NotADirectoryError(cmd_path)
    if not path[-1]:
        # Remove trailing slash part
        path = path[:-1]
    tree = rtctree.tree.RTCTree(paths=path)
    if not tree.has_path(path):
        raise rts_exceptions.NotADirectoryError(cmd_path)
    if not tree.is_directory(path):
        raise rts_exceptions.NotADirectoryError(cmd_path)
    return make_cmd_line(full_path)
Ejemplo n.º 5
0
def list_target(cmd_path, full_path, options, tree=None):
    use_colour = rtctree.utils.colour_supported(sys.stdout)

    path, port = rtctree.path.parse_path(full_path)
    if port:
        raise rts_exceptions.CannotDoToPortError('list')

    trailing_slash = False
    if not path[-1]:
        # There was a trailing slash
        trailing_slash = True
        path = path[:-1]

    if not tree:
        tree = rtctree.tree.RTCTree(paths=path, filter=[path])

    if not tree.has_path(path):
        raise rts_exceptions.NoSuchObjectError(cmd_path)
    if tree.is_component(path) or tree.is_unknown(path) or \
            tree.is_zombie(path):
        # Path points to a single object: print it like 'ls <file>'.
        if trailing_slash:
            # If there was a trailing slash, complain that the object is not a
            # directory.
            raise rts_exceptions.NoSuchObjectError(cmd_path)
        if options.long:
            return get_node_long_lines([tree.get_node(path)], use_colour)
        else:
            if tree.is_component(path):
                return [path[-1]]
            elif tree.is_zombie(path):
                return [(rtctree.utils.build_attr_string(['faint', 'white'],
                        supported=use_colour) + '*' + path[-1] +
                        rtctree.utils.build_attr_string(['reset'],
                        supported=use_colour))]
            else:
                # Assume unknown
                return [(rtctree.utils.build_attr_string(['faint', 'white'],
                        supported=use_colour) + path[-1] +
                        rtctree.utils.build_attr_string(['reset'],
                        supported=use_colour))]
    elif tree.is_directory(path):
        # If recursing, need to list this directory and all its children
        if options.recurse:
            recurse_root = tree.get_node(path)
            recurse_root_path = recurse_root.full_path_str
            def get_name(node, args):
                if node.full_path_str.startswith(recurse_root_path):
                    result = node.full_path_str[len(recurse_root_path):]
                else:
                    result = node.full_path_str
                return result.lstrip('/')
            dir_names = ['.'] + recurse_root.iterate(get_name,
                    args=options.long, filter=['is_directory'])[1:]
            listings = recurse_root.iterate(list_directory,
                    args=options.long, filter=['is_directory'])
            result = []
            for dir, listing in zip(dir_names, listings):
                if dir == '.':
                    result.append('.:')
                else:
                    result.append('./' + dir + ':')
                result += listing
                result.append('')
            return result
        else:
            dir_node = tree.get_node(path)
            return list_directory(dir_node, options.long)
    else:
        raise rts_exceptions.UnknownObjectError(cmd_path)
Ejemplo n.º 6
0
def list_target(cmd_path, full_path, options, tree=None):
    use_colour = rtctree.utils.colour_supported(sys.stdout)

    path, port = rtctree.path.parse_path(full_path)
    if port:
        raise rts_exceptions.CannotDoToPortError('list')

    trailing_slash = False
    if not path[-1]:
        # There was a trailing slash
        trailing_slash = True
        path = path[:-1]

    if not tree:
        tree = rtctree.tree.RTCTree(paths=path, filter=[path])

    if not tree.has_path(path):
        raise rts_exceptions.NoSuchObjectError(cmd_path)
    if tree.is_component(path) or tree.is_unknown(path) or \
            tree.is_zombie(path):
        # Path points to a single object: print it like 'ls <file>'.
        if trailing_slash:
            # If there was a trailing slash, complain that the object is not a
            # directory.
            raise rts_exceptions.NoSuchObjectError(cmd_path)
        if options.long:
            return get_node_long_lines([tree.get_node(path)], use_colour)
        else:
            if tree.is_component(path):
                return [path[-1]]
            elif tree.is_zombie(path):
                return [(rtctree.utils.build_attr_string(
                    ['faint', 'white'], supported=use_colour) + '*' +
                         path[-1] + rtctree.utils.build_attr_string(
                             ['reset'], supported=use_colour))]
            else:
                # Assume unknown
                return [(rtctree.utils.build_attr_string(
                    ['faint', 'white'], supported=use_colour) + path[-1] +
                         rtctree.utils.build_attr_string(
                             ['reset'], supported=use_colour))]
    elif tree.is_directory(path):
        # If recursing, need to list this directory and all its children
        if options.recurse:
            recurse_root = tree.get_node(path)
            recurse_root_path = recurse_root.full_path_str

            def get_name(node, args):
                if node.full_path_str.startswith(recurse_root_path):
                    result = node.full_path_str[len(recurse_root_path):]
                else:
                    result = node.full_path_str
                return result.lstrip('/')

            dir_names = ['.'] + recurse_root.iterate(
                get_name, args=options.long, filter=['is_directory'])[1:]
            listings = recurse_root.iterate(list_directory,
                                            args=options.long,
                                            filter=['is_directory'])
            result = []
            for dir, listing in zip(dir_names, listings):
                if dir == '.':
                    result.append('.:')
                else:
                    result.append('./' + dir + ':')
                result += listing
                result.append('')
            return result
        else:
            dir_node = tree.get_node(path)
            return list_directory(dir_node, options.long)
    else:
        raise rts_exceptions.UnknownObjectError(cmd_path)