Package flumotion :: Package component :: Package base :: Module admin_text
[hide private]

Source Code for Module flumotion.component.base.admin_text

  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.common import errors, log 
 23  from flumotion.twisted import flavors 
 24  from flumotion.twisted.compat import implements 
 25   
26 -class BaseAdminText(log.Loggable):
27 """ 28 I am a base class for all Text-based Admin views. 29 I am a view on one component's properties. 30 """ 31 32 implements(flavors.IStateListener) 33 34 logCategory = "admintext" 35 36 state = admin = 'hello pychecker' 37
38 - def __init__(self, state, admin):
39 """ 40 @param state: state of component this is a UI for 41 @type state: L{flumotion.common.planet.AdminComponentState} 42 @type admin: L{flumotion.admin.admin.AdminModel} 43 @param admin: the admin model that interfaces with the manager for us 44 """ 45 self.state = state 46 self.name = state.get('name') 47 self.admin = admin 48 self.debug('creating admin text for state %r' % state)
49
50 - def propertyErrback(self, failure, window):
51 failure.trap(errors.PropertyError) 52 self.warning("%s." % failure.getErrorMessage()) 53 #window.error_dialog("%s." % failure.getErrorMessage()) 54 return None
55
56 - def setElementProperty(self, elementName, propertyName, value):
57 """ 58 Set the given property on the element with the given name. 59 """ 60 d = self.admin.setProperty(self.state, elementName, propertyName, value) 61 d.addErrback(self.propertyErrback, self) 62 return d
63
64 - def getElementProperty(self, elementName, propertyName):
65 """ 66 Get the value of the given property of the element with the given name. 67 68 Returns: L{twisted.internet.defer.Deferred} returning the value. 69 """ 70 d = self.admin.getProperty(self.state, elementName, propertyName) 71 d.addErrback(self.propertyErrback, self) 72 return d
73
74 - def callRemote(self, methodName, *args, **kwargs):
75 return self.admin.componentCallRemote(self.state, methodName, 76 *args, **kwargs)
77 78 ### child class methods to be overridden 79
80 - def propertyChanged(self, name, value):
81 """ 82 Override this method to be notified of component's properties that 83 have changed. 84 85 I am meant to be overridden. 86 """ 87 self.debug("property %s changed to %r" % (name, value))
88
89 - def setup(self):
90 """ 91 Set up the admin view so it can display nodes. 92 """ 93 raise NotImplementedError("Child class needs to implement setup")
94
95 - def uiStateChanged(self, stateObject):
96 # default implementation 97 pass
98
99 - def stateSet(self, object, key, value):
100 self.uiStateChanged(object)
101 102
103 - def stateAppend(self, object, key, value):
104 self.uiStateChanged(object)
105 106
107 - def stateRemove(self, object, key, value):
108 self.uiStateChanged(object)
109 110 111 # given an input text return possible completions
112 - def getCompletions(self, input):
113 return []
114 115 # run command, return string with result
116 - def runCommand(self, command):
117 return ""
118