Package flumotion :: Package admin :: Package command :: Module utils
[hide private]

Source Code for Module flumotion.admin.command.utils

 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,2008,2009 Fluendo, S.L. 
 6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
 7  # All rights reserved. 
 8  # 
 9  # This file may be distributed and/or modified under the terms of 
10  # the GNU Lesser General Public License version 2.1 as published by 
11  # the Free Software Foundation. 
12  # This file is distributed without any warranty; without even the implied 
13  # warranty of merchantability or fitness for a particular purpose. 
14  # See "LICENSE.LGPL" in the source distribution for more information. 
15  # 
16  # Headers in this file shall remain intact. 
17   
18  """utilities used by flumotion-command""" 
19   
20  from flumotion.twisted.defer import defer_generator 
21  from flumotion.common import errors 
22   
23  __version__ = "$Rev$" 
24   
25   
26 -def avatarId(string):
27 split = string.split('/') 28 assert len(split) == 3 29 assert not split[0] 30 return split[1:]
31 32
33 -def avatarPath(string):
34 split = string.split('/') 35 assert not split[0] 36 assert len(split) > 0 and len(split) < 4 37 if len(split) == 3: 38 return ['component'] + split[1:] 39 elif len(split) == 2: 40 if split[1] == 'atmosphere': 41 return ['atmosphere'] 42 elif split[1] == '': 43 return ['root'] 44 else: 45 return ['flow'] + split[1:]
46 47
48 -def find_component(planet, avatarId):
49 if avatarId[0] == 'atmosphere': 50 for c in planet.get('atmosphere').get('components'): 51 if c.get('name') == avatarId[1]: 52 return c 53 print ('Could not find component named %s in flow %s' 54 % (avatarId[1], avatarId[0])) 55 return None 56 57 for f in planet.get('flows'): 58 if f.get('name') == avatarId[0]: 59 for c in f.get('components'): 60 if c.get('name') == avatarId[1]: 61 return c 62 print ('Could not find component named %s in flow %s' 63 % (avatarId[1], avatarId[0])) 64 return None
65 66
67 -def get_component_uistate(model, avatarId, component=None, quiet=False):
68 if not component: 69 d = model.callRemote('getPlanetState') 70 yield d 71 planet = d.value() 72 component = find_component(planet, avatarId) 73 if component: 74 d = model.componentCallRemote(component, 'getUIState') 75 yield d 76 try: 77 uistate = d.value() 78 yield uistate 79 except errors.SleepingComponentError: 80 if not quiet: 81 print ('Error: Component %s in flow %s is sleeping' 82 % (avatarId[1], avatarId[0]))
83 get_component_uistate = defer_generator(get_component_uistate) 84