Commit 36ec65be authored by Vincent Pelletier's avatar Vincent Pelletier

Improve docstrings.

Respect 80 columns limit.
Remove erroneous activation of alarms.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6899 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1e606522
...@@ -47,12 +47,12 @@ except ImportError: ...@@ -47,12 +47,12 @@ except ImportError:
class AlarmTool(BaseTool): class AlarmTool(BaseTool):
""" """
This tool will be usefull to manage alarms. There's This tool manages alarms.
alarms everywhere in ERP5, and it is a nice idea to be able
to manage all of them from a central point. It is used as a central managment point for all alarms.
Inside this tool we will have a way to retrieve all reports comings Inside this tool we have a way to retrieve all reports comings
from Alarms,... from Alarms,...
""" """
id = 'portal_alarms' id = 'portal_alarms'
meta_type = 'ERP5 Alarm Tool' meta_type = 'ERP5 Alarm Tool'
...@@ -69,29 +69,29 @@ class AlarmTool(BaseTool): ...@@ -69,29 +69,29 @@ class AlarmTool(BaseTool):
manageAlarmList = DTMLFile( 'manageAlarmList', _dtmldir ) manageAlarmList = DTMLFile( 'manageAlarmList', _dtmldir )
manage_options = ( ( { 'label' : 'Overview' manage_options = ( ( { 'label' : 'Overview'
, 'action' : 'manage_overview' , 'action' : 'manage_overview'
} }
, { 'label' : 'All Alarms' , { 'label' : 'All Alarms'
, 'action' : 'manageAlarmList' , 'action' : 'manageAlarmList'
} }
) )
+ Folder.manage_options + Folder.manage_options
) )
interval = 60 # Default interval for alarms is 60 seconds interval = 60 # Default interval for alarms is 60 seconds
last_tic = time.time() last_tic = time.time()
# Factory Type Information # Factory Type Information
factory_type_information = \ factory_type_information = \
{ 'id' : portal_type { 'id' : portal_type
, 'meta_type' : meta_type , 'meta_type' : meta_type
, 'description' : """\ , 'description' : """AlarmTool manages alarms."""
TemplateTool manages Business Templates."""
, 'icon' : 'folder_icon.gif' , 'icon' : 'folder_icon.gif'
, 'product' : 'ERP5Type' , 'product' : 'ERP5Type'
, 'factory' : 'addFolder' , 'factory' : 'addFolder'
, 'immediate_view' : 'Folder_viewContentList' , 'immediate_view' : 'Folder_viewContentList'
, 'allow_discussion' : 1 , 'allow_discussion' : 1
, 'allowed_content_types': ('Business Template',) , 'allowed_content_types': ()
, 'filter_content_types' : 1 , 'filter_content_types' : 1
, 'global_allow' : 1 , 'global_allow' : 1
, 'actions' : , 'actions' :
...@@ -99,55 +99,57 @@ TemplateTool manages Business Templates.""" ...@@ -99,55 +99,57 @@ TemplateTool manages Business Templates."""
, 'name' : 'View' , 'name' : 'View'
, 'category' : 'object_view' , 'category' : 'object_view'
, 'action' : 'Folder_viewContentList' , 'action' : 'Folder_viewContentList'
, 'permissions' : ( , 'permissions' : ( Permissions.View, )
Permissions.View, )
}, },
) )
} }
# API to manage alarms # API to manage alarms
""" # Aim of this API:
This is what we should do: #-- see all alarms stored everywhere
#-- defines global alarms
-- be able to see all alarms stored everywhere #-- activate an alarm
-- defines global alarms #-- see reports
-- activate an alarm #-- see active alarms
-- see reports #-- retrieve all alarms
-- see active alarms
-- retrieve all alarms
"""
security.declareProtected(Permissions.ModifyPortalContent, 'getAlarmList') security.declareProtected(Permissions.ModifyPortalContent, 'getAlarmList')
def getAlarmList(self,to_active=0): def getAlarmList(self, to_active = 0):
""" """
We retrieve thanks to the catalog the full list of alarms We retrieve thanks to the catalog the full list of alarms
""" """
user = self.portal_catalog.getOwner() user = self.portal_catalog.getOwner()
newSecurityManager(self.REQUEST, user) newSecurityManager(self.REQUEST, user)
if to_active: if to_active:
now = str(DateTime()) now = str(DateTime())
date_expression = '<= %s' % now date_expression = '<= %s' % now
catalog_search = self.portal_catalog(portal_type = self.getPortalAlarmTypeList(), alarm_date=date_expression) catalog_search = self.portal_catalog(portal_type = \
self.getPortalAlarmTypeList(), alarm_date = date_expression)
else: else:
catalog_search = self.portal_catalog(portal_type = self.getPortalAlarmTypeList()) catalog_search = self.portal_catalog(portal_type = \
self.getPortalAlarmTypeList())
alarm_list = map(lambda x:x.getObject(),catalog_search) alarm_list = map(lambda x:x.getObject(),catalog_search)
# LOG('AlarmTool.getAlarmList, alarm_list',0,alarm_list)
if to_active: if to_active:
now = DateTime() now = DateTime()
date_expression = '<= %s' % str(now) date_expression = '<= %s' % str(now)
catalog_search = self.portal_catalog(portal_type = self.getPortalAlarmTypeList(), alarm_date=date_expression) catalog_search = self.portal_catalog(
portal_type = self.getPortalAlarmTypeList(), alarm_date=date_expression
)
# check again the alarm date in case the alarm was not yet reindexed # check again the alarm date in case the alarm was not yet reindexed
alarm_list = [x.getObject() for x in catalog_search if x.getObject().getAlarmDate()<=now] alarm_list = [x.getObject() for x in catalog_search \
if x.getObject().getAlarmDate()<=now]
else: else:
catalog_search = self.portal_catalog(portal_type = self.getPortalAlarmTypeList()) catalog_search = self.portal_catalog(
portal_type = self.getPortalAlarmTypeList()
)
alarm_list = map(lambda x:x.getObject(),catalog_search) alarm_list = map(lambda x:x.getObject(),catalog_search)
return alarm_list return alarm_list
security.declareProtected(Permissions.ModifyPortalContent, 'tic') security.declareProtected(Permissions.ModifyPortalContent, 'tic')
def tic(self): def tic(self):
""" """
We will look at all alarms and see if they should be activated, We will look at all alarms and see if they should be activated,
if so then we will activate them. if so then we will activate them.
""" """
current_date = DateTime() current_date = DateTime()
for alarm in self.getAlarmList(to_active=1): for alarm in self.getAlarmList(to_active=1):
...@@ -161,23 +163,25 @@ TemplateTool manages Business Templates.""" ...@@ -161,23 +163,25 @@ TemplateTool manages Business Templates."""
security.declareProtected(Permissions.ManageProperties, 'subscribe') security.declareProtected(Permissions.ManageProperties, 'subscribe')
def subscribe(self): def subscribe(self):
""" subscribe to the global Timer Service """ """
Subscribe to the global Timer Service.
"""
service = getTimerService(self) service = getTimerService(self)
if not service: if not service:
LOG('AlarmTool', INFO, 'TimerService not available') LOG('AlarmTool', INFO, 'TimerService not available')
return return
service.subscribe(self) service.subscribe(self)
return "Subscribed to Timer Service" return "Subscribed to Timer Service"
security.declareProtected(Permissions.ManageProperties, 'unsubscribe') security.declareProtected(Permissions.ManageProperties, 'unsubscribe')
def unsubscribe(self): def unsubscribe(self):
""" unsubscribe from the global Timer Service """ """
Unsubscribe from the global Timer Service.
"""
service = getTimerService(self) service = getTimerService(self)
if not service: if not service:
LOG('AlarmTool', INFO, 'TimerService not available') LOG('AlarmTool', INFO, 'TimerService not available')
return return
service.unsubscribe(self) service.unsubscribe(self)
return "Usubscribed from Timer Service" return "Usubscribed from Timer Service"
...@@ -191,16 +195,11 @@ TemplateTool manages Business Templates.""" ...@@ -191,16 +195,11 @@ TemplateTool manages Business Templates."""
def process_timer(self, tick, interval, prev="", next=""): def process_timer(self, tick, interval, prev="", next=""):
""" """
Call tic() every x seconds. x is defined in self.interval Call tic() every x seconds. x is defined in self.interval
This method is called by TimerService in the interval given This method is called by TimerService in the interval given
in zope.conf. The Default is every 5 seconds. in zope.conf. The Default is every 5 seconds.
""" """
if tick - self.last_tic >= self.interval: if tick - self.last_tic >= self.interval:
self.tic() self.tic()
self.last_tic = tick self.last_tic = tick
for alarm in self.getAlarmList(to_active=1):
if alarm.isActive() or not alarm.isEnabled():
# do nothing if already active, or not enabled
continue
alarm.activate().activeSense()
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