Created
August 27, 2013 09:11
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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