1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import sys
19
20 from flumotion.common import log, common, registry
21 from flumotion.common.options import OptionParser
22
23 __version__ = "$Rev$"
24
25
27 maxLen = 76 - indent
28 frags = data.split(' ')
29 while frags:
30 segment = frags.pop(0)
31 while frags and len(segment) + len(frags[0]) + 1 <= maxLen:
32 segment += " %s" % frags.pop(0)
33 print ' %s %s' % (' ' * indent, segment)
34
35
37 pname = prop.getName()
38 desc = prop.getDescription()
39 print (' %s%s: type %s, %s%s'
40 % (' '*(indent-len(pname)), pname, prop.getType(),
41 prop.isRequired() and 'required' or 'optional',
42 prop.isMultiple() and ', multiple ok' or ''))
43 if desc:
44 printMultiline(indent, desc)
45 if isinstance(prop, registry.RegistryEntryCompoundProperty):
46 subprop_names = [sp.getName() for sp in prop.getProperties()]
47 subprop_names.sort()
48 printMultiline(indent, 'subproperties: %s' %
49 ', '.join(subprop_names))
50
51
59
60
63
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
162 c.getNeedsSynchronization()):
163 print ' Clock priority: %d' % c.getClockPriority()
164 print '\nSockets:'
165 for socket in sockets:
166 print ' %s' % socket
167 print
168 if r.hasPlug(cname):
169 handled = True
170 p = r.getPlug(cname)
171 print '\nPlug type:'
172 print ' %s' % cname
173 desc = p.getDescription()
174 if desc:
175 print ' %s' % desc
176 print '\nEntry:'
177 e = p.getEntry()
178 print ' %s() in %s' % (e.getFunction(), e.getModuleName())
179 print '\nProperties:'
180 printProperties(p.getProperties(), 0)
181 print
182 if not handled:
183 parser.exit(status=1, msg=('Unknown component or plug `%s\'\n' %
184 cname))
185 elif len(args) == 3:
186 cname = args[1]
187 pname = args[2]
188 ppath = pname.split(':')
189 handled = False
190 if r.hasComponent(cname):
191 handled = True
192 c = r.getComponent(cname)
193 try:
194 prop = getNestedProperty(c, ppath)
195 except _NestedPropertyError, npe:
196 parser.exit(status=1, msg='%s\n' % npe.message)
197 print '\nComponent:'
198 print ' %s' % cname
199 desc = c.getDescription()
200 if desc:
201 print ' %s' % desc
202 print '\nProperty:'
203 printProperty(prop, len(prop.getName()))
204 print
205 if r.hasPlug(cname):
206 handled = True
207 p = r.getPlug(cname)
208 try:
209 prop = getNestedProperty(p, ppath)
210 except _NestedPropertyError, npe:
211 parser.exit(status=1, msg='%s\n' % npe.message)
212 print '\nPlug:'
213 print ' %s' % cname
214 print '\nType:'
215 print ' %s' % p.getType()
216 print '\nProperty:'
217 printProperty(prop, len(prop.getName()))
218 print
219 if not handled:
220 parser.exit(status=1, msg=('Unknown component or plug `%s\'\n' %
221 cname))
222 else:
223 parser.error('Could not process arguments, try "-h" option.')
224
225 return 0
226