From 9210b7d140bb7cebccb76c4db305650b5e9a329d Mon Sep 17 00:00:00 2001
From: Rafael Monnerat <rafael@nexedi.com>
Date: Wed, 17 Jun 2009 18:08:42 +0000
Subject: [PATCH] Added Draft of LogMixin.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27639 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Tool/IntrospectionTool.py |  4 +-
 product/ERP5/Tool/LogMixin.py          | 87 ++++++++++++++++++++++++++
 2 files changed, 89 insertions(+), 2 deletions(-)
 create mode 100644 product/ERP5/Tool/LogMixin.py

diff --git a/product/ERP5/Tool/IntrospectionTool.py b/product/ERP5/Tool/IntrospectionTool.py
index 5de1e4d9cf..52a69a8c37 100644
--- a/product/ERP5/Tool/IntrospectionTool.py
+++ b/product/ERP5/Tool/IntrospectionTool.py
@@ -35,13 +35,14 @@ from Products.ERP5Type.Tool.BaseTool import BaseTool
 from Products.ERP5Type import Permissions
 from AccessControl.SecurityManagement import setSecurityManager
 from Products.ERP5 import _dtmldir
+from Products.ERP5.Tool.LogMixin import LogMixin
 from Products.ERP5Type.Utils import _setSuperSecurityManager
 from App.config import getConfiguration
 import tarfile
 
 _MARKER = []
 
-class IntrospectionTool(BaseTool):
+class IntrospectionTool(LogMixin, BaseTool):
   """
     This tool provides both local and remote introspection.
   """
@@ -50,7 +51,6 @@ class IntrospectionTool(BaseTool):
   title = 'Introspection Tool'
   meta_type = 'ERP5 Introspection Tool'
   portal_type = 'Introspection Tool'
-  allowed_content_types = ('Anonymized Introspection Report', 'User Introspection Report',) # XXX User Portal Type please
 
   security = ClassSecurityInfo()
 
diff --git a/product/ERP5/Tool/LogMixin.py b/product/ERP5/Tool/LogMixin.py
new file mode 100644
index 0000000000..e4e7e628f5
--- /dev/null
+++ b/product/ERP5/Tool/LogMixin.py
@@ -0,0 +1,87 @@
+##############################################################################
+#
+# Copyright (c) 2009 Nexedi SA and Contributors. All Rights Reserved.
+#                    Jean-Paul Smets-Solanes <jp@nexedi.com>
+#                    Rafael M. Monnerat <rafael@nexedi.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+##############################################################################
+
+from AccessControl import ClassSecurityInfo
+from Products.ERP5Type import Permissions
+
+# XXX This Mixin is not finished yet. Added as a reference for the
+# future implementation which will come.
+
+class LogMixin:
+  """
+    The idea of this mixin is to try to share all the code related
+    to log file access, caching, log filtering and filtering 
+    optimisation. 
+
+    The model chosen here is simplistic:
+    - one tool per service
+    - account parameter is used to select the customer account
+    - log_name parameter is used to select the log
+
+    I prefer this way for now so that the code for log access in
+    Tools is reduced to the minimum and we do not need to 
+    add so many portal types.
+  """
+  security = ClassSecurityInfo()
+
+  security.declareProtected('getLogFile', Permissions.ManagePortal)
+  def getLogFile(self, file_name, account=None):
+    """
+      Returns the raw log file (as they are)
+      Must be overriden
+    """
+    raise NotImplementedError
+
+  security.declareProtected('getLogFileNameList', Permissions.ManagePortal)
+  def getLogFileNameList(self, log_name, account=None,
+                        domain=None, user_name=None, 
+                        from_line=None, to_line=None,
+                        from_date=None, to_date=None ):
+    """
+      Returns the list of file names for all log files. This 
+      is iseful if we use logrotate for example. It is also
+      useful to provide some filtering parameters here 
+      (ex. to reduce the number of files to parse)
+    """
+    raise NotImplementedError
+
+  security.declareProtected('getLogNameList', Permissions.ManagePortal)
+  def getLogNameList(self, account=None):
+    """
+      Returns the list of log names.
+    """
+    raise NotImplementedError
+
+  security.declareProtected('parseLogLine', Permissions.ManagePortal)
+  def parseLogLine(self, log_name, log_line ):
+    """
+      Parses the line and returns a dict
+    """
+    method = self.getTypeBasedMethod('parseLogLine')
+    return method(log_name, log_line)
-- 
2.30.9