How to remove local utility

5 messages Options
Embed this post
Permalink
mhora () How to remove local utility
Reply Threaded More More options
Print post
Permalink
Hi,

is there a way to remove a local utility from a site manager ?
I have a package that registers few local utilities via  
componentregistry profile step. The need is to be able to uninstall  
and remove the package.

I wrote a uninstall step that runs SiteManager::unregisterUtility  
however after removing the package I am not able to get the  
SiteManager with the following error:

009-07-21 12:07:51 WARNING OFS.Uninstalled Could not import class  
'IGSAConnectionManager' from module 'collective.gsa.interfaces'
2009-07-21 12:07:51 WARNING OFS.Uninstalled Could not import class  
'IGSAIndexQueueProcessor' from module 'collective.gsa.interfaces'
2009-07-21 12:07:51 WARNING OFS.Uninstalled Could not import class  
'IGSAQueue' from module 'collective.gsa.interfaces'
2009-07-21 12:07:51 WARNING OFS.Uninstalled Could not import class  
'GSAConnectionManager' from module 'collective.gsa.manager'
2009-07-21 12:07:51 ERROR ZODB.Connection Couldn't load state for 0x2dce
Traceback (most recent call last):
   File "/Users/matucha/Projects/fryit/gsa/parts/zope2/lib/python/ZODB/
Connection.py", line 761, in setstate
     self._setstate(obj)
   File "/Users/matucha/Projects/fryit/gsa/parts/zope2/lib/python/ZODB/
Connection.py", line 819, in _setstate
     self._reader.setGhostState(obj, p)
   File "/Users/matucha/Projects/fryit/gsa/parts/zope2/lib/python/ZODB/
serialize.py", line 604, in setGhostState
     state = self.getState(pickle)
   File "/Users/matucha/Projects/fryit/gsa/parts/zope2/lib/python/ZODB/
serialize.py", line 597, in getState
     return unpickler.load()
   File "/Users/matucha/python/245/lib/python2.4/copy_reg.py", line  
48, in _reconstructor
     obj = object.__new__(cls)
TypeError: ('object.__new__(GSAConnectionManager) is not safe, use  
Persistence.Persistent.__new__()', <function _reconstructor at  
0x1c0c30>, (<class 'collective.gsa.manager.GSAConnectionManager'>,  
<type 'object'>, None))

If I readd my package and run  
SiteManager::getAllRegisteredUtilitiesFor I still see the utility  
objects there and cannot remove them.

Matous
cewing () Re: How to remove local utility
Reply Threaded More More options
Print post
Permalink
mhora wrote:
Hi,

is there a way to remove a local utility from a site manager ?
Just read this blog post this morning, from planet plone:

http://blog.fourdigits.nl/removing-a-persistent-local-utility

Should help you out quite nicely

c
mhora () Re: How to remove local utility
Reply Threaded More More options
Print post
Permalink
cewing wrote:
mhora wrote:
Hi,

is there a way to remove a local utility from a site manager ?
Just read this blog post this morning, from planet plone:

http://blog.fourdigits.nl/removing-a-persistent-local-utility

Should help you out quite nicely

c
Thank you for the link, I have come across that too. This solution works but it's not very reliable. My current problem is that I'm not using Extension/uninstall/install method but only profiles.

If I reinstall the product, GS unregisters the utility, creates new one and registers it. Hence I have 8 utility objects and none registered and I'm not able to remove them, because I cannot get them via getUtility.

Either I'm doing something terribly wrong or everybody uses profiles has to have the same problem :)
cewing () Re: How to remove local utility
Reply Threaded More More options
Print post
Permalink
mhora wrote:
Thank you for the link, I have come across that too. This solution works but it's not very reliable. My current problem is that I'm not using Extension/uninstall/install method but only profiles.

If I reinstall the product, GS unregisters the utility, creates new one and registers it. Hence I have 8 utility objects and none registered and I'm not able to remove them, because I cannot get them via getUtility.

Either I'm doing something terribly wrong or everybody uses profiles has to have the same problem :)
You may not be using an Install.py, but you can do a similar thing with a GS profile using setuphandlers and the import_steps.xml GS step.  You can also (and probably should) create an uninstall profile, to be run when your product is uninstalled.  Then you can use setuphandlers in the uninstall routine to remove old utilities in the manner outlined in that blog post.  

Some basic information about using import_steps.xml and setuphandlers.py can be found here:

http://plone.org/documentation/tutorial/borg/setup-using-genericsetup

More reading on GS uninstall profiles is linked from this page:

https://weblion.psu.edu/trac/weblion/wiki/UninstallProfile

Good luck!

C
mhora () Re: How to remove local utility
Reply Threaded More More options
Print post
Permalink
cewing wrote:
mhora wrote:
Thank you for the link, I have come across that too. This solution works but it's not very reliable. My current problem is that I'm not using Extension/uninstall/install method but only profiles.

If I reinstall the product, GS unregisters the utility, creates new one and registers it. Hence I have 8 utility objects and none registered and I'm not able to remove them, because I cannot get them via getUtility.

Either I'm doing something terribly wrong or everybody uses profiles has to have the same problem :)
You may not be using an Install.py, but you can do a similar thing with a GS profile using setuphandlers and the import_steps.xml GS step.  You can also (and probably should) create an uninstall profile, to be run when your product is uninstalled.  Then you can use setuphandlers in the uninstall routine to remove old utilities in the manner outlined in that blog post.  

Some basic information about using import_steps.xml and setuphandlers.py can be found here:

http://plone.org/documentation/tutorial/borg/setup-using-genericsetup

More reading on GS uninstall profiles is linked from this page:

https://weblion.psu.edu/trac/weblion/wiki/UninstallProfile

Good luck!

C
Hi,

so finally I have turn on zope2 support and added install/uninstall methods, but I had to run the following code to clear it:

ut_obj = sm.queryUtility(util)
if ut_obj is not None:
      sm.unregisterUtility(provided=util)
      del ut_obj

sm.utilities.unsubscribe((), util)
del sm.utilities.__dict__['_provided'][util]
del sm.utilities._subscribers[0][util]

Thanks for help
Matous