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 optparse 
 23  import sys 
 24   
 25  from flumotion.common import log, common, registry 
 26   
 27   
28 -def err(x):
29 sys.stderr.write(x + '\n') 30 raise SystemExit(1)
31
32 -def main(args):
33 from flumotion.common import setup 34 setup.setupPackagePath() 35 36 parser = optparse.OptionParser() 37 parser.add_option('-d', '--debug', 38 action="store", type="string", dest="debug", 39 help="set debug levels") 40 parser.add_option('-v', '--verbose', 41 action="store_true", dest="verbose", 42 help="be verbose") 43 parser.add_option('', '--version', 44 action="store_true", dest="version", 45 default=False, 46 help="show version information") 47 48 log.debug('inspect', 'Parsing arguments (%r)' % ', '.join(args)) 49 options, args = parser.parse_args(args) 50 51 # verbose overrides --debug 52 if options.verbose: 53 options.debug = "*:3" 54 55 # handle all options 56 if options.version: 57 print common.version("flumotion-inspect") 58 return 0 59 60 if options.debug: 61 log.setFluDebug(options.debug) 62 63 r = registry.getRegistry() 64 65 if len(args) == 1: 66 # print all components 67 components = [(c.getType(), c) for c in r.getComponents()] 68 components.sort() 69 print '\nAvailable components:\n' 70 for name, c in components: 71 print ' %s' % name 72 plugs = [(p.getType(), p) for p in r.getPlugs()] 73 plugs.sort() 74 print '\nAvailable plugs:\n' 75 for name, p in plugs: 76 print ' %s' % name 77 print 78 elif len(args) == 2: 79 cname = args[1] 80 handled = False 81 if r.hasComponent(cname): 82 handled = True 83 c = r.getComponent(cname) 84 print '\nComponent:' 85 print ' %s' % cname 86 desc = c.getDescription() 87 if desc: 88 print ' %s' % desc 89 print '\nSource:' 90 print ' %s' % c.getSource() 91 print ' in %s' % c.getBase() 92 print '\nEaters:' 93 if c.getEaters(): 94 for e in c.getEaters(): 95 print (' %s (%s%s)' 96 % (e.getName(), 97 e.getRequired() and 'required' or 'optional', 98 (e.getMultiple() and ', multiple ok' or ''))) 99 else: 100 print ' (None)' 101 print '\nFeeders:' 102 if c.getFeeders(): 103 for e in c.getFeeders(): 104 print ' %s' % e 105 else: 106 print ' (None)' 107 print '\nFeatures:' 108 features = [(p.getType(), p) for p in c.getEntries()] 109 features.sort() 110 if features: 111 for k, v in features: 112 print ' %s: %s:%s' % (k, v.getLocation(), v.getFunction()) 113 else: 114 print ' (None)' 115 properties = [(p.getName(), p) for p in c.getProperties()] 116 properties.sort() 117 print '\nProperties:' 118 if properties: 119 for k, v in properties: 120 desc = v.getDescription() 121 print (' %s: type %s, %s%s' 122 % (k, v.getType(), 123 v.isRequired() and 'required' or 'optional', 124 v.isMultiple() and ', multiple ok' or '')) 125 if desc: 126 print ' %s %s' % (' ' * len(k), desc) 127 sockets = c.getSockets() 128 print '\nClocking:' 129 print ' Needs synchronisation: %r' % c.getNeedsSynchronization() 130 if c.getClockPriority() is not None and c.getNeedsSynchronization(): 131 print ' Clock priority: %d' % c.getClockPriority() 132 print '\nSockets:' 133 for socket in sockets: 134 print ' %s' % socket 135 print 136 if r.hasPlug(cname): 137 handled = True 138 p = r.getPlug(cname) 139 print '\nPlug:' 140 print ' %s' % cname 141 print '\nType:' 142 print ' %s' % p.getType() 143 print '\nEntry:' 144 e = p.getEntry() 145 print ' %s() in %s' % (e.getFunction(), e.getModuleName()) 146 print '\nProperties:' 147 properties = [(x.getName(), x) for x in p.getProperties()] 148 properties.sort() 149 if properties: 150 for k, v in properties: 151 print (' %s: type %s, %s%s' 152 % (k, v.getType(), 153 v.isRequired() and 'required' or 'optional', 154 v.isMultiple() and ', multiple ok' or '')) 155 print 156 if not handled: 157 err('Unknown component or plug `%s\'' % cname) 158 else: 159 err('Usage: flumotion-inspect [COMPONENT-OR-PLUG]') 160 161 return 0
162