Commit 0b6059aa authored by Marco Mariani's avatar Marco Mariani

initial import: extracted egg from slapos.cookbook

parents
*pyc
.installed.cfg
bin/
build
develop-eggs/
dist
downloads/
eggs/
parts/
slapos.cookbook.maarch.egg-info
.*.swp
Changelog
=========
0.1-dev (unreleased)
--------------------
- extracted egg from main recipe repositori [Marco Mariani]
.. contents::
slapos.recipe.maarch
====================
This diff is collapsed.
[buildout]
develop = .
parts = test
[test]
recipe = zc.recipe.testrunner
eggs = slapos.recipe.maarch [tests]
# -*- coding: utf-8 -*-
"""
This module contains the tool of slapos.recipe.maarch
"""
import os
from setuptools import setup, find_packages
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
version = '0.1'
long_description = read('README.txt') + '\n' + read('CHANGES.txt') + '\n'
entry_point = 'slapos.recipe.maarch:Recipe'
entry_points = {"zc.buildout": ["default = %s" % entry_point]}
tests_require = ['zope.testing', 'zc.buildout']
setup(name='slapos.recipe.maarch',
version=version,
description="",
long_description=long_description,
# Get more strings from
# http://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
'Framework :: Buildout',
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
],
keywords='',
author='Marco Mariani',
author_email='marco.mariani@nexedi.com',
url='http://git.erp5.org/gitweb/slapos.recipe.maarch.git',
license='GPLv3',
packages=find_packages(exclude=['ez_setup']),
namespace_packages=['slapos', 'slapos.recipe'],
include_package_data=True,
zip_safe=False,
install_requires=['setuptools',
'zc.buildout',
# -*- Extra requirements: -*-
'slapos.recipe',
'psycopg2',
],
tests_require=tests_require,
extras_require=dict(tests=tests_require),
test_suite='slapos.recipe.maarch.tests.test_docs.test_suite',
entry_points=entry_points,
)
__import__('pkg_resources').declare_namespace(__name__)
__import__('pkg_resources').declare_namespace(__name__)
Supported options
=================
The recipe supports the following options:
.. Note to recipe author!
----------------------
For each option the recipe uses you should include a description
about the purpose of the option, the format and semantics of the
values it accepts, whether it is mandatory or optional and what the
default value is if it is omitted.
option1
Description for ``option1``...
option2
Description for ``option2``...
Example usage
=============
.. Note to recipe author!
----------------------
zc.buildout provides a nice testing environment which makes it
relatively easy to write doctests that both demonstrate the use of
the recipe and test it.
You can find examples of recipe doctests from the PyPI, e.g.
http://pypi.python.org/pypi/zc.recipe.egg
The PyPI page for zc.buildout contains documentation about the test
environment.
http://pypi.python.org/pypi/zc.buildout#testing-support
Below is a skeleton doctest that you can start with when building
your own tests.
We'll start by creating a buildout that uses the recipe::
>>> write('buildout.cfg',
... """
... [buildout]
... parts = test1
...
... [test1]
... recipe = slapos.recipe.maarch
... option1 = %(foo)s
... option2 = %(bar)s
... """ % { 'foo' : 'value1', 'bar' : 'value2'})
Running the buildout gives us::
>>> buildout_output_lower = system(buildout).lower()
>>> "installing test1" in buildout_output_lower
True
>>> "unused options for test1: 'option2' 'option1'" in buildout_output_lower
True
##############################################################################
#
# Copyright (c) 2012 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import ConfigParser
import errno
import lxml.etree
import md5
import os
import lxml
import psycopg2
from slapos.recipe.librecipe import GenericBaseRecipe
# XXX: When run inside webrunner, Postgres refuses connection.
# TODO: make the recipe work inside webrunner
def xpath_set(xml, settings):
for path, value in settings.iteritems():
xml.xpath(path)[0].text = value
class Recipe(GenericBaseRecipe):
"""\
This recipe configures a maarch instance to be ready to run,
without going through the initial wizard:
- creation of two xml files from the provided defaults
- php.ini as required by Maarch
- database setup.
The superuser password will be the same as the Postgres one.
"""
def install(self):
self.update_phpini(php_ini_path=os.path.join(self.options['php_ini_dir'], 'php.ini'))
self.load_initial_db()
ret = []
apps_config_xml = self.create_apps_config_xml()
if apps_config_xml:
ret.append(apps_config_xml)
core_config_xml = self.create_core_config_xml()
if core_config_xml:
ret.append(core_config_xml)
# confirm that everything is done, the app will run without further setup
lck_path = self.installed_lock()
ret.append(lck_path)
return ret
def create_apps_config_xml(self):
options = self.options
folder = os.path.join(options['htdocs'], 'apps/maarch_entreprise/xml')
config_xml_default = os.path.join(folder, 'config.xml.default')
config_xml = os.path.join(folder, 'config.xml')
# do not overwrite the config.xml file (it can be customized inside the application)
if os.path.exists(config_xml):
return
content = open(config_xml_default, 'rb').read()
xml = lxml.etree.fromstring(content)
xpath_set(xml, {
'CONFIG/databaseserver': options['db_host'],
'CONFIG/databaseserverport': options['db_port'],
'CONFIG/databasename': options['db_dbname'],
'CONFIG/databaseuser': options['db_username'],
'CONFIG/databasepassword': options['db_password'],
'CONFIG/lang': options['language'],
})
with os.fdopen(os.open(config_xml, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o600), 'w') as fout:
fout.write(lxml.etree.tostring(xml, xml_declaration=True, encoding='utf-8').encode('utf-8'))
return config_xml
def create_core_config_xml(self):
options = self.options
folder = os.path.join(options['htdocs'], 'core/xml')
config_xml_default = os.path.join(folder, 'config.xml.default')
config_xml = os.path.join(folder, 'config.xml')
# do not overwrite the config.xml file (it can be customized inside the application)
if os.path.exists(config_xml):
return
content = open(config_xml_default, 'rb').read()
xml = lxml.etree.fromstring(content)
xpath_set(xml, {
'CONFIG/defaultlanguage': options['language'],
})
with os.fdopen(os.open(config_xml, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o600), 'w') as fout:
fout.write(lxml.etree.tostring(xml, xml_declaration=True, encoding='utf-8').encode('utf-8'))
return config_xml
def update_phpini(self, php_ini_path):
php_ini = ConfigParser.RawConfigParser()
php_ini.read(php_ini_path)
php_ini.set('PHP', 'error_reporting', 'E_ALL & ~E_DEPRECATED & ~E_NOTICE')
php_ini.set('PHP', 'display_errors', 'On')
php_ini.set('PHP', 'short_open_tag', 'On')
php_ini.set('PHP', 'magic_quotes_gpc', 'Off')
with os.fdopen(os.open(php_ini_path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o600), 'w') as fout:
php_ini.write(fout)
def load_initial_db(self):
"""
This method:
- creates the initial schema
- patches the schema for ipv6
- loads initial data
- sets initial superadmin password
- configures and creates docservers directories
"""
options = self.options
conn = psycopg2.connect(host = options['db_host'],
port = int(options['db_port']),
database = options['db_dbname'],
user = options['db_username'],
password = options['db_password'])
cur = conn.cursor()
# skip everything if the tables have already been created
cur.execute("SELECT 1 FROM information_schema.tables WHERE table_schema='public' AND table_name='docservers';")
if cur.rowcount == 1:
conn.close()
return
htdocs = options['htdocs']
# load the schema
with open(os.path.join(htdocs, 'structure.sql')) as fin:
cur.execute(fin.read())
# patch the schema to store long addresses (ipv6)
cur.execute('ALTER TABLE HISTORY ALTER COLUMN remote_ip TYPE CHAR(255);')
with open(os.path.join(htdocs, 'data_mini.sql')) as fin:
cur.execute(fin.read())
# initial admin password
enc_password = md5.md5(options['db_password']).hexdigest()
cur.execute("UPDATE users SET password=%s WHERE user_id='superadmin';", (enc_password, ))
# directories described in http://wiki.maarch.org/Maarch_Entreprise/fr/Man/Admin/Stockage
for docserver_id, foldername in [
('OFFLINE_1', 'offline'),
('FASTHD_AI', 'ai'),
('OAIS_MAIN_1', 'OAIS_main'),
('OAIS_SAFE_1', 'OAIS_safe'),
('FASTHD_MAN', 'manual'),
('TEMPLATES', 'templates'),
]:
full_path = os.path.join(self.options['root_docservers'], foldername)
cur.execute('UPDATE docservers SET path_template=%s WHERE docserver_id=%s', (full_path, docserver_id))
try:
os.makedirs(full_path)
except OSError as exc:
if exc.errno == errno.EEXIST:
pass
else:
raise
conn.commit()
cur.close()
conn.close()
def installed_lock(self):
"""\
Create an empty file to mean the setup is completed
"""
htdocs = self.options['htdocs']
lck_path = os.path.join(htdocs, 'installed.lck')
with open(lck_path, 'w'):
pass
return lck_path
# -*- coding: utf-8 -*-
"""
Doctest runner for 'slapos.recipe.maarch'.
"""
__docformat__ = 'restructuredtext'
import unittest
import doctest
import zc.buildout.tests
import zc.buildout.testing
from zope.testing import renormalizing
optionflags = (doctest.ELLIPSIS |
doctest.NORMALIZE_WHITESPACE |
doctest.REPORT_ONLY_FIRST_FAILURE)
def setUp(test):
zc.buildout.testing.buildoutSetUp(test)
# Install the recipe in develop mode
zc.buildout.testing.install_develop('slapos.recipe.maarch', test)
# Install any other recipes that should be available in the tests
#zc.buildout.testing.install('collective.recipe.foobar', test)
def test_suite():
suite = unittest.TestSuite((
doctest.DocFileSuite(
'../README.txt',
setUp=setUp,
tearDown=zc.buildout.testing.buildoutTearDown,
optionflags=optionflags,
checker=renormalizing.RENormalizing([
# If want to clean up the doctest output you
# can register additional regexp normalizers
# here. The format is a two-tuple with the RE
# as the first item and the replacement as the
# second item, e.g.
# (re.compile('my-[rR]eg[eE]ps'), 'my-regexps')
zc.buildout.testing.normalize_path,
]),
),
))
return suite
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
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