Fabric – instale Python, Zope 2 e crie uma instância Zope (Linux)

Sobre
Um script que escrevi recentemente para automatizar a instalação do Python, Zope 2, setuptools, psycopg2 e PyXML.

Uso
Instalar Fabric. Salve o código abaixo em um arquivo chamado fabfile.py. Para listar todas as funções disponíveis, use

fab -l 

Para executar todo o procedimento de configuração (ou seja, instalar Python, Zope, psycopg2, PyXML e criar uma instância zope), use

fab run_setup

Teste
Se não houver erros, uma instância do zope deve ter sido criada no zopediretório. Inicie a instância

cd zopebin
./zopectl start

Navegar para

http: // localhost: 8080 / manage [interface de administrador]
nome de usuário: admin, senha: admin

OU

http: // localhost: 8080 [site]

"""fabfile.py - Fabric script to setup Python and Zope2 (Linux)"""
import os
import tarfile
from fabric.api import local, lcd

### CONFIGURATION ###

# By default, the current directory is used
PREFIX
= os.getcwd()

# Python and Zope scripts will be installed under EXEC_PREFIX/bin
EXEC_PREFIX
= os.path.join(PREFIX, "Programs")

# Zope instance will be created under ZOPE_HOME
ZOPE_HOME
= os.path.join(PREFIX, "zope")

### END CONFIGURATION ###

PKGS
= {
"python": [
"Python-2.3.7.tar.bz2",
"http://www.python.org/ftp/python/2.3.7/Python-2.3.7.tar.bz2#fa73476c5214c57d0751fae527f991e1"
],
"setuptools": [
"setuptools-0.6c11.tar.gz",
"http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e"
],
"zope": [
"Zope-2.8.7-final.tgz",
"http://old.zope.org/Products/Zope/2.8.7/Zope-2.8.7-final.tgz#1b5cfce7bf70ac877c3662441d08dfb9"
]
}

# Additional dependencies - installed with easy_install
DEPS
= ["psycopg2==2.0.8", "PyXML"]

# Use python 2.3 to compile everything else
PYTHON
= os.path.join(EXEC_PREFIX, "bin", "python")


def _make_install():
"""Run make and make install"""
local("make -s")
local("make -s install")


def _prepare(pkg):
"""Download and extract the given archive"""
fname
, url = PKGS[pkg]
if not os.path.exists(fname):
local("wget -nv {0}".format(url))
else:
print "Package exists: {0}".format(fname)

archive
= tarfile.open(fname)
archdir
= os.path.commonprefix(archive.getnames())
archive
.extractall()
archive
.close()

# so we can next run configure
return archdir


def install_python():
"""Intall Python 2.3 with zlib support"""
pydir
= _prepare("python")
with lcd(pydir):
print "Building and installing Python"
local("./configure --prefix={0}".format(EXEC_PREFIX))

print "Enable zlib support for Python"
local(r"sed -i 's:#(zlib.*):1:' Modules/Setup")
_make_install
()


def install_deps():
"""Install dependencies"""

pkgdir
= _prepare("setuptools")
with lcd(pkgdir):
print "Install setuptools"
local("{0} setup.py -q install".format(PYTHON))

# install additional dependencies
easy_install
= os.path.join(EXEC_PREFIX, "bin", "easy_install")
for dep in DEPS:
print "Install {0}".format(dep)
local("{0} -q {1}".format(easy_install, dep))


def install_zope():
"""Install Zope"""
zopedir
= _prepare("zope")
with lcd(zopedir):
print "Build and install Zope"
local("./configure --prefix={0} --with-python={1} "
"--optimize".format(EXEC_PREFIX, PYTHON))
_make_install
()


def make_zope_instance():
"""Create Zope instance"""
print "Creating Zope instance"
local("{0} {1} -d {2} -u admin:admin".format(PYTHON,
os
.path.join(EXEC_PREFIX, "bin/mkzopeinstance.py"), ZOPE_HOME))


def run_setup():
"""Run all steps"""
print "Install Python"
install_python
()

print "Install dependencies"
install_deps
()

print "Install Zope"
install_zope
()

print "Create Zope instance"
make_zope_instance
()

print "Finished"


if __name__ == "__main__":
run_setup
()