Commit 7dbae7af authored by Rafael Monnerat's avatar Rafael Monnerat

Extend Introspection Tool to make possible download logs and the Data.fs.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26188 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 247ff185
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
# #
############################################################################## ##############################################################################
import os
import tempfile
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Globals import InitializeClass, DTMLFile from Globals import InitializeClass, DTMLFile
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
...@@ -34,6 +36,8 @@ from Products.ERP5Type import Permissions ...@@ -34,6 +36,8 @@ from Products.ERP5Type import Permissions
from AccessControl.SecurityManagement import setSecurityManager from AccessControl.SecurityManagement import setSecurityManager
from Products.ERP5 import _dtmldir from Products.ERP5 import _dtmldir
from Products.ERP5Type.Utils import _setSuperSecurityManager from Products.ERP5Type.Utils import _setSuperSecurityManager
from App.config import getConfiguration
import tarfile
_MARKER = [] _MARKER = []
...@@ -104,4 +108,83 @@ class IntrospectionTool(BaseTool): ...@@ -104,4 +108,83 @@ class IntrospectionTool(BaseTool):
return erp5_module_list return erp5_module_list
security.declareProtected(Permissions.ManagePortal, 'getLocalFile')
def _getLocalFile(self, REQUEST, RESPONSE, file_path,
tmp_file_path='/tmp/', compressed=1):
"""
It should return the local file compacted as tar.gz.
"""
if file_path.startswith('/'):
raise IOError, 'The file path must be relative not absolute'
instance_home = getConfiguration().instancehome
file_path = os.path.join(instance_home, file_path)
if not os.path.exists(file_path):
raise IOError, 'The file: %s does not exist.' % file_path
if compressed:
tmp_file_path = tempfile.mktemp(dir=tmp_file_path)
tmp_file = tarfile.open(tmp_file_path,"w:gz")
tmp_file.add(file_path)
tmp_file.close()
RESPONSE.setHeader('Content-type', 'application/x-tar')
else:
tmp_file_path = file_path
f = open(tmp_file_path)
try:
RESPONSE.setHeader('Content-Length', os.stat(tmp_file_path).st_size)
RESPONSE.setHeader('Content-Disposition', \
'attachment;filename="%s.tar.gz"' % file_path.split('/')[-1])
for data in f:
RESPONSE.write(data)
finally:
f.close()
if compressed:
os.remove(tmp_file_path)
return ''
security.declareProtected(Permissions.ManagePortal, 'getAccessLog')
def getAccessLog(self, compressed=1, REQUEST=None):
"""
Get the Access Log.
"""
if REQUEST is not None:
response = REQUEST.RESPONSE
else:
return "FAILED"
return self._getLocalFile(REQUEST, response,
file_path='log/Z2.log',
compressed=1)
security.declareProtected(Permissions.ManagePortal, 'getAccessLog')
def getEventLog(self, compressed=1, REQUEST=None):
"""
Get the Access Log.
"""
if REQUEST is not None:
response = REQUEST.RESPONSE
else:
return "FAILED"
return self._getLocalFile(REQUEST, response,
file_path='log/event.log',
compressed=1)
security.declareProtected(Permissions.ManagePortal, 'getAccessLog')
def getDataFs(self, compressed=1, REQUEST=None):
"""
Get the Access Log.
"""
if REQUEST is not None:
response = REQUEST.RESPONSE
else:
return "FAILED"
return self._getLocalFile(REQUEST, response,
file_path='var/Data.fs',
compressed=1)
InitializeClass(IntrospectionTool) InitializeClass(IntrospectionTool)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment