Package flumotion :: Package launch :: Module inspect
[hide private]

Source Code for Module flumotion.launch.inspect

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 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   
30 -def printMultiline(indent, data):
31 maxLen = 76 - indent # Limit to 80 cols; but we add in 4 extra spaces. 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
40 -def printProperty(prop, indent):
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
56 -def printProperties(props, indent):
57 properties = [(p.getName(), p) for p in props] 58 properties.sort() 59 if properties: 60 indent = max([len(p[0]) for p in properties]) 61 for _, p in properties: 62 printProperty(p, indent)
63 64
65 -class _NestedPropertyError(Exception):
66 pass
67 68
69 -def getNestedProperty(c, ppath):
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
92 -def main(args):
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 # print all components 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