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 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  """utilities used by flumotion-command""" 
23   
24  from flumotion.twisted.defer import defer_generator 
25  from flumotion.common import errors 
26   
27  __version__ = "$Rev$" 
28   
29   
30 -def avatarId(string):
31 split = string.split('/') 32 assert len(split) == 3 33 assert not split[0] 34 return split[1:]
35 36
37 -def avatarPath(string):
38 split = string.split('/') 39 assert not split[0] 40 assert len(split) > 0 and len(split) < 4 41 if len(split) == 3: 42 return ['component'] + split[1:] 43 elif len(split) == 2: 44 if split[1] == 'atmosphere': 45 return ['atmosphere'] 46 elif split[1] == '': 47 return ['root'] 48 else: 49 return ['flow'] + split[1:]
50 51
52 -def find_component(planet, avatarId):
53 if avatarId[0] == 'atmosphere': 54 for c in planet.get('atmosphere').get('components'): 55 if c.get('name') == avatarId[1]: 56 return c 57 print ('Could not find component named %s in flow %s' 58 % (avatarId[1], avatarId[0])) 59 return None 60 61 for f in planet.get('flows'): 62 if f.get('name') == avatarId[0]: 63 for c in f.get('components'): 64 if c.get('name') == avatarId[1]: 65 return c 66 print ('Could not find component named %s in flow %s' 67 % (avatarId[1], avatarId[0])) 68 return None
69 70
71 -def get_component_uistate(model, avatarId, component=None, quiet=False):
72 if not component: 73 d = model.callRemote('getPlanetState') 74 yield d 75 planet = d.value() 76 component = find_component(planet, avatarId) 77 if component: 78 d = model.componentCallRemote(component, 'getUIState') 79 yield d 80 try: 81 uistate = d.value() 82 yield uistate 83 except errors.SleepingComponentError: 84 if not quiet: 85 print ('Error: Component %s in flow %s is sleeping' 86 % (avatarId[1], avatarId[0]))
87 get_component_uistate = defer_generator(get_component_uistate) 88