[Erp5-report] r11926 - in /erp5/trunk/products/TimerService: ./ timerserver/ zpt/
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Jan 8 15:03:34 CET 2007
Author: kevin
Date: Mon Jan 8 15:03:31 2007
New Revision: 11926
URL: http://svn.erp5.org?rev=11926&view=rev
Log:
Original v0.2 code
Added:
erp5/trunk/products/TimerService/
erp5/trunk/products/TimerService/CREDITS.txt
erp5/trunk/products/TimerService/INSTALL.txt
erp5/trunk/products/TimerService/TimerService.py
erp5/trunk/products/TimerService/__init__.py
erp5/trunk/products/TimerService/timerserver/
erp5/trunk/products/TimerService/timerserver/TimerServer.py
erp5/trunk/products/TimerService/timerserver/__init__.py
erp5/trunk/products/TimerService/timerserver/__pkginfo__.py
erp5/trunk/products/TimerService/timerserver/component.xml
erp5/trunk/products/TimerService/timerserver/setup.py
erp5/trunk/products/TimerService/timerserver/version.txt
erp5/trunk/products/TimerService/version.txt
erp5/trunk/products/TimerService/zpt/
erp5/trunk/products/TimerService/zpt/timer_icon.gif (with props)
erp5/trunk/products/TimerService/zpt/view_subscriptions.zpt
Added: erp5/trunk/products/TimerService/CREDITS.txt
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/CREDITS.txt?rev=11926&view=auto
==============================================================================
--- erp5/trunk/products/TimerService/CREDITS.txt (added)
+++ erp5/trunk/products/TimerService/CREDITS.txt Mon Jan 8 15:03:31 2007
@@ -1,0 +1,5 @@
+Author
+
+ Nikolay Kim <fafhrd at legco.biz>
+
+Many thanks to Igor Stroh <jenner at dpost.de>
Added: erp5/trunk/products/TimerService/INSTALL.txt
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/INSTALL.txt?rev=11926&view=auto
==============================================================================
--- erp5/trunk/products/TimerService/INSTALL.txt (added)
+++ erp5/trunk/products/TimerService/INSTALL.txt Mon Jan 8 15:03:31 2007
@@ -1,0 +1,19 @@
+Prerequisites
+
+ * Zope 2.7.0+ (www.zope.org)
+
+
+Instalation
+
+1) go to timerserver directory and run:
+
+ a) python setup.py install
+ b) or create link to timerserver in $ZOPE/lib/python
+
+ timerserver module must be available in python path
+
+2) add to zope.conf
+
+%import timerserver
+<timer-server>
+</timer-server>
Added: erp5/trunk/products/TimerService/TimerService.py
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/TimerService.py?rev=11926&view=auto
==============================================================================
--- erp5/trunk/products/TimerService/TimerService.py (added)
+++ erp5/trunk/products/TimerService/TimerService.py Mon Jan 8 15:03:31 2007
@@ -1,0 +1,108 @@
+# -*- coding: UTF-8 -*-
+# -*- Mode: Python; py-indent-offset: 4 -*-
+# Authors: Nik Kim <fafhrd at legco.biz>
+__version__ = '$Revision: 1.3 $'[11:-2]
+
+import sys, time
+from DateTime import DateTime
+from Globals import InitializeClass
+from OFS.SimpleItem import SimpleItem
+from OFS.PropertyManager import PropertyManager
+
+from zLOG import LOG, INFO, ERROR
+
+from AccessControl import ClassSecurityInfo, Permissions
+from Products.PageTemplates.PageTemplateFile import PageTemplateFile
+
+current_version = 1
+
+class TimerService(SimpleItem):
+ """ timer service, all objects that wants timer
+ event subscribe here """
+
+ id='timer_service'
+ title = 'TimerService'
+
+ security = ClassSecurityInfo()
+
+ icon = 'misc_/TimerService/timer_icon.gif'
+
+ max_size = 0
+
+ manage_options = (
+ ({'label': 'Subscribers', 'action':'manage_viewSubscriptions'},))
+
+ security.declareProtected(
+ Permissions.view_management_screens, 'manage_viewSubscriptions')
+ manage_viewSubscriptions = PageTemplateFile(
+ 'zpt/view_subscriptions',
+ globals(),
+ __name__='manage_viewSubscriptions'
+ )
+
+ _version = 0
+
+ def __init__(self, id='timer_service'):
+ """ """
+ self._subscribers = []
+ self._version = 1
+
+ def process_timer(self, interval):
+ """ """
+ subscriptions = [self.unrestrictedTraverse(path)
+ for path in self._subscribers]
+
+ tick = time.time()
+ prev_tick = tick - interval
+ next_tick = tick + interval
+
+ LOG('TimerService', INFO, 'Ttimer tick at %s\n'%time.ctime(tick))
+
+ for subscriber in subscriptions:
+ try:
+ subscriber.process_timer(
+ interval, DateTime(tick), DateTime(prev_tick), DateTime(next_tick))
+ except:
+ LOG('TimerService', ERROR, 'Process timer error', error = sys.exc_info())
+
+ def subscribe(self, ob):
+ """ """
+ path = '/'.join(ob.getPhysicalPath())
+
+ #if not ISMTPHandler.isImplementedBy(ob):
+ # raise ValueError, 'Object not support ISMTPHandler'
+
+ subscribers = self._subscribers
+ if path not in subscribers:
+ subscribers.append(path)
+ self._subscribers = subscribers
+
+ def unsubscribe(self, ob):
+ """ """
+ path = '/'.join(ob.getPhysicalPath())
+
+ subscribers = self._subscribers
+ if path in subscribers:
+ subscribers.remove(path)
+ self._subscribers = subscribers
+
+ security.declareProtected(
+ Permissions.view_management_screens, 'lisSubscriptions')
+ def lisSubscriptions(self):
+ """ """
+ return self._subscribers
+
+ def manage_removeSubscriptions(self, no, REQUEST=None):
+ """ """
+ subs = self.listAllSubscriptions()
+
+ remove_list = [subs[n] for n in [int(n) for n in no]]
+
+ for subs, event, fl in remove_list:
+ self.unsubscribe( subs, event_type=event )
+
+ if REQUEST is not None:
+ REQUEST.RESPONSE.redirect('manage_viewSubscriptions')
+
+
+InitializeClass(TimerService)
Added: erp5/trunk/products/TimerService/__init__.py
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/__init__.py?rev=11926&view=auto
==============================================================================
--- erp5/trunk/products/TimerService/__init__.py (added)
+++ erp5/trunk/products/TimerService/__init__.py Mon Jan 8 15:03:31 2007
@@ -1,0 +1,40 @@
+# -*- coding: UTF-8 -*-
+# -*- Mode: Python; py-indent-offset: 4 -*-
+# Authors: Nik Kim <fafhrd at legco.biz>
+
+import Globals
+from AccessControl import ModuleSecurityInfo, allow_module
+from AccessControl.Permissions import view
+
+from TimerService import TimerService, current_version
+
+misc_ = { 'timer_icon.gif':
+ Globals.ImageFile('zpt/timer_icon.gif', globals())}
+
+cp_id = 'timer_service'
+
+def getTimerService(context):
+ """ returns the SMTP srevice instance """
+ return context.Control_Panel.timer_service
+
+def make_timer_service(cp):
+ """Control_Panel smtp service"""
+ timer_service = TimerService(cp_id)
+ cp._setObject(cp_id, timer_service)
+ return getattr(cp, cp_id)
+
+def initialize(context):
+ # hook into the Control Panel
+ cp = context._ProductContext__app.Control_Panel
+ if cp_id in cp.objectIds():
+ #cp._delObject(cp_id)
+ timer = getattr(cp, cp_id)
+ timer_service = timer
+ if not isinstance(timer_service, TimerService):
+ timer = make_timer_service(cp)
+ else:
+ timer = make_timer_service(cp)
+
+ if timer._version < current_version:
+ cp._delObject(cp_id)
+ timer = make_timer_service(cp)
Added: erp5/trunk/products/TimerService/timerserver/TimerServer.py
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/timerserver/TimerServer.py?rev=11926&view=auto
==============================================================================
--- erp5/trunk/products/TimerService/timerserver/TimerServer.py (added)
+++ erp5/trunk/products/TimerService/timerserver/TimerServer.py Mon Jan 8 15:03:31 2007
@@ -1,0 +1,94 @@
+# -*- coding: UTF-8 -*-
+# -*- Mode: Python; py-indent-offset: 4 -*-
+# Authors: Nik Kim <fafhrd at legco.biz>
+__version__ = 'TimerServer for Zope 0.1'
+
+import traceback
+
+import thread
+import sys, os, errno, time
+from StringIO import StringIO
+from zLOG import LOG, INFO
+
+from ZServer.PubCore import handle
+from ZPublisher.BaseRequest import BaseRequest
+from ZPublisher.BaseResponse import BaseResponse
+from ZPublisher.HTTPRequest import HTTPRequest
+
+class TimerServer:
+ def __init__(self, module, interval=600):
+ self.module = module
+
+ self.interval = interval
+
+ sync = thread.allocate_lock()
+
+ self._a = sync.acquire
+ self._r = sync.release
+
+ self._a()
+ thread.start_new_thread(self.run, ())
+ self._r()
+
+ LOG('ZServer', INFO,
+ 'Timer server started at %s\n'
+ '\tInterval: %s seconds.\n'%(time.ctime(time.time()), interval))
+
+ def run(self):
+ module = self.module
+ interval = self.interval
+
+ # minutes = time.gmtime(time.time()[4], seconds = time.gmtime(time.time()[5]
+ # max interval is therefore 59*60 + 59 = 208919 seconds
+
+ wait = ((time.gmtime(time.time())[4] * 60) + time.gmtime(time.time())[5]) % interval
+ sleep = interval - wait
+
+ if sleep > 0:
+ time.sleep(sleep)
+
+ LOG('ZServer', INFO, 'Timerserver ready, starting timer services.')
+
+ while 1:
+ time.sleep(interval)
+ # send message to zope
+ try:
+ out = StringIO()
+ err = StringIO()
+ response = TimerResponse(out, err)
+ handle(module, TimerRequest(response, interval), response)
+ except:
+ pass
+
+
+class TimerResponse(BaseResponse):
+ def _finish(self):
+ pass
+
+ def unauthorized(self):
+ pass
+
+
+class TimerRequest(HTTPRequest):
+
+ retry_max_count = 0
+
+ def __init__(self, response, interval):
+ stdin=StringIO()
+ environ=self._get_env(stdin)
+ HTTPRequest.__init__(self, stdin, environ, response, clean=1)
+
+ self.other['interval'] = interval
+
+ def _get_env(self, stdin):
+ "Returns a CGI style environment"
+ env={}
+ env['REQUEST_METHOD']='GET'
+ env['SERVER_SOFTWARE']= 'TimerServer for Zope'
+ env['SERVER_NAME'] = ''
+ env['SERVER_PORT'] = ''
+ env['REMOTE_ADDR'] = ''
+ env['GATEWAY_INTERFACE'] = 'CGI/1.1'
+
+ env['PATH_INFO']= '/Control_Panel/timer_service/process_timer'
+ return env
Added: erp5/trunk/products/TimerService/timerserver/__init__.py
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/timerserver/__init__.py?rev=11926&view=auto
==============================================================================
--- erp5/trunk/products/TimerService/timerserver/__init__.py (added)
+++ erp5/trunk/products/TimerService/timerserver/__init__.py Mon Jan 8 15:03:31 2007
@@ -1,0 +1,10 @@
+from ZServer.datatypes import ServerFactory
+
+class TimerServerFactory(ServerFactory):
+ def __init__(self, section):
+ ServerFactory.__init__(self)
+ self.interval = section.interval
+
+ def create(self):
+ from timerserver.TimerServer import TimerServer
+ return TimerServer(self.module, self.interval)
Added: erp5/trunk/products/TimerService/timerserver/__pkginfo__.py
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/timerserver/__pkginfo__.py?rev=11926&view=auto
==============================================================================
--- erp5/trunk/products/TimerService/timerserver/__pkginfo__.py (added)
+++ erp5/trunk/products/TimerService/timerserver/__pkginfo__.py Mon Jan 8 15:03:31 2007
@@ -1,0 +1,17 @@
+
+modname = 'timerserver'
+version = open('version.txt').read().strip()
+numversion = version.split('.')
+
+license = 'GPL'
+copyright = '''Nikolay Kim (c) 2004'''
+
+author = "Nikolay Kim"
+author_email = "fafhrd at legco.biz"
+
+short_desc = "Timer Server for Zope"
+long_desc = short_desc
+
+web = ""
+ftp = ""
+mailing_list = ""
Added: erp5/trunk/products/TimerService/timerserver/component.xml
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/timerserver/component.xml?rev=11926&view=auto
==============================================================================
--- erp5/trunk/products/TimerService/timerserver/component.xml (added)
+++ erp5/trunk/products/TimerService/timerserver/component.xml Mon Jan 8 15:03:31 2007
@@ -1,0 +1,14 @@
+<component>
+ <import package="ZServer" />
+
+ <sectiontype name="timer-server"
+ datatype="timerserver.TimerServerFactory"
+ implements="ZServer.server">
+ <key name="interval" datatype="integer" default="600">
+ <description>
+ Interval in seconds.
+ </description>
+ </key>
+ </sectiontype>
+
+</component>
Added: erp5/trunk/products/TimerService/timerserver/setup.py
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/timerserver/setup.py?rev=11926&view=auto
==============================================================================
--- erp5/trunk/products/TimerService/timerserver/setup.py (added)
+++ erp5/trunk/products/TimerService/timerserver/setup.py Mon Jan 8 15:03:31 2007
@@ -1,0 +1,23 @@
+#!/usr/bin/env python
+import sys
+from distutils import util
+from distutils.core import setup, Extension
+
+from __pkginfo__ import modname, version, license, short_desc, long_desc,\
+ web, author, author_email
+
+if __name__ == '__main__' :
+ dist = setup(name = modname,
+ version = version,
+ license =license,
+ description = short_desc,
+ long_description = long_desc,
+ author = author,
+ author_email = author_email,
+ url = web,
+ package_dir = {modname: '.'},
+ packages = [modname,],
+ data_files = [
+ ('./lib/python%s.%s/site-packages/%s'%(sys.version_info[0], sys.version_info[1], modname),
+ ['component.xml'])]
+ )
Added: erp5/trunk/products/TimerService/timerserver/version.txt
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/timerserver/version.txt?rev=11926&view=auto
==============================================================================
--- erp5/trunk/products/TimerService/timerserver/version.txt (added)
+++ erp5/trunk/products/TimerService/timerserver/version.txt Mon Jan 8 15:03:31 2007
@@ -1,0 +1,1 @@
+0.2
Added: erp5/trunk/products/TimerService/version.txt
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/version.txt?rev=11926&view=auto
==============================================================================
--- erp5/trunk/products/TimerService/version.txt (added)
+++ erp5/trunk/products/TimerService/version.txt Mon Jan 8 15:03:31 2007
@@ -1,0 +1,1 @@
+0.2
Added: erp5/trunk/products/TimerService/zpt/timer_icon.gif
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/zpt/timer_icon.gif?rev=11926&view=auto
==============================================================================
Binary file - no diff available.
Propchange: erp5/trunk/products/TimerService/zpt/timer_icon.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: erp5/trunk/products/TimerService/zpt/view_subscriptions.zpt
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/zpt/view_subscriptions.zpt?rev=11926&view=auto
==============================================================================
--- erp5/trunk/products/TimerService/zpt/view_subscriptions.zpt (added)
+++ erp5/trunk/products/TimerService/zpt/view_subscriptions.zpt Mon Jan 8 15:03:31 2007
@@ -1,0 +1,38 @@
+<h1 tal:replace="structure here/manage_page_header">Header</h1>
+<h2 tal:define="manage_tabs_message options/manage_tabs_message | nothing"
+ tal:replace="structure here/manage_tabs">Tabs</h2>
+
+<h4 class="form-label">Subscriptions</h4>
+
+<h4 tal:define="global subscriptions here/lisSubscriptions"
+ tal:condition="not:subscriptions">There are no subscriptions.</h4>
+
+<form method="post" action="manage_removeSubscriptions">
+
+<table width="100%" cellspacing="0" cellpadding="2" border="0"
+ tal:condition="subscriptions">
+
+<tr align="left">
+ <th> </th>
+ <th align="left">Subscriber</th>
+</tr>
+
+<tbody tal:repeat="subscription subscriptions">
+
+<tr align="left" class="form-help">
+ <td><input type="checkbox" name="no:list"
+ tal:attributes="value repeat/subscription/index" /></td>
+ <td tal:content="subscription">Subscriber</td>
+</tr>
+
+</tbody>
+
+</table>
+
+<br />
+<input type="submit" value="Remove" />
+
+</form>
+
+<h1 tal:replace="structure here/manage_page_footer">Footer</h1>
+
More information about the Erp5-report
mailing list