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