appy.shared: improved Debianizer (launches Zope and OO automatically); appy.bin: new.py is now able to create a pure Zope instance on its own (without mkzopeinstance) from a Zope install made with Debian zope2.12 package.
This commit is contained in:
parent
97ce11aa49
commit
a1b048153f
147
bin/new.py
147
bin/new.py
|
@ -22,7 +22,68 @@ MKZOPE_NOT_FOUND = 'Script mkzopeinstance.py not found in "%s and ' \
|
||||||
WRONG_INSTANCE_PATH = '"%s" must be an existing folder for creating the ' \
|
WRONG_INSTANCE_PATH = '"%s" must be an existing folder for creating the ' \
|
||||||
'instance in it.'
|
'instance in it.'
|
||||||
|
|
||||||
|
# zopectl template file for a pure Zope instance -------------------------------
|
||||||
zopeCtl = '''#!/bin/sh
|
zopeCtl = '''#!/bin/sh
|
||||||
|
PYTHON="/usr/lib/zope2.12/bin/python"
|
||||||
|
INSTANCE_HOME="%s"
|
||||||
|
CONFIG_FILE="$INSTANCE_HOME/etc/zope.conf"
|
||||||
|
ZDCTL="/usr/lib/zope2.12/bin/zopectl"
|
||||||
|
export INSTANCE_HOME
|
||||||
|
export PYTHON
|
||||||
|
exec "$ZDCTL" -C "$CONFIG_FILE" "$@"
|
||||||
|
'''
|
||||||
|
|
||||||
|
# runzope template file for a pure Zope instance -------------------------------
|
||||||
|
runZope = '''#! /bin/sh
|
||||||
|
INSTANCE_HOME="%s"
|
||||||
|
CONFIG_FILE="$INSTANCE_HOME/etc/zope.conf"
|
||||||
|
ZOPE_RUN="/usr/lib/zope2.12/bin/runzope"
|
||||||
|
export INSTANCE_HOME
|
||||||
|
exec "$ZOPE_RUN" -C "$CONFIG_FILE" "$@"
|
||||||
|
'''
|
||||||
|
|
||||||
|
# zope.conf template file for a pure Zope instance -----------------------------
|
||||||
|
zopeConf = '''# Zope configuration.
|
||||||
|
%%define INSTANCE %s
|
||||||
|
%%define HTTPPORT 8080
|
||||||
|
%%define ZOPE_USER zope
|
||||||
|
|
||||||
|
instancehome $INSTANCE
|
||||||
|
effective-user $ZOPE_USER
|
||||||
|
<eventlog>
|
||||||
|
level info
|
||||||
|
<logfile>
|
||||||
|
path $INSTANCE/log/event.log
|
||||||
|
level info
|
||||||
|
</logfile>
|
||||||
|
</eventlog>
|
||||||
|
<logger access>
|
||||||
|
level WARN
|
||||||
|
<logfile>
|
||||||
|
path $INSTANCE/log/Z2.log
|
||||||
|
format %%(message)s
|
||||||
|
</logfile>
|
||||||
|
</logger>
|
||||||
|
<http-server>
|
||||||
|
address $HTTPPORT
|
||||||
|
</http-server>
|
||||||
|
<zodb_db main>
|
||||||
|
<filestorage>
|
||||||
|
path $INSTANCE/var/Data.fs
|
||||||
|
</filestorage>
|
||||||
|
mount-point /
|
||||||
|
</zodb_db>
|
||||||
|
<zodb_db temporary>
|
||||||
|
<temporarystorage>
|
||||||
|
name temporary storage for sessioning
|
||||||
|
</temporarystorage>
|
||||||
|
mount-point /temp_folder
|
||||||
|
container-class Products.TemporaryFolder.TemporaryContainer
|
||||||
|
</zodb_db>
|
||||||
|
'''
|
||||||
|
|
||||||
|
# zopectl template for a Plone (4) Zope instance -------------------------------
|
||||||
|
zopeCtlPlone = '''#!/bin/sh
|
||||||
PYTHON="%s"
|
PYTHON="%s"
|
||||||
INSTANCE_HOME="%s"
|
INSTANCE_HOME="%s"
|
||||||
CONFIG_FILE="$INSTANCE_HOME/etc/zope.conf"
|
CONFIG_FILE="$INSTANCE_HOME/etc/zope.conf"
|
||||||
|
@ -33,7 +94,9 @@ export PYTHON
|
||||||
export PYTHONPATH
|
export PYTHONPATH
|
||||||
exec "$PYTHON" "$ZDCTL" -C "$CONFIG_FILE" "$@"
|
exec "$PYTHON" "$ZDCTL" -C "$CONFIG_FILE" "$@"
|
||||||
'''
|
'''
|
||||||
runZope = '''#! /bin/sh
|
|
||||||
|
# runzope template for a Plone (4) Zope instance -------------------------------
|
||||||
|
runZopePlone = '''#! /bin/sh
|
||||||
PYTHON="%s"
|
PYTHON="%s"
|
||||||
INSTANCE_HOME="%s"
|
INSTANCE_HOME="%s"
|
||||||
CONFIG_FILE="$INSTANCE_HOME/etc/zope.conf"
|
CONFIG_FILE="$INSTANCE_HOME/etc/zope.conf"
|
||||||
|
@ -44,6 +107,8 @@ export PYTHON
|
||||||
export PYTHONPATH
|
export PYTHONPATH
|
||||||
exec "$PYTHON" "$ZOPE_RUN" -C "$CONFIG_FILE" "$@"
|
exec "$PYTHON" "$ZOPE_RUN" -C "$CONFIG_FILE" "$@"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
# Patch to apply to file pkg_resources.py in a Plone4 Zope instance ------------
|
||||||
pkgResourcesPatch = '''import os, os.path
|
pkgResourcesPatch = '''import os, os.path
|
||||||
productsFolder = os.path.join(os.environ["INSTANCE_HOME"], "Products")
|
productsFolder = os.path.join(os.environ["INSTANCE_HOME"], "Products")
|
||||||
for name in os.listdir(productsFolder):
|
for name in os.listdir(productsFolder):
|
||||||
|
@ -61,20 +126,77 @@ def getAppyVersion(req, location):
|
||||||
platform='linux2', location=location)
|
platform='linux2', location=location)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
class ZopeInstanceCreator:
|
||||||
|
'''This class allows to create a Zope instance. It makes the assumption that
|
||||||
|
Zope was installed via the Debian package zope2.12.'''
|
||||||
|
|
||||||
|
def __init__(self, instancePath):
|
||||||
|
self.instancePath = instancePath
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
# Create the instance folder hierarchy
|
||||||
|
if not os.path.exists(self.instancePath):
|
||||||
|
os.makedirs(self.instancePath)
|
||||||
|
curdir = os.getcwd()
|
||||||
|
# Create bin/zopectl
|
||||||
|
os.chdir(self.instancePath)
|
||||||
|
os.mkdir('bin')
|
||||||
|
f = file('bin/zopectl', 'w')
|
||||||
|
f.write(zopeCtl % self.instancePath)
|
||||||
|
f.close()
|
||||||
|
os.chmod('bin/zopectl', 0744) # Make it executable by owner.
|
||||||
|
# Create bin/runzope
|
||||||
|
f = file('bin/runzope', 'w')
|
||||||
|
f.write(runZope % self.instancePath)
|
||||||
|
f.close()
|
||||||
|
os.chmod('bin/runzope', 0744) # Make it executable by owner.
|
||||||
|
# Create bin/startoo
|
||||||
|
f = file('bin/startoo', 'w')
|
||||||
|
f.write('#!/bin/sh\nsoffice -invisible -headless -nofirststartwizard '\
|
||||||
|
'"-accept=socket,host=localhost,port=2002;urp;"&\n')
|
||||||
|
f.close()
|
||||||
|
os.chmod('bin/startoo', 0744) # Make it executable by owner.
|
||||||
|
# Create etc/zope.conf
|
||||||
|
os.mkdir('etc')
|
||||||
|
f = file('etc/zope.conf', 'w')
|
||||||
|
f.write(zopeConf % self.instancePath)
|
||||||
|
f.close()
|
||||||
|
# Create other folders
|
||||||
|
for name in ('Extensions', 'log', 'Products', 'var'): os.mkdir(name)
|
||||||
|
f = file('Products/__init__.py', 'w')
|
||||||
|
f.write('#Makes me a Python package.\n')
|
||||||
|
f.close()
|
||||||
|
# Create 'inituser' file with admin password
|
||||||
|
import binascii
|
||||||
|
try:
|
||||||
|
from hashlib import sha1 as sha
|
||||||
|
except:
|
||||||
|
from sha import new as sha
|
||||||
|
f = open('inituser', 'w')
|
||||||
|
password = binascii.b2a_base64(sha('admin').digest())[:-1]
|
||||||
|
f.write('admin:{SHA}%s\n' % password)
|
||||||
|
f.close()
|
||||||
|
os.chmod('inituser', 0644)
|
||||||
|
# User "zope" must own this instance
|
||||||
|
os.system('chown -R zope %s' % self.instancePath)
|
||||||
|
print 'Zope instance created in %s.' % self.instancePath
|
||||||
|
os.chdir(curdir)
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
class NewScript:
|
class NewScript:
|
||||||
'''usage: %prog ploneVersion plonePath instancePath
|
'''usage: %prog ploneVersion plonePath instancePath
|
||||||
|
|
||||||
"ploneVersion" can be plone25, plone30, plone3x or plone4
|
"ploneVersion" can be plone25, plone30, plone3x, plone4 or zope
|
||||||
(plone3x represents Plone 3.2.x, Plone 3.3.5...)
|
(plone3x represents Plone 3.2.x, Plone 3.3.5...)
|
||||||
|
|
||||||
"plonePath" is the (absolute) path to you plone installation.
|
"plonePath" is the (absolute) path to your plone (or zope)
|
||||||
Plone 2.5 and 3.0 are typically installed in
|
installation. Plone 2.5 and 3.0 are typically installed
|
||||||
/opt/Plone-x.x.x, while Plone 3 > 3.0 is typically
|
in /opt/Plone-x.x.x, while Plone 3 > 3.0 is typically
|
||||||
installed in in /usr/local/Plone.
|
installed in in /usr/local/Plone.
|
||||||
"instancePath" is the (absolute) path where you want to create your
|
"instancePath" is the (absolute) path where you want to create your
|
||||||
instance (should not already exist).'''
|
instance (should not already exist).'''
|
||||||
ploneVersions = ('plone25', 'plone30', 'plone3x', 'plone4')
|
ploneVersions = ('plone25', 'plone30', 'plone3x', 'plone4', 'zope')
|
||||||
|
|
||||||
def installPlone25or30Stuff(self, linksForProducts):
|
def installPlone25or30Stuff(self, linksForProducts):
|
||||||
'''Here, we will copy all Plone2-related stuff in the Zope instance
|
'''Here, we will copy all Plone2-related stuff in the Zope instance
|
||||||
|
@ -132,12 +254,14 @@ class NewScript:
|
||||||
'''Patches Plone 4 that can't live without buildout as-is.'''
|
'''Patches Plone 4 that can't live without buildout as-is.'''
|
||||||
self.patchPlone3x() # We still need this for Plone 4 as well.
|
self.patchPlone3x() # We still need this for Plone 4 as well.
|
||||||
# bin/zopectl
|
# bin/zopectl
|
||||||
content = zopeCtl % (self.pythonPath, self.instancePath, self.zopePath)
|
content = zopeCtlPlone % (self.pythonPath, self.instancePath,
|
||||||
|
self.zopePath)
|
||||||
f = file('%s/bin/zopectl' % self.instancePath, 'w')
|
f = file('%s/bin/zopectl' % self.instancePath, 'w')
|
||||||
f.write(content)
|
f.write(content)
|
||||||
f.close()
|
f.close()
|
||||||
# bin/runzope
|
# bin/runzope
|
||||||
content = runZope % (self.pythonPath, self.instancePath, self.zopePath)
|
content = runZopePlone % (self.pythonPath, self.instancePath,
|
||||||
|
self.zopePath)
|
||||||
f = file('%s/bin/runzope' % self.instancePath, 'w')
|
f = file('%s/bin/runzope' % self.instancePath, 'w')
|
||||||
f.write(content)
|
f.write(content)
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -293,8 +417,11 @@ class NewScript:
|
||||||
linksForProducts = options.links
|
linksForProducts = options.links
|
||||||
try:
|
try:
|
||||||
self.manageArgs(args)
|
self.manageArgs(args)
|
||||||
print 'Creating new %s instance...' % self.ploneVersion
|
if self.ploneVersion != 'zope':
|
||||||
self.createInstance(linksForProducts)
|
print 'Creating new %s instance...' % self.ploneVersion
|
||||||
|
self.createInstance(linksForProducts)
|
||||||
|
else:
|
||||||
|
ZopeInstanceCreator(self.instancePath).run()
|
||||||
except NewError, ne:
|
except NewError, ne:
|
||||||
optParser.print_help()
|
optParser.print_help()
|
||||||
print
|
print
|
||||||
|
|
|
@ -88,15 +88,32 @@ class Debianizer:
|
||||||
# Add the md5 sum to the file
|
# Add the md5 sum to the file
|
||||||
f.write('%s %s\n' % (m.hexdigest(), pathName))
|
f.write('%s %s\n' % (m.hexdigest(), pathName))
|
||||||
f.close()
|
f.close()
|
||||||
# Create postinst, a script that will bytecompile Python files after the
|
# Create postinst, a script that will:
|
||||||
# Debian install.
|
# - bytecompile Python files after the Debian install
|
||||||
|
# - create a Zope instance (excepted if we are installing Appy itself).
|
||||||
f = file('postinst', 'w')
|
f = file('postinst', 'w')
|
||||||
content = '#!/bin/sh\nset -e\n'
|
content = '#!/bin/sh\nset -e\n'
|
||||||
for version in self.pythonVersions:
|
for version in self.pythonVersions:
|
||||||
content += 'if [ -e /usr/bin/python%s ]\nthen\n ' \
|
bin = '/usr/bin/python%s' % version
|
||||||
'/usr/bin/python%s -m compileall -q ' \
|
lib = '/usr/lib/python%s' % version
|
||||||
'/usr/lib/python%s/%s 2> /dev/null\nfi\n' % \
|
cmds = ' %s -m compileall -q %s/%s 2> /dev/null\n' % (bin, lib,
|
||||||
(version, version, version, self.appName)
|
self.appName)
|
||||||
|
if self.appName != 'appy':
|
||||||
|
inst = '/home/zope/%sInstance' % self.appName
|
||||||
|
cmds += ' if [ -e %s ]\n then\n' % inst
|
||||||
|
# If the Zope instance already exists, simply restart it.
|
||||||
|
cmds += ' %s/bin/zopectl restart\n else\n' % inst
|
||||||
|
# Else, create a Zope instance in the home of user "zope".
|
||||||
|
cmds += ' %s %s/appy/bin/new.py zope /usr/lib/zope2.12 ' \
|
||||||
|
'%s\n' % (bin, lib, inst)
|
||||||
|
# Within this instance, create a symlink to the Zope product
|
||||||
|
cmds += ' ln -s %s/%s/zope %s/Products/%s\n' % \
|
||||||
|
(lib, self.appName, inst, self.appName)
|
||||||
|
# Launch the instance
|
||||||
|
cmds += ' %s/bin/zopectl start\n' % inst
|
||||||
|
# Launch OpenOffice in server mode
|
||||||
|
cmds += ' %s/bin/startoo\n fi\n' % inst
|
||||||
|
content += 'if [ -e %s ]\nthen\n%sfi\n' % (bin, cmds)
|
||||||
f.write(content)
|
f.write(content)
|
||||||
f.close()
|
f.close()
|
||||||
# Create prerm, a script that will remove all pyc files before removing
|
# Create prerm, a script that will remove all pyc files before removing
|
||||||
|
|
Loading…
Reference in a new issue