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   
28 -def printMultiline(indent, data):
29 maxLen = 76 - indent # Limit to 80 cols; but we add in 4 extra spaces. 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
37 -def printProperty(prop, indent):
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
52 -def printProperties(props, indent):
53 properties = [(p.getName(), p) for p in props] 54 properties.sort() 55 if properties: 56 indent = max([len(p[0]) for p in properties]) 57 for _, p in properties: 58 printProperty(p, indent)
59
60 -class _NestedPropertyError(Exception):
61 pass
62
63 -def getNestedProperty(c, ppath):
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
86 -def main(args):
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 # print all components 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