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