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