Re: [Zope3-Users] Get a site

2007-03-08 Thread Stephan Richter
On Sunday 28 January 2007 12:23, Florian Lindner wrote:
 exceptions.ValueError: I/O operation on closed file


 any idea what caused it?

I think you violate the transaction mechanism. I think it would be easier to 
make a call via the publisher.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics  Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Get a site

2007-03-08 Thread Florian Lindner
Am Donnerstag, 8. März 2007 20:10 schrieb Stephan Richter:
 On Sunday 28 January 2007 12:23, Florian Lindner wrote:
  exceptions.ValueError: I/O operation on closed file
 
 
  any idea what caused it?

 I think you violate the transaction mechanism. I think it would be easier
 to make a call via the publisher.

The problem was that I forgot to close the connection, resp. called the close 
function on the wrong object.

Regards,

Florian
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Get a site

2007-01-28 Thread Florian Lindner
Am Montag, 22. Januar 2007 08:32 schrieb Christian Theune:
 Hi,

 Am Sonntag, den 21.01.2007, 14:44 +0100 schrieb Florian Lindner:
  Hello,
  I am in a function that has no context and want to set a site.
  The function is called periodically from a scheduler:
 
  from scheduler import loop
 
  def onStartup(event):
  refresher = loop.LoopTask(releaseRefreshEvent, interval=60)
 
  In this function I need to call getUtilitiesFor which needs a site set
  but I don't know how to get a site:
 
  (Pdb)  from zope.app.component import hooks
  (Pdb) from zope.app.zapi import *
 
  (Pdb) hooks.setSite(getSiteManager())
  *** AttributeError: 'BaseGlobalComponents' object has no
  attribute 'getSiteManager'
 
  (Pdb) hooks.setSite(getGlobalSiteManager())
  *** AttributeError: 'BaseGlobalComponents' object has no
  attribute 'getSiteManager'

 You don't set the site managers as a site, but the objects that are
 sites have site managers (or component registries) attached to them.

 Also, the global registry is always active, without settinga site.

  Just getting the root object (which AFAIK always is a site) would be ok.
  Or the object of static path.

 You'd have to open a connection to the database, get the root object and
 use that with setSite(). I don't have the complete spelling for that in
 my head though. If this is code that runs within Zope 3, then you might
 not want to talk to the database directly anyway because of the
 automatic transaction management.

Ok, I do it this way now:

def releaseRefreshEvent():
 Calls all utlities that have a INewsfeed interface registered. 
print releaseRefreshEvent!!
db = getUtility(ZODB.interfaces.IDatabase)
conn = db.open()
root = conn.root().data['Application']
zope.app.component.hooks.setSite(root)

utils = getUtilitiesFor(INewsfeed)
for i in utils:
print Utility called:, i[0]
i[1].sendNotification()

db.close()


called every 60 seconds. This works a few times but then gives an error:

2007-01-28T18:19:01 INFO root Startup time: 16.079 sec real, 4.780 sec CPU
releaseRefreshEvent!!
releaseRefreshEvent!!
Unhandled error in Deferred:
Traceback (most recent call last):
  File /home/florian/Zope3/src/zope/app/twisted/main.py, line 89, in main
reactor.run()
  File /home/florian/Zope3/src/twisted/internet/posixbase.py, line 206, in 
run
self.mainLoop()
  File /home/florian/Zope3/src/twisted/internet/posixbase.py, line 214, in 
mainLoop
self.runUntilCurrent()
  File /home/florian/Zope3/src/twisted/internet/base.py, line 541, in 
runUntilCurrent
call.func(*call.args, **call.kw)
--- exception caught here ---
  File /home/florian/Zope3/src/twisted/internet/task.py, line 84, in 
__call__
self.f(*self.a, **self.kw)
  File /home/florian/Desktop/zope/lib/python/CS/centershock/centershock.py, 
line 21, in releaseRefreshEvent
root = conn.root().data['Application']
  File /home/florian/Zope3/src/ZODB/Connection.py, line 304, in root
return self.get(z64)
  File /home/florian/Zope3/src/ZODB/Connection.py, line 204, in get
p, serial = self._storage.load(oid, self._version)
  File /home/florian/Zope3/src/ZODB/FileStorage/FileStorage.py, line 549, in 
load
h = self._read_data_header(pos, oid)
  File /home/florian/Zope3/src/ZODB/FileStorage/format.py, line 187, in 
_read_data_header
self._file.seek(pos)
exceptions.ValueError: I/O operation on closed file


any idea what caused it?

Thanks,

Florian

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Get a site

2007-01-23 Thread Florian Lindner
Am Montag, 22. Januar 2007 09:40 schrieb FB:
 Hi,

 On Mon, Jan 22, 2007 at 08:32:21AM +0100, Christian Theune wrote:

 [snip]

  You'd have to open a connection to the database, get the root object and
  use that with setSite(). I don't have the complete spelling for that in
  my head though.

 db = zapi.getUtility(IDatabase)
 conn=db.open()
 root=conn.root().data['Application']

Thanks, this way it works!

Regards,

Florian
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Get a site

2007-01-22 Thread FB
Hi,

