Package flumotion :: Package component :: Package plugs :: Module adminaction
[hide private]

Source Code for Module flumotion.component.plugs.adminaction

 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   
19  import time 
20   
21  from flumotion.common import errors 
22  from flumotion.component.plugs import base 
23   
24  __version__ = "$Rev$" 
25   
26   
27 -class AdminActionPlug(base.ManagerPlug):
28 """ 29 Base class for plugs that can react to actions by an admin. For 30 example, some plugs might want to check that the admin in question 31 has the right permissions, and some others might want to log the 32 action to a database. Defines the admin action API methods. 33 """ 34
35 - def action(self, identity, method, args, kwargs):
36 """ 37 @type identity: L{flumotion.common.identity.Identity} 38 @type method: str 39 @type args: list 40 @type kwargs: dict 41 """ 42 raise NotImplementedError('subclasses have to override me')
43 44
45 -class AdminActionLoggerFilePlug(AdminActionPlug):
46 filename = None 47 file = None 48
49 - def start(self, vishnu):
50 self.filename = self.args['properties']['logfile'] 51 try: 52 self.file = open(self.filename, 'a') 53 except IOError, data: 54 raise errors.PropertyError('could not open log file %s ' 55 'for writing (%s)' 56 % (self.filename, data[1]))
57
58 - def stop(self, vishnu):
59 self.file.close() 60 self.file = None
61
62 - def action(self, identity, method, args, kwargs):
63 # gaaaaah 64 s = ('[%04d-%02d-%02d %02d:%02d:%02d] %s: %s: %r %r\n' 65 % (time.gmtime()[:6] + 66 ((identity, method, args, kwargs)))) 67 self.file.write(s) 68 self.file.flush()
69