6 Copyright (C) 2009-2014 8 RT-Synthesis Research Group 9 Intelligent Systems Research Institute, 10 National Institute of Advanced Industrial Science and Technology (AIST), 13 Licensed under the Eclipse Public License -v 1.0 (EPL) 14 http://www.opensource.org/licenses/eclipse-1.0.txt 16 Objects and functions used to build and store a tree representing a hierarchy 17 of name servers, directories, managers and components. 22 from omniORB
import any
31 term_attributes = {
'reset':
'00',
60 from traceback
import extract_stack
63 '''Build a string that will turn any ANSI shell output the desired 66 attrs should be a list of keys into the term_attributes table. 71 if type(attrs) == str:
75 result += term_attributes[attr] +
';' 76 return result[:-1] +
'm' 80 if sys.platform ==
'win32':
86 '''Given a list of string widths, a width of the minimum gap to place 87 between them, and the maximum width of the output (such as a terminal 88 width), calculate the number of columns and rows, and the width of each 89 column, for the optimal layout. 92 def calc_longest_width(widths, gap_width, ncols):
94 rows = [widths[s:s + ncols]
for s
in range(0, len(widths), ncols)]
97 for ii, c
in enumerate(r):
98 if c > col_widths[ii]:
100 length = sum(col_widths) + gap_width * (ncols - 1)
103 return longest, col_widths
105 def calc_num_rows(num_items, cols):
106 div, mod = divmod(num_items, cols)
107 return div + (mod != 0)
115 longest_width, col_widths = calc_longest_width(widths, gap_width, ncols)
116 if longest_width < term_width:
118 return calc_num_rows(len(widths), ncols), ncols, col_widths
123 return len(widths), 1, 0
127 '''Finds the width of the terminal, or returns a suitable default value.''' 128 def read_terminal_size_by_ioctl(fd):
130 import struct, fcntl, termios
131 cr = struct.unpack(
'hh', fcntl.ioctl(1, termios.TIOCGWINSZ,
139 cr = read_terminal_size_by_ioctl(0)
or \
140 read_terminal_size_by_ioctl(1)
or \
141 read_terminal_size_by_ioctl(2)
145 fd = os.open(os.ctermid(), os.O_RDONLY)
146 cr = read_terminal_size_by_ioctl(fd)
153 if os.getenv(
'ROWS'):
154 cr[1] = int(os.getenv(
'ROWS'))
155 if os.getenv(
'COLUMNS'):
156 cr[0] = int(os.getenv(
'COLUMNS'))
162 '''Convert a dictionary into a CORBA namevalue list.''' 164 for item
in dict.keys() :
165 result.append(SDOPackage.NameValue(item, any.to_any(dict[item])))
170 '''Convert a CORBA namevalue list into a dictionary.''' 173 result[item.name] = item.value.value()
178 '''Check if a path is removed by a filter. 180 Check if a path is in the provided set of paths, @ref filter. If 181 none of the paths in filter begin with @ref path, then True is 182 returned to indicate that the path is filtered out. If @ref path is 183 longer than the filter, and starts with the filter, it is 184 considered unfiltered (all paths below a filter are unfiltered). 186 An empty filter ([]) is treated as not filtering any. 192 if len(path) > len(p):
193 if path[:len(p)] == p:
196 if p[:len(path)] == path:
202 '''Trim @ref levels levels from the front of each path in @filter.''' 203 trimmed = [f[levels:]
for f
in filter]
204 return [f
for f
in trimmed
if f]
def colour_supported(term)
def trim_filter(filter, levels=1)
def filtered(path, filter)
def get_num_columns_and_rows(widths, gap_width, term_width)
def build_attr_string(attrs, supported=True)
def nvlist_to_dict(nvlist)