1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import sys
23
24 from flumotion.common import log, common, registry
25 from flumotion.common.options import OptionParser
26
27 __version__ = "$Rev: 6125 $"
28
29
31 maxLen = 76 - indent
32 frags = data.split(' ')
33 while frags:
34 segment = frags.pop(0)
35 while frags and len(segment) + len(frags[0]) + 1 <= maxLen:
36 segment += " %s" % frags.pop(0)
37 print ' %s %s' % (' ' * indent, segment)
38
40 pname = prop.getName()
41 desc = prop.getDescription()
42 print (' %s%s: type %s, %s%s'
43 % (' '*(indent-len(pname)), pname, prop.getType(),
44 prop.isRequired() and 'required' or 'optional',
45 prop.isMultiple() and ', multiple ok' or ''))
46 if desc:
47 printMultiline(indent, desc)
48 if isinstance(prop, registry.RegistryEntryCompoundProperty):
49 subprop_names = [sp.getName() for sp in prop.getProperties()]
50 subprop_names.sort()
51 printMultiline(indent, 'subproperties: %s' %
52 ', '.join(subprop_names))
53
61
64
66 obj_class = 'Component'
67 obj_type = c.getType()
68 if not isinstance(c, registry.RegistryEntryComponent):
69 obj_class = 'Plug'
70 if not c.hasProperty(ppath[0]):
71 raise _NestedPropertyError("%s `%s' has no property `%s'." %
72 (obj_class, obj_type, ppath[0]))
73 cobj = c
74 found = []
75 while ppath:
76 cname = ppath.pop(0)
77 try:
78 cobj = cobj.properties[cname]
79 except:
80 raise _NestedPropertyError("%s `%s': property `%s' has no"
81 " subproperty `%s'." %
82 (obj_class, obj_type,
83 ':'.join(found), cname))
84 found.append(cname)
85 return cobj
86
87
89 from flumotion.common import setup
90 setup.setupPackagePath()
91
92 usage_str = ('Usage: %prog [options] [COMPONENT-OR-PLUG'
93 ' [FULL-PROPERTY-NAME]]')
94 fpname_str = ("FULL-PROPERTY-NAME: represents a fully qualified"
95 " property name, including the names of the containing"
96 " properties: "
97 "...[property-name:]property-name")
98 parser = OptionParser(usage=usage_str, description=fpname_str,
99 domain="flumotion-inspect")
100
101 log.debug('inspect', 'Parsing arguments (%r)' % ', '.join(args))
102 options, args = parser.parse_args(args)
103
104 r = registry.getRegistry()
105
106 if len(args) == 1:
107
108 components = [(c.getType(), c) for c in r.getComponents()]
109 components.sort()
110 print '\nAvailable components:\n'
111 for name, c in components:
112 print ' %s' % name
113 plugs = [(p.getType(), p) for p in r.getPlugs()]
114 plugs.sort()
115 print '\nAvailable plugs:\n'
116 for name, p in plugs:
117 print ' %s' % name
118 print
119 elif len(args) == 2:
120 cname = args[1]
121 handled = False
122 if r.hasComponent(cname):
123 handled = True
124 c = r.getComponent(cname)
125 print '\nComponent:'
126 print ' %s' % cname
127 desc = c.getDescription()
128 if desc:
129 print ' %s' % desc
130 print '\nSource:'
131 print ' %s' % c.getSource()
132 print ' in %s' % c.getBase()
133 print '\nEaters:'
134 if c.getEaters():
135 for e in c.getEaters():
136 print (' %s (%s%s)'
137 % (e.getName(),
138 e.getRequired() and 'required' or 'optional',
139 (e.getMultiple() and ', multiple ok' or '')))
140 else:
141 print ' (None)'
142 print '\nFeeders:'
143 if c.getFeeders():
144 for e in c.getFeeders():
145 print ' %s' % e
146 else:
147 print ' (None)'
148 print '\nFeatures:'
149 features = [(p.getType(), p) for p in c.getEntries()]
150 features.sort()
151 if features:
152 for k, v in features:
153 print ' %s: %s:%s' % (k, v.getLocation(), v.getFunction())
154 else:
155 print ' (None)'
156 print '\nProperties:'
157 printProperties(c.getProperties(), 0)
158 sockets = c.getSockets()
159 print '\nClocking:'
160 print ' Needs synchronisation: %r' % c.getNeedsSynchronization()
161 if c.getClockPriority() is not None and c.getNeedsSynchronization():
162 print ' Clock priority: %d' % c.getClockPriority()
163 print '\nSockets:'
164 for socket in sockets:
165 print ' %s' % socket
166 print
167 if r.hasPlug(cname):
168 handled = True
169 p = r.getPlug(cname)
170 print '\nPlug:'
171 print ' %s' % cname
172 print '\nType:'
173 print ' %s' % p.getType()
174 print '\nEntry:'
175 e = p.getEntry()
176 print ' %s() in %s' % (e.getFunction(), e.getModuleName())
177 print '\nProperties:'
178 printProperties(p.getProperties(), 0)
179 print
180 if not handled:
181 parser.exit(status=1, msg=('Unknown component or plug `%s\'\n' %
182 cname))
183 elif len(args) == 3:
184 cname = args[1]
185 pname = args[2]
186 ppath = pname.split(':')
187 handled = False
188 if r.hasComponent(cname):
189 handled = True
190 c = r.getComponent(cname)
191 try:
192 prop = getNestedProperty(c, ppath)
193 except _NestedPropertyError, npe:
194 parser.exit(status=1, msg='%s\n' % npe.message)
195 print '\nComponent:'
196 print ' %s' % cname
197 desc = c.getDescription()
198 if desc:
199 print ' %s' % desc
200 print '\nProperty:'
201 printProperty(prop, len(prop.getName()))
202 print
203 if r.hasPlug(cname):
204 handled = True
205 p = r.getPlug(cname)
206 try:
207 prop = getNestedProperty(p, ppath)
208 except _NestedPropertyError, npe:
209 parser.exit(status=1, msg='%s\n' % npe.message)
210 print '\nPlug:'
211 print ' %s' % cname
212 print '\nType:'
213 print ' %s' % p.getType()
214 print '\nProperty:'
215 printProperty(prop, len(prop.getName()))
216 print
217 if not handled:
218 parser.exit(status=1, msg=('Unknown component or plug `%s\'\n' %
219 cname))
220 else:
221 parser.error('Could not process arguments, try "-h" option.')
222
223 return 0
224