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