Commit 458a1816 authored by Łukasz Nowak's avatar Łukasz Nowak

- move eggs to proper place

 - reuse externals to fetch eggs (temporally solution)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33865 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ee4f0263
# svn propset svn:externals -F ./EXTERNALS.TXT .
z3c.recipe.openoffice http://svn.zope.org/repos/main/z3c.recipe.openoffice/branches/erp5-downloadcache
erp5.timmy https://svn.erp5.org/repos/public/erp5/trunk/utils/erp5.timmy/
erp5.timmy https://svn.erp5.org/repos/public/erp5/trunk/utils/erp5.timmy
erp5.recipe.bt5checkout https://svn.erp5.org/repos/public/erp5/trunk/utils/erp5.recipe.bt5checkout
erp5.recipe.mysqldatabase https://svn.erp5.org/repos/public/erp5/trunk/utils/erp5.recipe.mysqldatabase
erp5.recipe.openoffice https://svn.erp5.org/repos/public/erp5/trunk/utils/erp5.recipe.openoffice
erp5.recipe.standaloneinstance https://svn.erp5.org/repos/public/erp5/trunk/utils/erp5.recipe.standaloneinstance
Changelog
=========
0.1 (2010-02-25)
----------------
- intial version
[luke]
infrae.subversion wrapper for Business Templates
================================================
Easy way to define which Business Templates to download to which folders.
[infrae]
urls =
http://server/path/SOMETHING/revision SOMETHING
[bt5checkout]
base = http://server/path/
revision = revision
urls =
SOMETHING # it will become http://server/path/SOMETHING/revision SOMETHING for infrae.subversion
from setuptools import setup, find_packages
name = "erp5.recipe.bt5checkout"
version = '0.1'
def read(name):
return open(name).read()
long_description=(
read('README.txt')
+ '\n' +
read('CHANGES.txt')
)
setup(
name = name,
version = version,
author = "Lukasz Nowak",
author_email = "luke@nexedi.com",
description = "ZC Buildout recipe to fetch easily BT5 from SVN",
long_description=long_description,
license = "ZPL 2.1",
keywords = "zope2 buildout",
classifiers=[
"License :: OSI Approved :: Zope Public License",
"Framework :: Buildout",
"Framework :: Zope2",
],
packages = find_packages('src'),
include_package_data = True,
package_dir = {'':'src'},
namespace_packages = ['erp5', 'erp5.recipe'],
install_requires = [
'infrae.subversion',
],
zip_safe=False,
entry_points = {'zc.buildout': ['default = %s:Recipe' % name]},
)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Copyright (c) 2006-2008 Zope Corporation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import infrae.subversion
class Recipe(infrae.subversion.Recipe):
def __init__(self, buildout, name, options):
base, revision, urls = options['base'], options['revision'], \
options['urls']
new_url_list = []
for url in options['urls'].split('\n'):
if url:
url = '%s/%s/%s %s' % (base, url, revision, url)
new_url_list.append(url)
options['urls'] = '\n'.join(new_url_list)
infrae.subversion.Recipe.__init__(self, buildout, name, options)
Changelog
=========
1.0 (2010-03-17)
----------------
- Initial version
[Rafael Monnerat]
Introduction
============
This recipe generates a new database on a mysql server.
Example
=======
You can use it with a part like this::
[default-database]
recipe = erp5.recipe.mysqldatabase
mysql_database_name = somename
mysql_user = root
mysql_password =
mysql_superuser = root
mysql_superpassword =
Options
=======
mysql_database_name
Mysql Database name.
mysql_host
Hostname which is running your mysql server. By Default uses localhost.
(Optional).
mysql_port
Port Number which is running your mysql server. By Default uses 3306.
(Optional).
mysql_user
User of new database, used to grant privilegies on the new database.
mysql_password
User's Password of new database, used to grant privilegies on the new
database.
mysql_superuser
User of mysql used to connect to mysql server to create the database.
mysql_superpassword
Password of user defined at mysql_superuser.
from setuptools import setup, find_packages
name = "erp5.recipe.mysqldatabase"
version = '1.0'
def read(name):
return open(name).read()
long_description=( read('README.txt')
+ '\n' +
read('CHANGES.txt')
)
setup(
name = name,
version = version,
author = "Nexedi",
author_email = "info@nexedi.com",
description = "ZC Buildout recipe for create a mysql database",
long_description=long_description,
license = "ZPL 2.1",
keywords = "zope2 buildout",
url='http://www.erp5.org/HowToUseBuildout',
classifiers=[
"License :: OSI Approved :: Zope Public License",
"Framework :: Buildout",
"Framework :: Zope2",
],
packages = find_packages('src'),
package_dir = {'': 'src'},
install_requires = ['zc.recipe.egg', ],
namespace_packages = ['erp5', 'erp5.recipe'],
entry_points = {'zc.buildout': ['default = %s:Recipe' % name]},
)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Copyright (c) 2006-2008 Zope Corporation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import os
import logging
import zc.buildout
class Recipe(object):
def __init__(self, buildout, name, options):
self.buildout, self.options, self.name = buildout, options, name
self.logger=logging.getLogger(self.name)
options['location'] = os.path.join(
buildout['buildout']['parts-directory'],
self.name,
)
options.setdefault('mysql_host', 'localhost')
options.setdefault('mysql_port', '3306')
def install(self):
options = self.options
location = options['location']
try:
import MySQLdb
except ImportError:
raise ImportError('To be able to create database MySQLdb is required'
' Install system wide or use software generated python')
database_name, user, password, port, host\
= \
options.get('mysql_database_name'), \
options.get('mysql_user'), \
options.get('mysql_password'), \
options.get('mysql_port'), \
options.get('mysql_host')
if not (database_name and user):
raise zc.buildout.UserError('database_name and user are '
'required to create database and grant privileges')
connection = MySQLdb.connect(
host = self.options.get('mysql_host'),
port = int(self.options.get('mysql_port')),
user = self.options.get('mysql_superuser'),
passwd = self.options.get('mysql_superpassword'),
)
connection.autocommit(0)
cursor = connection.cursor()
cursor.execute(
'CREATE DATABASE IF NOT EXISTS %s DEFAULT CHARACTER SET utf8 COLLATE '
'utf8_unicode_ci' % database_name)
privileges = ['GRANT ALL PRIVILEGES ON %s.* TO %s' % (
database_name, user)]
if host:
privileges.append('@%s' % host)
if password:
privileges.append(' IDENTIFIED BY "%s"' % password)
cursor.execute(''.join(privileges))
connection.commit()
connection.close()
return location
update = install
from setuptools import setup, find_packages
name = "erp5.recipe.openoffice"
version = '0.1'
setup(
name = name,
version = version,
author = "Nicolas Dumazet",
author_email = "nicolas.dumazet@nexedi.com",
description = "ZC Buildout recipe to install openoffice",
license = "ZPL 2.1",
keywords = "openoffice buildout",
classifiers=[
"License :: OSI Approved :: Zope Public License",
"Framework :: Buildout",
],
packages = find_packages('src'),
include_package_data = True,
package_dir = {'':'src'},
namespace_packages = ['erp5', 'erp5.recipe'],
install_requires = [
'z3c.recipe.openoffice',
],
zip_safe=False,
entry_points = {'zc.buildout': ['default = %s:Recipe' % name]},
)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Copyright (c) 2006-2008 Zope Corporation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import z3c.recipe.openoffice.recipe as original
import os
import platform
class Recipe(original.Recipe):
"""
Wrap z3c.recipe.openoffice to allow selecting the architecture
"""
def __init__(self, buildout, name, options):
machine = platform.uname()[-2]
if machine in ('i386', 'i586', 'i686'):
target = 'x86_32'
elif machine == 'x86_64':
target = 'x86_64'
else:
raise ValueError('Unknown machine')
options['download-url'] = options['download-%s' % target]
original.Recipe.__init__(self, buildout, name, options)
self.options['tmp-storage'] = buildout['buildout'].get('download-cache',
os.path.join(buildout['buildout']['directory'], 'download'))
Changelog
=========
0.4 (2010-03-18)
----------------
- continue fixing of deletion of data - update of instance could result in
buildout having stored location of instance, which then could be removed
[luke]
0.3 (2010-03-17)
----------------
- do not enable not set any preferences
[luke]
0.2 (2010-03-10)
----------------
- fix issues, that during uninstallation instance data was removed
[luke]
0.1 (2010-02-12)
----------------
- intial version
[luke]
Zope standalone instance
========================
This recipe is useful to create standalone Zope instance independent from
buildout tree.
Specification
=============
This recipe shall provide safe instance creation and updating. It shall mix
Zope level instance creation with ERP5 site bootstrap (erp5.recipe.zope2install
+ erp5.recipe.createsite). On update only filesystem will be *safely* updated
without touch user produced data (mostly from ZODB).
DISCLAIMER
==========
Until some stability will be met everything can change without any further
notice, without backward compatibility, possibly with *removing* existing data
produced by previous versions.
- be even more isolated
- support for Zope and ZEO
- in case of one Zope add normal directory
from setuptools import setup, find_packages
name = "erp5.recipe.standaloneinstance"
version = '0.4'
def read(name):
return open(name).read()
long_description=(
read('README.txt')
+ '\n' +
read('CHANGES.txt')
)
setup(
name = name,
version = version,
author = "Lukasz Nowak",
author_email = "luke@nexedi.com",
description = "ZC Buildout recipe to install standalone instance",
long_description=long_description,
license = "ZPL 2.1",
keywords = "zope2 buildout",
classifiers=[
"License :: OSI Approved :: Zope Public License",
"Framework :: Buildout",
"Framework :: Zope2",
],
packages = find_packages('src'),
include_package_data = True,
package_dir = {'':'src'},
namespace_packages = ['erp5', 'erp5.recipe'],
install_requires = [
'plone.recipe.zope2instance',
'erp5.recipe.mysqldatabase',
],
zip_safe=False,
entry_points = {'zc.buildout': ['default = %s:Recipe' % name]},
)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Copyright (c) 2006-2008 Zope Corporation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import os, sys, subprocess
from string import Template
import zc.buildout
import plone.recipe.zope2instance
import erp5.recipe.mysqldatabase
class WithMinusTemplate(Template):
idpattern = '[_a-z][-_a-z0-9]*'
class Recipe(plone.recipe.zope2instance.Recipe):
def __init__(self, buildout, name, options):
instancehome = options.get('instancehome')
if not instancehome:
raise zc.buildout.UserError('instancehome have to be specified')
options['control-script'] = options.get('control-script',
os.path.join(instancehome, 'bin', 'zopectl'))
self.egg = zc.recipe.egg.Egg(buildout, options['recipe'], options)
options['bin-directory'] = os.path.join(instancehome, 'bin')
options['scripts'] = '' # suppress script generation.
options['file-storage'] = options.get('file-storage',
os.path.join(instancehome, 'var', 'Data.fs'))
self.buildout, self.options, self.name = buildout, options, name
self.zope2_location = options.get('zope2-location', '')
# Relative path support for the generated scripts
relative_paths = options.get(
'relative-paths',
buildout['buildout'].get('relative-paths', 'false')
)
if relative_paths == 'true':
options['buildout-directory'] = buildout['buildout']['directory']
self._relative_paths = options['buildout-directory']
else:
self._relative_paths = ''
assert relative_paths == 'false'
def install(self):
# Override erp5.recipe.zope2instance so as to create several
# directories used by ERP5.
options = self.options
instancehome = options['instancehome']
requirements, ws = self.egg.working_set()
ws_locations = [d.location for d in ws]
if options.get('mysql_create_database', 'false').lower() == 'true':
# Use mysqldatabase recipe for Create the mysql database.
erp5.recipe.mysqldatabase.Recipe(self.buildout, self.name, self.options).install()
# What follows is a bit of a hack because the instance-setup mechanism
# is a bit monolithic. We'll run mkzopeinstance and then we'll
# patch the result. A better approach might be to provide independent
# instance-creation logic, but this raises lots of issues that
# need to be stored out first.
if not self.zope2_location:
mkzopeinstance = os.path.join(
options['bin-directory'], 'mkzopeinstance')
if not mkzopeinstance:
# EEE
return
else:
mkzopeinstance = os.path.join(
self.zope2_location, 'bin', 'mkzopeinstance.py')
if not os.path.exists(mkzopeinstance):
mkzopeinstance = os.path.join(
self.zope2_location, 'utilities', 'mkzopeinstance.py')
if sys.platform[:3].lower() == "win":
mkzopeinstance = '"%s"' % mkzopeinstance
if not mkzopeinstance:
# EEE
return
assert os.spawnl(
os.P_WAIT, os.path.normpath(options['executable']),
zc.buildout.easy_install._safe_arg(options['executable']),
mkzopeinstance, '-d',
zc.buildout.easy_install._safe_arg(instancehome),
'-u', options['user'],
) == 0
# patch begin: create several directories
for directory in ('Constraint', 'Document', 'PropertySheet', 'tests'):
path = os.path.join(instancehome, directory)
if not os.path.exists(path):
os.mkdir(path)
# patch end: create several directories
# Save the working set:
open(os.path.join(instancehome, 'etc', '.eggs'), 'w').write(
'\n'.join(ws_locations))
# Make a new zope.conf based on options in buildout.cfg
self.build_zope_conf()
# Patch extra paths into binaries
self.patch_binaries(ws_locations)
# Install extra scripts
self.install_scripts()
# Add zcml files to package-includes
self.build_package_includes()
if self.options.get('force-zodb-update','false').strip().lower() == 'true':
force_zodb_update = True
else:
force_zodb_update = False
if os.path.exists(options['zodb-path'].strip()) and not force_zodb_update:
# in case if there is no site available force update of ZODB
force_zodb_update = not self.is_site_available()
if not os.path.exists(options['zodb-path'].strip()) or \
force_zodb_update:
if os.path.exists(options['zodb-path'].strip()):
if not self.is_site_running():
# only in case if site is not running changes to ZODB are allowed
self.update_zodb()
# we return nothing, as this is totally standalone installation
return []
def is_site_running(self):
options = self.options
zopectl_path = os.path.join(options['bin-directory'],
options['control-script'])
argv = [zopectl_path, 'status']
(result_std, result_err) = subprocess.Popen(argv, stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()
result_std = result_std.strip()
if 'running' in result_std:
return True
return False
def is_site_available(self):
if self.is_site_running():
# in case of running site it is not possible to attach to Data.fs
# and even more - any change in Data.fs, even forced one, could be
# dangerous, so assume that running site do have site inside
return True
options = self.options
zopectl_path = os.path.join(options['bin-directory'],
options['control-script'])
script_name = os.path.join(os.path.dirname(__file__),
'portal_check.py')
argv = [zopectl_path, 'run', script_name, options.get('portal_id',
'erp5')]
(result_std, result_err) = subprocess.Popen(argv, stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()
result_std = result_std.strip()
if result_std == 'False':
return False
elif result_std == 'True':
return True
else:
raise ValueError('Unknwon response from %s: %r %r' % (argv, result_std,
result_err))
def update_zodb(self):
options = self.options
zopectl_path = os.path.join(options['bin-directory'],
options['control-script'])
script_name = os.path.join(os.path.dirname(__file__),
'create_erp5_instance.py')
argv = [zopectl_path, 'run', script_name]
if options.get('portal_id'):
argv.extend(['--portal_id', options['portal_id']])
if options.get('erp5_sql_connection_string'):
argv.extend(['--erp5_sql_connection_string',
options['erp5_sql_connection_string']])
if options.get('cmf_activity_sql_connection_string'):
argv.extend(['--cmf_activity_sql_connection_string',
options['cmf_activity_sql_connection_string']])
if options.get('erp5_catalog_storage'):
argv.extend(['--erp5_catalog_storage',
options['erp5_catalog_storage']])
if options.get('user'):
# XXX read rom zope2instance section ?
argv.extend(['--initial-user',
options['user']])
argv.extend(['--bt5-path',
os.path.join(options['bt5-path'])])
argv.extend([bt for bt in options.get('bt5', '').split('\n') if bt])
assert os.spawnl(
os.P_WAIT, zopectl_path, *argv ) == 0
def build_zope_conf(self):
options = self.options
instancehome = options['instancehome']
template_input_data = ''.join(
file(self.options['zope_conf_template'].strip()).readlines()
)
template = WithMinusTemplate(template_input_data)
# XXX: support local products with simple option instead of hardcoding
# make prepend products with 'products'
options_dict = self.options.copy()
if 'products' in options_dict:
prefixed_products = []
for product in options_dict['products'].split('\n'):
product = product.strip()
if product:
prefixed_products.append('products %s' % product)
options_dict['products'] = '\n'.join(prefixed_products)
result = template.substitute(options_dict)
zope_conf_path = os.path.join(instancehome, 'etc', 'zope.conf')
file(zope_conf_path, 'w').write(result)
def update(self):
# if self.options.get('force-zodb-update','false').strip().lower() == 'true':
# return self.install()
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) and self.is_site_available():
# 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 []
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)
)
# Create an ERP5 instance
# usage: zopectl run create_erp5_instance [options] [business templates]
import os
from optparse import OptionParser
from urllib import unquote
from Testing.makerequest import makerequest
from AccessControl.SecurityManagement import newSecurityManager
parser = OptionParser()
parser.add_option("-p", "--portal_id", dest="portal_id",
help="The ID of the Portal", default="erp5")
parser.add_option("--erp5_sql_connection_string",
dest="erp5_sql_connection_string",
help="Connection String used for ZSQLCatalog "
"(use %20 for space)",
default="test test")
parser.add_option("--cmf_activity_sql_connection_string",
dest="cmf_activity_sql_connection_string",
help="Connection String used for CMFActivity")
parser.add_option("--erp5_catalog_storage",
dest="erp5_catalog_storage",
help="Business Template for Catalog Storage")
parser.add_option("-u", "--initial-user",
dest="user_and_pass",
help="User and Password, separated by :",
default="zope:zope")
parser.add_option("--bt5-path",
dest="bt5_path",
help="Path to folder containing business templates. "
"Can be multiple, separated by commas.",
default="bt5")
(options, args) = parser.parse_args()
# cmf activity connection string defaults to zsqlcatalog's one
if not options.cmf_activity_sql_connection_string:
options.cmf_activity_sql_connection_string = \
options.erp5_sql_connection_string
# connection strings have to contain a space, for conveniance, this space can
# be replaced by %20 character.
options.erp5_sql_connection_string =\
unquote(options.erp5_sql_connection_string)
options.cmf_activity_sql_connection_string =\
unquote(options.cmf_activity_sql_connection_string)
username, password = options.user_and_pass.split(':')
try:
import transaction
except ImportError:
class Transaction:
def commit(self):
return get_transaction().commit()
transaction = Transaction()
app = makerequest(app)
user = app.acl_users.getUserById(username)
if user is None:
uf = app.acl_users
uf._doAddUser(username, password, ['Manager', 'Member', 'Assignee',
'Assignor', 'Author'], [])
user = uf.getUserById(username)
newSecurityManager(None, user.__of__(app.acl_users))
portal = getattr(app, options.portal_id, None)
if portal is None:
add_dict = dict(
id=options.portal_id,
erp5_sql_connection_string=options.erp5_sql_connection_string,
cmf_activity_sql_connection_string=\
options.cmf_activity_sql_connection_string,
erp5_catalog_storage='erp5_mysql_innodb_catalog' )
print 'Adding ERP5 site with parameters %r' % add_dict
app.manage_addProduct['ERP5'].manage_addERP5Site(**add_dict)
transaction.commit()
portal = app._getOb(options.portal_id)
# install our business templates
bt5_list = []
bt5_path_list = []
for i in options.bt5_path.split('\n'):
bt5_path_list.extend(i.split(","))
for arg in args:
bt_path = None
for path in bt5_path_list:
bt_path = os.path.join(path, arg)
if os.path.exists(bt_path):
break
else:
bt_path = None
if bt_path is None:
raise ValueError('Business Template %s not found in paths %s' % (arg,
options.bt5_path))
installed_bt = portal.portal_templates.getInstalledBusinessTemplate(arg)
if installed_bt is not None:
# XXX this way works only for extracted business template, not for
# *.bt5 packed business template.
version = file('%s/bt/version' % bt_path).read().strip()
revision = file('%s/bt/revision' % bt_path).read().strip()
if version == installed_bt.getVersion() and \
revision == installed_bt.getRevision():
print 'Skipping bt %s' % bt_path
continue
else:
print 'Updating bt %s' % bt_path
else:
print 'Installing bt %s' % bt_path
bt = portal.portal_templates.download(bt_path)
bt.install(force=True)
transaction.commit()
transaction.commit()
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