##############################################################################
#
# Copyright (c) 2003-2005 Kupu Contributors. All rights reserved.
#
# This software is distributed under the terms of the Kupu
# License. See LICENSE.txt for license text. For a list of Kupu
# Contributors see CREDITS.txt.
#
##############################################################################
"""Install kupu in CMF and, if available, Plone
This is best executed using CMFQuickInstaller
$Id: Install.py 18104 2005-10-03 14:10:11Z duncan $
"""
import os.path
import sys
import re
from StringIO import StringIO
from App.Common import package_home
from Products.CMFCore.utils import getToolByName, minimalpath
from Products.CMFCore.DirectoryView import createDirectoryView
from Products.kupu import kupu_globals
from Products.kupu.config import TOOLNAME, PROJECTNAME, TOOLTITLE
from OFS.ObjectManager import BadRequestException
from zExceptions import BadRequest
try:
from Products.MimetypesRegistry import MimeTypeItem
except ImportError:
pass # Plone not available
kupu_package_dir = package_home(kupu_globals)
def register_layer(self, relpath, name, out):
"""Register a file system directory as skin layer
"""
print >>out, "register skin layers"
skinstool = getToolByName(self, 'portal_skins')
if name not in skinstool.objectIds():
kupu_plone_skin_dir = minimalpath(os.path.join(kupu_package_dir, relpath))
createDirectoryView(skinstool, kupu_plone_skin_dir, name)
print >>out, "The layer '%s' was added to the skins tool" % name
# put this layer into all known skins
for skinName in skinstool.getSkinSelections():
path = skinstool.getSkinPath(skinName)
path = [i.strip() for i in path.split(',')]
try:
if name not in path:
path.insert(path.index('custom')+1, name)
except ValueError:
if name not in path:
path.append(name)
path = ','.join(path)
skinstool.addSkinSelection(skinName, path)
def install_plone(self, out):
"""Install with plone
"""
# register the plone skin layer
register_layer(self, 'plone/kupu_plone_layer', 'kupu_plone', out)
# register as editor
portal_props = getToolByName(self, 'portal_properties')
site_props = getattr(portal_props,'site_properties', None)
attrname = 'available_editors'
if site_props is not None:
editors = list(site_props.getProperty(attrname))
if 'Kupu' not in editors:
editors.append('Kupu')
site_props._updateProperty(attrname, editors)
print >>out, "Added 'Kupu' to available editors in Plone."
install_libraries(self, out)
install_configlet(self, out)
install_transform(self, out)
install_resources(self, out)
install_customisation(self, out)
def _read_resources():
resourcefile = open(os.path.join(kupu_package_dir, 'plone', 'head.kupu'), 'r')
try:
data = resourcefile.read()
return data
finally:
resourcefile.close()
def css_files(resources):
CSSPAT = re.compile(r'\]*rel="stylesheet"[^>]*\${portal_url}/([^"]*)"')
for m in CSSPAT.finditer(resources):
id = m.group(1)
yield id
def js_files(resources):
JSPAT = re.compile(r'\