extend/improve paster shell utilities
This commit is contained in:
parent
bbd1d06792
commit
3263672934
1 changed files with 15 additions and 7 deletions
22
psu.py
22
psu.py
|
@ -16,8 +16,10 @@ from zope.app.component.hooks import setSite
|
||||||
from zope.app.container.contained import ObjectAddedEvent, ObjectRemovedEvent
|
from zope.app.container.contained import ObjectAddedEvent, ObjectRemovedEvent
|
||||||
from zope.cachedescriptors.property import Lazy
|
from zope.cachedescriptors.property import Lazy
|
||||||
from zope.catalog.interfaces import ICatalog
|
from zope.catalog.interfaces import ICatalog
|
||||||
|
from zope.copypastemove.interfaces import IContainerItemRenamer
|
||||||
from zope import component
|
from zope import component
|
||||||
from zope.event import notify
|
from zope.event import notify
|
||||||
|
from zope.exceptions.interfaces import DuplicationError
|
||||||
from zope.lifecycleevent import ObjectCreatedEvent, ObjectModifiedEvent
|
from zope.lifecycleevent import ObjectCreatedEvent, ObjectModifiedEvent
|
||||||
from zope.publisher.browser import TestRequest as BaseTestRequest
|
from zope.publisher.browser import TestRequest as BaseTestRequest
|
||||||
from zope.security.management import getInteraction, newInteraction, endInteraction
|
from zope.security.management import getInteraction, newInteraction, endInteraction
|
||||||
|
@ -25,7 +27,7 @@ from zope.interface import Interface
|
||||||
|
|
||||||
from cybertools.util.jeep import Jeep
|
from cybertools.util.jeep import Jeep
|
||||||
from loops.common import adapted, baseObject
|
from loops.common import adapted, baseObject
|
||||||
from loops.util import getObjectForUid, getUidForObject
|
from loops.util import getObjectForUid, getUidForObject, getCatalog, reindex
|
||||||
#from xxx import config
|
#from xxx import config
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,8 +35,7 @@ sc = Jeep() # shortcuts
|
||||||
rf = None # root folder
|
rf = None # root folder
|
||||||
|
|
||||||
def setup(root):
|
def setup(root):
|
||||||
global rf, sm, smdefault, intids, pau, sc
|
global sm, smdefault, catalog, intids, pau, sc
|
||||||
rf = root
|
|
||||||
setSite(root)
|
setSite(root)
|
||||||
sm = component.getSiteManager(root)
|
sm = component.getSiteManager(root)
|
||||||
smdefault = sm['default']
|
smdefault = sm['default']
|
||||||
|
@ -79,15 +80,22 @@ def delete(container, name):
|
||||||
del container[name]
|
del container[name]
|
||||||
commit()
|
commit()
|
||||||
|
|
||||||
def rename(container, old, new):
|
def rename(container, old, new, docommit=True):
|
||||||
obj = container.get(old)
|
obj = container.get(old)
|
||||||
if obj is None:
|
if obj is None:
|
||||||
print '*** Object', old, 'not found!'
|
print '*** Object', old, 'not found!'
|
||||||
return
|
return
|
||||||
container[new] = obj
|
renamer = IContainerItemRenamer(container)
|
||||||
#notifyAdded(obj)
|
if new != old:
|
||||||
|
try:
|
||||||
|
renamer.renameItem(old, new)
|
||||||
|
except DuplicationError:
|
||||||
|
print '*** Object', new, 'already exists!'
|
||||||
|
# container[new] = obj
|
||||||
|
# notifyAdded(obj)
|
||||||
notifyModification(obj)
|
notifyModification(obj)
|
||||||
commit()
|
if docommit:
|
||||||
|
commit()
|
||||||
|
|
||||||
def move(source, target, name):
|
def move(source, target, name):
|
||||||
obj = source.get(name)
|
obj = source.get(name)
|
||||||
|
|
Loading…
Add table
Reference in a new issue