Commit 07f5b5ca authored by Łukasz Nowak's avatar Łukasz Nowak

- fix issues, that during uninstallation instance data was removed

 - update changes and TODO
 - expose new version in setup


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33586 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e0ff5eaf
Changelog Changelog
========= =========
0.2 (2010-03-10)
----------------
- fix issues, that during uninstallation instance data was removed
[luke]
0.1 (2010-02-12) 0.1 (2010-02-12)
---------------- ----------------
......
- be even more isolated - be even more isolated
- support for Zope and ZEO - support for Zope and ZEO
- in case of one Zope add normal directory - in case of one Zope add normal directory
- use template for zope.conf and zeo.conf
from setuptools import setup, find_packages from setuptools import setup, find_packages
name = "erp5.recipe.standaloneinstance" name = "erp5.recipe.standaloneinstance"
version = '0.1' version = '0.2'
def read(name): def read(name):
return open(name).read() return open(name).read()
......
...@@ -23,17 +23,16 @@ class WithMinusTemplate(Template): ...@@ -23,17 +23,16 @@ class WithMinusTemplate(Template):
class Recipe(plone.recipe.zope2instance.Recipe): class Recipe(plone.recipe.zope2instance.Recipe):
def __init__(self, buildout, name, options): def __init__(self, buildout, name, options):
standalone_location = options.get('instancehome') instancehome = options.get('instancehome')
if not standalone_location: if not instancehome:
raise zc.buildout.UserError('instancehome have to be specified') raise zc.buildout.UserError('instancehome have to be specified')
options['location'] = standalone_location
options['control-script'] = options.get('control-script', options['control-script'] = options.get('control-script',
os.path.join(standalone_location, 'bin', 'zopectl')) os.path.join(instancehome, 'bin', 'zopectl'))
self.egg = zc.recipe.egg.Egg(buildout, options['recipe'], options) self.egg = zc.recipe.egg.Egg(buildout, options['recipe'], options)
options['bin-directory'] = os.path.join(standalone_location, 'bin') options['bin-directory'] = os.path.join(instancehome, 'bin')
options['scripts'] = '' # suppress script generation. options['scripts'] = '' # suppress script generation.
options['file-storage'] = options.get('file-storage', options['file-storage'] = options.get('file-storage',
os.path.join(standalone_location, 'var', 'Data.fs')) os.path.join(instancehome, 'var', 'Data.fs'))
self.buildout, self.options, self.name = buildout, options, name self.buildout, self.options, self.name = buildout, options, name
self.zope2_location = options.get('zope2-location', '') self.zope2_location = options.get('zope2-location', '')
...@@ -53,7 +52,7 @@ class Recipe(plone.recipe.zope2instance.Recipe): ...@@ -53,7 +52,7 @@ class Recipe(plone.recipe.zope2instance.Recipe):
# Override erp5.recipe.zope2instance so as to create several # Override erp5.recipe.zope2instance so as to create several
# directories used by ERP5. # directories used by ERP5.
options = self.options options = self.options
location = options['instancehome'] instancehome = options['instancehome']
requirements, ws = self.egg.working_set() requirements, ws = self.egg.working_set()
ws_locations = [d.location for d in ws] ws_locations = [d.location for d in ws]
...@@ -126,19 +125,19 @@ class Recipe(plone.recipe.zope2instance.Recipe): ...@@ -126,19 +125,19 @@ class Recipe(plone.recipe.zope2instance.Recipe):
os.P_WAIT, os.path.normpath(options['executable']), os.P_WAIT, os.path.normpath(options['executable']),
zc.buildout.easy_install._safe_arg(options['executable']), zc.buildout.easy_install._safe_arg(options['executable']),
mkzopeinstance, '-d', mkzopeinstance, '-d',
zc.buildout.easy_install._safe_arg(location), zc.buildout.easy_install._safe_arg(instancehome),
'-u', options['user'], '-u', options['user'],
) == 0 ) == 0
# patch begin: create several directories # patch begin: create several directories
for directory in ('Constraint', 'Document', 'PropertySheet', 'tests'): for directory in ('Constraint', 'Document', 'PropertySheet', 'tests'):
path = os.path.join(location, directory) path = os.path.join(instancehome, directory)
if not os.path.exists(path): if not os.path.exists(path):
os.mkdir(path) os.mkdir(path)
# patch end: create several directories # patch end: create several directories
# Save the working set: # Save the working set:
open(os.path.join(location, 'etc', '.eggs'), 'w').write( open(os.path.join(instancehome, 'etc', '.eggs'), 'w').write(
'\n'.join(ws_locations)) '\n'.join(ws_locations))
# Make a new zope.conf based on options in buildout.cfg # Make a new zope.conf based on options in buildout.cfg
...@@ -198,7 +197,7 @@ class Recipe(plone.recipe.zope2instance.Recipe): ...@@ -198,7 +197,7 @@ class Recipe(plone.recipe.zope2instance.Recipe):
def build_zope_conf(self): def build_zope_conf(self):
options = self.options options = self.options
location = options['instancehome'] instancehome = options['instancehome']
template_input_data = ''.join( template_input_data = ''.join(
file(self.options['zope_conf_template'].strip()).readlines() file(self.options['zope_conf_template'].strip()).readlines()
) )
...@@ -214,10 +213,261 @@ class Recipe(plone.recipe.zope2instance.Recipe): ...@@ -214,10 +213,261 @@ class Recipe(plone.recipe.zope2instance.Recipe):
prefixed_products.append('products %s' % product) prefixed_products.append('products %s' % product)
options_dict['products'] = '\n'.join(prefixed_products) options_dict['products'] = '\n'.join(prefixed_products)
result = template.substitute(options_dict) result = template.substitute(options_dict)
zope_conf_path = os.path.join(location, 'etc', 'zope.conf') zope_conf_path = os.path.join(instancehome, 'etc', 'zope.conf')
file(zope_conf_path, 'w').write(result) file(zope_conf_path, 'w').write(result)
def update(self): def update(self):
# if self.options.get('force-zodb-update','false').strip().lower() == 'true': # if self.options.get('force-zodb-update','false').strip().lower() == 'true':
# return self.install() # return self.install()
return plone.recipe.zope2instance.Recipe.update(self) options = self.options
instancehome = options['instancehome']
requirements, ws = self.egg.working_set()
ws_locations = [d.location for d in ws]
if os.path.exists(instancehome):
# See if we can stop. We need to see if the working set path
# has changed.
saved_path = os.path.join(instancehome, 'etc', '.eggs')
if os.path.isfile(saved_path):
if (open(saved_path).read() !=
'\n'.join(ws_locations)
):
# Something has changed. Blow away the instance.
return self.install()
elif options.get('site-zcml'):
self.build_package_includes()
# Nothing has changed.
self.install_scripts()
return instancehome
else:
return self.install()
def patch_binaries(self, ws_locations):
if not self.zope2_location:
return
instancehome = self.options['instancehome']
path =":".join(ws_locations)
for script_name in ('runzope', 'zopectl'):
script_path = os.path.join(instancehome, 'bin', script_name)
script = open(script_path).read()
if '$SOFTWARE_HOME:$PYTHONPATH' in script:
script = script.replace(
'$SOFTWARE_HOME:$PYTHONPATH',
path+':$SOFTWARE_HOME:$PYTHONPATH'
)
elif "$SOFTWARE_HOME" in script:
# Zope 2.8
script = script.replace(
'"$SOFTWARE_HOME"',
'"'+path+':$SOFTWARE_HOME:$PYTHONPATH"'
)
f = open(script_path, 'w')
f.write(script)
f.close()
# Patch Windows scripts
for script_name in ('runzope.bat', ):
script_path = os.path.join(instancehome, 'bin', script_name)
if os.path.exists(script_path):
script = open(script_path).read()
# This could need some regex-fu
lines = [l for l in script.splitlines()
if not l.startswith('@set PYTHON=')]
lines.insert(2, '@set PYTHON=%s' % self.options['executable'])
script = '\n'.join(lines)
# Use servicewrapper.py instead of calling run.py directly
# so that sys.path gets properly set. We used to append
# all the eggs to PYTHONPATH in runzope.bat, but after
# everything was turned into eggs we exceeded the
# environment maximum size for cmd.exe.
script = script.replace(
"ZOPE_RUN=%SOFTWARE_HOME%\\Zope2\\Startup\\run.py",
"ZOPE_RUN=%INSTANCE_HOME%\\bin\\servicewrapper.py"
)
f = open(script_path, 'w')
f.write(script)
f.close()
# Patch Windows service scripts
path =";".join(ws_locations)
script_name = 'zopeservice.py'
script_path = os.path.join(instancehome, 'bin', script_name)
if os.path.exists(script_path):
script = open(script_path).read()
script = script.replace(
"ZOPE_RUN = r'%s\\Zope2\\Startup\\run.py' % SOFTWARE_HOME",
"ZOPE_RUN = r'%s\\bin\\servicewrapper.py' % INSTANCE_HOME"
)
f = open(script_path, 'w')
f.write(script)
f.close()
script_name = 'servicewrapper.py'
script_path = os.path.join(instancehome, 'bin', script_name)
script = """import sys
sys.path[0:0] = [
%s]
if __name__ == '__main__':
from Zope2.Startup import run
run.run()
""" % ''.join([' \'%s\',\n' % l.replace('\\', '\\\\') for l in ws_locations])
f = open(script_path, 'w')
f.write(script)
f.close()
# Add a test.bat that works on Windows
new_script_path = os.path.join(instancehome, 'bin', 'test.bat')
script_path = os.path.join(instancehome, 'bin', 'runzope.bat')
if os.path.exists(script_path):
script = open(script_path).read()
# Adjust script to use the right command
script = script.replace("@set ZOPE_RUN=%SOFTWARE_HOME%\\Zope2\\Startup\\run.py",
"""@set ZOPE_RUN=%ZOPE_HOME%\\test.py
@set ERRLEV=0""")
script = script.replace("\"%ZOPE_RUN%\" -C \"%CONFIG_FILE%\" %1 %2 %3 %4 %5 %6 %7",
"""\"%ZOPE_RUN%\" --config-file \"%CONFIG_FILE%\" %1 %2 %3 %4 %5 %6 %7 %8 %9
@IF %ERRORLEVEL% NEQ 0 SET ERRLEV=1
@ECHO \"%ERRLEV%\">%INSTANCE_HOME%\\testsexitcode.err""")
f = open(new_script_path, 'w')
f.write(script)
f.close()
def install_scripts(self):
options = self.options
instancehome = options['instancehome']
# The instance control script
zope_conf = os.path.join(instancehome, 'etc', 'zope.conf')
zope_conf_path = options.get('zope-conf', zope_conf)
extra_paths = []
# Only append the instance home and Zope lib/python in a non-egg
# environment
lib_python = os.path.join(self.zope2_location, 'lib', 'python')
if os.path.exists(lib_python):
extra_paths.append(os.path.join(instancehome))
extra_paths.append(lib_python)
extra_paths.extend(options.get('extra-paths', '').split())
requirements, ws = self.egg.working_set(['plone.recipe.zope2instance'])
if options.get('no-shell') == 'true':
zc.buildout.easy_install.scripts(
[(self.options.get('control-script', self.name),
'plone.recipe.zope2instance.ctl', 'noshell')],
ws, options['executable'], options['bin-directory'],
extra_paths = extra_paths,
arguments = ('\n ["-C", %r]'
'\n + sys.argv[1:]'
% zope_conf_path
),
relative_paths=self._relative_paths,
)
else:
zc.buildout.easy_install.scripts(
[(self.options.get('control-script', self.name),
'plone.recipe.zope2instance.ctl', 'main')],
ws, options['executable'], options['bin-directory'],
extra_paths = extra_paths,
arguments = ('\n ["-C", %r]'
'\n + sys.argv[1:]'
% zope_conf_path
),
relative_paths=self._relative_paths,
)
# The backup script, pointing to repozo.py
repozo = options.get('repozo', None)
if repozo is None:
repozo = os.path.join(self.zope2_location, 'utilities', 'ZODBTools', 'repozo.py')
directory, filename = os.path.split(repozo)
if repozo and os.path.exists(repozo):
zc.buildout.easy_install.scripts(
[('repozo', os.path.splitext(filename)[0], 'main')],
{}, options['executable'], options['bin-directory'],
extra_paths = [os.path.join(self.zope2_location, 'lib', 'python'),
directory],
relative_paths=self._relative_paths,
)
def build_package_includes(self):
"""Create ZCML slugs in etc/package-includes
"""
instancehome = self.options['instancehome']
sitezcml_path = os.path.join(instancehome, 'etc', 'site.zcml')
zcml = self.options.get('zcml')
site_zcml = self.options.get('site-zcml')
additional_zcml = self.options.get("zcml-additional")
if site_zcml:
open(sitezcml_path, 'w').write(site_zcml)
return
if zcml:
zcml=zcml.split()
if additional_zcml or zcml:
includes_path = os.path.join(instancehome, 'etc', 'package-includes')
if not os.path.exists(includes_path):
# Zope 2.9 does not have a package-includes so we
# create one.
os.mkdir(includes_path)
else:
if '*' in zcml:
zcml.remove('*')
else:
shutil.rmtree(includes_path)
os.mkdir(includes_path)
if additional_zcml:
path=os.path.join(includes_path, "999-additional-overrides.zcml")
open(path, "w").write(additional_zcml.strip())
if zcml:
if not os.path.exists(sitezcml_path):
# Zope 2.9 does not have a site.zcml so we copy the
# one out from Five.
skel_path = os.path.join(self.zope2_location, 'lib', 'python',
'Products', 'Five', 'skel',
'site.zcml')
shutil.copyfile(skel_path, sitezcml_path)
n = 0
package_match = re.compile('\w+([.]\w+)*$').match
for package in zcml:
n += 1
orig = package
if ':' in package:
package, filename = package.split(':')
else:
filename = None
if '-' in package:
package, suff = package.split('-')
if suff not in ('configure', 'meta', 'overrides'):
raise ValueError('Invalid zcml', orig)
else:
suff = 'configure'
if filename is None:
filename = suff + '.zcml'
if not package_match(package):
raise ValueError('Invalid zcml', orig)
path = os.path.join(
includes_path,
"%3.3d-%s-%s.zcml" % (n, package, suff),
)
open(path, 'w').write(
'<include package="%s" file="%s" />\n'
% (package, filename)
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment