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: 6125 $" 
 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 -def printProperty(prop, indent):
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
54 -def printProperties(props, indent):
55 properties = [(p.getName(), p) for p in props] 56 properties.sort() 57 if properties: 58 indent = max([len(p[0]) for p in properties]) 59 for _, p in properties: 60 printProperty(p, indent)
61
62 -class _NestedPropertyError(Exception):
63 pass
64
65 -def getNestedProperty(c, ppath):
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
88 -def main(args):
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 # print all components 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