On Mon, Jan 22, 2007 at 08:32:21AM +0100, Christian Theune wrote:

[snip]

 You'd have to open a connection to the database, get the root object and
 use that with setSite(). I don't have the complete spelling for that in
 my head though.

db = zapi.getUtility(IDatabase)
conn=db.open()
root=conn.root().data['Application']


Regards,

Frank
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Get a site

2007-01-22 Thread Florian Lindner
Am Montag, 22. Januar 2007 08:32 schrieb Christian Theune:
 Hi,

 Am Sonntag, den 21.01.2007, 14:44 +0100 schrieb Florian Lindner:
  Hello,
  I am in a function that has no context and want to set a site.
  The function is called periodically from a scheduler:
 
  from scheduler import loop
 
  def onStartup(event):
  refresher = loop.LoopTask(releaseRefreshEvent, interval=60)
 
  In this function I need to call getUtilitiesFor which needs a site set
  but I don't know how to get a site:
 
  (Pdb)  from zope.app.component import hooks
  (Pdb) from zope.app.zapi import *
 
  (Pdb) hooks.setSite(getSiteManager())
  *** AttributeError: 'BaseGlobalComponents' object has no
  attribute 'getSiteManager'
 
  (Pdb) hooks.setSite(getGlobalSiteManager())
  *** AttributeError: 'BaseGlobalComponents' object has no
  attribute 'getSiteManager'

 You don't set the site managers as a site, but the objects that are
 sites have site managers (or component registries) attached to them.

 Also, the global registry is always active, without settinga site.

And how do I get the global registry?


  Just getting the root object (which AFAIK always is a site) would be ok.
  Or the object of static path.

 You'd have to open a connection to the database, get the root object and
 use that with setSite(). I don't have the complete spelling for that in
 my head though. If this is code that runs within Zope 3, then you might
 not want to talk to the database directly anyway because of the
 automatic transaction management.

The code is not being run out of Zope. It's just not part of any class, but 
it's only called when Zope is app and running.

This function is called upon a IProcessStartingEvent event:

def onStartup(event):
 Perform initializations on startup of the server. 
refresher = loop.LoopTask(releaseRefreshEvent, interval=60)
refresher.start()

in the releaseRefreshEvent I want to call all registered utilities:

def releaseRefreshEvent():
 Calls all utlities that have a INewsfeed interface registered. 
utils = getUtilitiesFor(INewsfeed)
for i in utils:
print Utility called:, i.__name__
i.sendNotification()


but that always returns no utilites at all. IMHO the problem is that a site is 
not set. How would you do that? 
(sorry, your answer is somehow too sophisticated for me...)

Thanks,

Florian
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Get a site

2007-01-21 Thread Florian Lindner
Hello,
I am in a function that has no context and want to set a site.
The function is called periodically from a scheduler:

from scheduler import loop

def onStartup(event):
refresher = loop.LoopTask(releaseRefreshEvent, interval=60)

In this function I need to call getUtilitiesFor which needs a site set but I 
don't know how to get a site:

(Pdb)  from zope.app.component import hooks
(Pdb) from zope.app.zapi import *

(Pdb) hooks.setSite(getSiteManager())
*** AttributeError: 'BaseGlobalComponents' object has no 
attribute 'getSiteManager'

(Pdb) hooks.setSite(getGlobalSiteManager())
*** AttributeError: 'BaseGlobalComponents' object has no 
attribute 'getSiteManager'

Just getting the root object (which AFAIK always is a site) would be ok. Or 
the object of static path.

Thanks,

Florian
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Get a site

2007-01-21 Thread Christian Theune
Hi,

Am Sonntag, den 21.01.2007, 14:44 +0100 schrieb Florian Lindner:
 Hello,
 I am in a function that has no context and want to set a site.
 The function is called periodically from a scheduler:
 
 from scheduler import loop
 
 def onStartup(event):
 refresher = loop.LoopTask(releaseRefreshEvent, interval=60)
 
 In this function I need to call getUtilitiesFor which needs a site set but I 
 don't know how to get a site:
 
 (Pdb)  from zope.app.component import hooks
 (Pdb) from zope.app.zapi import *
 
 (Pdb) hooks.setSite(getSiteManager())
 *** AttributeError: 'BaseGlobalComponents' object has no 
 attribute 'getSiteManager'
 
 (Pdb) hooks.setSite(getGlobalSiteManager())
 *** AttributeError: 'BaseGlobalComponents' object has no 
 attribute 'getSiteManager'

You don't set the site managers as a site, but the objects that are
sites have site managers (or component registries) attached to them.

Also, the global registry is always active, without settinga site.

 Just getting the root object (which AFAIK always is a site) would be ok. Or 
 the object of static path.

You'd have to open a connection to the database, get the root object and
use that with setSite(). I don't have the complete spelling for that in
my head though. If this is code that runs within Zope 3, then you might
not want to talk to the database directly anyway because of the
automatic transaction management.

Christian

-- 
gocept gmbh  co. kg - forsterstraße 29 - 06112 halle/saale - germany
www.gocept.com - [EMAIL PROTECTED] - phone +49 345 122 9889 7 -
fax +49 345 122 9889 1 - zope and plone consulting and development


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users