Commit 3f65fccf authored by Nicolas Delaby's avatar Nicolas Delaby

Recipe usefull to install business templates into erp5 instance

through XML-RPC transport.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36008 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 08661821
Changelog
=========
0.1 (2010-06-03)
----------------
- intial version
[nicolas]
Business Templates installer through XML-RPC
================================================
Easy way to install Business Templates
[install-business-templates]
recipe = erp5.recipe.installbusinesstemplate
repository_path = file://${bt5list:location}
bt5_list = ${bt5list:bt5_urls}
update_catalog = false
protocol = http
user = ${zope-instance:user}
hostname = ${zope-instance:ip-address}
port = ${zope-instance:http-address}
portal_id = ${zope-instance:portal_id}
\ No newline at end of file
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
name = "erp5.recipe.installbusinesstemplate"
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 = "Nicolas Delaby",
author_email = "nicolas@nexedi.com",
description = "ZC Buildout recipe to install easily BT5 from repository",
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]},
)
# -*- coding: utf-8 -*-
# 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 -*-
# 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 -*-
# -*- 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 xmlrpclib
#import zc.buildout
import zc.buildout.easy_install
import zc.buildout.download
import zc.recipe.egg
import subprocess
class Recipe(object):
MAX_BT_PER_TRANSACTION = 2
def __init__(self, buildout, name, options):
self.buildout, self.options, self.name = buildout, options, name
self.logger = logging.getLogger(self.name)
self.egg = zc.recipe.egg.Egg(buildout, options['recipe'], options)
options.setdefault('location', os.path.join(
buildout['buildout']['parts-directory'],
self.name,
))
# Business Template installation
options.setdefault('repository_path', '')
options.setdefault('bt5_list', '')
options.setdefault('update_catalog', 'false')
# XML-RPC connection
options.setdefault('protocol', 'http')
options.setdefault('user', '')
options.setdefault('hostname', 'localhost')
options.setdefault('port', '8080')
options.setdefault('portal_id', 'erp5')
def _getConnectionString(self):
"""Return connection string to connect
to instance
"""
options = self.options
connection_string = '%(protocol)s://%(user)s@%(hostname)'\
's:%(port)s/%(portal_id)s/' % options
return connection_string
def _getConnection(self, connection_string):
"""Return XML-RPC connected object
"""
connection = xmlrpclib.ServerProxy(connection_string, allow_none=True)
return connection
def install(self):
options = self.options
location = options['location']
if not os.path.exists(location):
os.mkdir(location)
connection = self._getConnection(self._getConnectionString())
# install templates
repository_path = options['repository_path']
connection.portal_templates.updateRepositoryBusinessTemplateList(
[repository_path], None)
bt5_list = [bt5 for bt5 in options['bt5_list'].splitlines() if bt5]
update_catalog = options['update_catalog'].lower() == 'true' or False
while bt5_list:
partial_bt5_list = bt5_list[:self.MAX_BT_PER_TRANSACTION]
print 'Installing following business template:',\
', '.join(partial_bt5_list)
result = connection.portal_templates\
.installBusinessTemplatesFromRepositories(partial_bt5_list,
True, update_catalog)
bt5_list = bt5_list[self.MAX_BT_PER_TRANSACTION:]
return [] # instance related recipe, it can be disaster to allow buildout
# to remove instances
update = install
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