Skip to content

Instantly share code, notes, and snippets.

@toutpt
Created August 27, 2013 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toutpt/6351383 to your computer and use it in GitHub Desktop.
Save toutpt/6351383 to your computer and use it in GitHub Desktop.
This is a script to get all browser:resources from a Plone install
from zope.publisher.interfaces.browser import IDefaultBrowserLayer,\
IBrowserPublisher
from zope.component.hooks import setSite
import zope.interface
from zope.component._api import getAdapters
import shutil
import os
from Testing import makerequest
portal = app.restrictedTraverse('adria-rcse')
setSite(portal)
portal = makerequest.makerequest(portal)
try:
from zope.globalrequest import setRequest
# support plone.subrequest
portal.REQUEST['PARENTS'] = [portal]
setRequest(portal.REQUEST)
except ImportError:
pass
class dummy(object):
zope.interface.classProvides(IDefaultBrowserLayer)
# provides = list(irequest) + layer
cond = True
gen = getAdapters((dummy,), zope.interface.Interface)
while cond:
try:
name, adapter = gen.next()
except StopIteration:
print 'stop iteration'
cond = False
except Exception, e:
print 'error while trying to get the next adapter: %s' % e
pass
else:
if IBrowserPublisher.providedBy(adapter):
path = adapter.context.path
if os.path.isdir(path):
print "resourceDirectory found: %s" % name
destination = "resources/++resource++%s/" % name
if os.path.exists(destination):
shutil.rmtree(destination)
shutil.copytree(path, destination)
else:
print "resource found: %s" % name
destination = "resources/++resource++%s" % name
if os.path.exists(destination):
os.remove(destination)
shutil.copy(path, destination)
else:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment