Commit 5b55ca0d authored by Fred Drake's avatar Fred Drake

Merge new scripts and configuration/installation support from the

new-install-branch.
parent de577f0b
#!python
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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 sys
mydir = os.path.dirname(os.path.abspath(sys.argv[0]))
zopehome = os.path.dirname(mydir)
softwarehome = os.path.join(zopehome, "lib", "python")
if softwarehome not in sys.path:
sys.path.append(softwarehome)
from ZEO.mkzeoinst import ZEOInstanceBuilder
class InstanceBuilder(ZEOInstanceBuilder):
def get_params(self, *args, **kw):
params = ZEOInstanceBuilder.get_params(self, *args, **kw)
sw = os.path.join(softwarehome, "lib", "python")
params["server"] = os.path.join(sw, "ZEO", "runzeo.py")
params["zdrun"] = os.path.join(sw, "zdaemon", "zdrun.py")
params["zdctl"] = os.path.join(sw, "zdaemon", "zdctl.py")
return params
if __name__ == "__main__":
InstanceBuilder().run()
#! python
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
##############################################################################
"""%(program)s: Create a Zope instance home.
usage: %(program)s [options] directory
Options:
-h/--help -- print this help text
-u/--user NAME:PASSWORD -- set the user name and password of the initial user
"""
import getopt
import os
import shutil
import sys
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "hu:", ["help", "user="])
except getopt.GetoptError, msg:
usage(sys.stderr, msg)
sys.exit(2)
user = None
password = None
for opt, arg in opts:
if opt in ("-h", "--help"):
usage(sys.stdout)
sys.exit()
if opt in ("-u", "--user"):
if not ":" in arg:
usage(sys.stderr, "user must be specified as name:password")
sys.exit(2)
user, password = arg.split(":", 1)
if len(args) != 1:
usage(sys.stderr, "mkzopeinstance requires exactly one argument")
sys.exit(2)
dirname = os.path.abspath(args[0])
inituser = os.path.join(dirname, "inituser")
if not (user or os.path.exists(inituser)):
user, password = get_inituser()
makeinstance(dirname, user, password, inituser)
def usage(stream, msg=None):
if msg:
print >>stream, msg
print >>stream
program = os.path.basename(sys.argv[0])
print >>stream, __doc__ % {"program": program}
def get_inituser():
import getpass
print 'Please choose a username and password for the initial user.'
print 'These will be the credentials you use to initially manage'
print 'your new Zope instance.'
print
user = raw_input("Username: ").strip()
if user == '':
return None, None
while 1:
passwd = getpass.getpass("Password: ")
verify = getpass.getpass("Verify password: ")
if verify == passwd:
break
else:
passwd = verify = ''
print "Password mismatch, please try again..."
return user, passwd
def makeinstance(dirname, user, password, inituser):
script = os.path.abspath(sys.argv[0])
installation = os.path.dirname(os.path.dirname(script))
skel = os.path.join(installation, "skel")
# Create the top of the instance:
if not os.path.exists(dirname):
os.mkdir(dirname)
replacements = {
"PYTHON": sys.executable,
"INSTANCE_HOME": dirname,
"SOFTWARE_HOME": os.path.join(installation, "lib", "python"),
"ZOPE_HOME": installation,
}
# This is fairly ugly. The chdir() makes path manipulation in the
# walk() callback a little easier (less magical), so we'll live
# with it.
pwd = os.getcwd()
os.chdir(skel)
try:
try:
os.path.walk(os.curdir, copyskel, (dirname, replacements))
finally:
os.chdir(pwd)
except (IOError, OSError), msg:
print >>sys.stderr, msg
sys.exit(1)
if user:
write_inituser(inituser, user, password)
def write_inituser(fn, user, password):
import binascii
import sha
fp = open(fn, "w")
pw = binascii.b2a_base64(sha.new(password).digest())[:-1]
fp.write('%s:{SHA}%s\n' % (user, pw))
fp.close()
os.chmod(fn, 0644)
CVS = os.path.normcase("CVS")
def copyskel((basedir, replacements), dirname, names):
# Don't recurse into CVS directories:
for name in names[:]:
if os.path.normcase(name) == CVS:
names.remove(name)
elif os.path.isfile(os.path.join(dirname, name)):
# Copy the file:
sn, ext = os.path.splitext(name)
if os.path.normcase(ext) == ".in":
dst = os.path.join(basedir, dirname, sn)
if os.path.exists(dst):
continue
copyin(os.path.join(dirname, name), dst, replacements)
else:
src = os.path.join(dirname, name)
dst = os.path.join(basedir, src)
if os.path.exists(dst):
continue
shutil.copyfile(src, dst)
else:
# Directory:
dn = os.path.join(basedir, dirname, name)
if not os.path.exists(dn):
os.mkdir(dn)
def copyin(src, dst, replacements):
ifp = open(src)
text = ifp.read()
ifp.close()
for k in replacements:
text = text.replace("<<%s>>" % k, replacements[k])
ofp = open(dst, "w")
ofp.write(text)
ofp.close()
shutil.copymode(src, dst)
if __name__ == "__main__":
main()
#!python
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Start Zope. Now!"""
import App.config
from Zope.Startup import handlers, options, start_zope
def main():
opts = options.ZopeOptions()
opts.realize()
handlers.handleConfig(opts.configroot, opts.confighandlers)
App.config.setConfiguration(opts.configroot)
start_zope(opts.configroot)
if __name__ == "__main__":
main()
#!python
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""zopectl -- control Zope using zdaemon.
Usage: zopectl [options] [action [arguments]]
Options:
-h/--help -- print usage message and exit
-b/--backoff-limit SECONDS -- set backoff limit to SECONDS (default 10)
-d/--daemon -- run as a proper daemon; fork a subprocess, close files etc.
-f/--forever -- run forever (by default, exit when backoff limit is exceeded)
-h/--help -- print this usage message and exit
-i/--interactive -- start an interactive shell after executing commands
-l/--logfile -- log file to be read by logtail command
action [arguments] -- see below
Actions are commands like "start", "stop" and "status". If -i is
specified or no action is specified on the command line, a "shell"
interpreting actions typed interactively is started (unless the
configuration option default_to_interactive is set to false). Use the
action "help" to find out about available actions.
"""
import os
import sys
import zdaemon
import Zope.Startup
from zdaemon.zdctl import ZDCmd
from zdaemon.zdoptions import ZDOptions
from zLOG.datatypes import FileHandlerFactory
class ZopeCtlOptions(ZDOptions):
"""Zope controller options.
After initialization, this should look very much like a
zdaemon.zdctl.ZDCtlOptions instance. Many of the attributes are
initialized from different sources, however.
"""
positional_args_allowed = 1
program = "zopectl"
schemadir = os.path.dirname(Zope.Startup.__file__)
schemafile = "zopeschema.xml"
# XXX Suppress using Zope's <eventlog> section to avoid using the
# same logging for zdctl as for the Zope appserver. There still
# needs to be a way to set a logfile for zdctl.
logsectionname = None
def __init__(self):
ZDOptions.__init__(self)
self.add("backofflimit", "runner.backoff_limit",
"b:", "backoff-limit=", int, default=10)
self.add("daemon", "runner.daemon", "d", "daemon", flag=1, default=0)
self.add("forever", "runner.forever", "f", "forever",
flag=1, default=0)
self.add("hang_around", "runner.hang_around", default=0)
self.add("interactive", None, "i", "interactive", flag=1)
self.add("default_to_interactive", "runner.default_to_interactive",
default=1)
self.add("logfile", None, "l:", "logfile=")
self.add("prompt", "runner.prompt", default="zopectl>")
def realize(self, *args, **kw):
ZDOptions.realize(self, *args, **kw)
config = self.configroot
self.directory = config.instancehome
self.program = [os.path.join(self.directory, "bin", "runzope")]
self.sockname = os.path.join(config.clienthome, "zopectlsock")
self.user = None
self.python = sys.executable
self.zdrun = os.path.join(os.path.dirname(zdaemon.__file__),
"zdrun.py")
self.exitcodes = [0, 2]
if self.logfile is None and config.eventlog is not None:
for handler in config.eventlog.handler_factories:
if isinstance(handler, FileHandlerFactory):
self.logfile = handler.section.path
if self.logfile not in ("STDERR", "STDOUT"):
break
class ZopeCmd(ZDCmd):
def _get_override(self, opt, name, svalue=None, flag=0):
# Suppress the config file, and pass all configuration via the
# command line. This avoids needing to specialize the zdrun
# script.
if name == "configfile":
return []
value = getattr(self.options, name)
if value is None:
return []
if flag:
if value:
args = [opt]
else:
args = []
else:
if svalue is None:
svalue = str(value)
args = [opt, svalue]
return args
def main(args=None):
# This is exactly like zdctl.main(), but uses ZopeCtlOptions and
# ZopeCmd instead of ZDCtlOptions and ZDCmd, so the default values
# are handled properly for Zope.
options = ZopeCtlOptions()
options.realize(args)
c = ZopeCmd(options)
if options.args:
c.onecmd(" ".join(options.args))
if options.interactive:
try:
import readline
except ImportError:
pass
print "program:", " ".join(options.program)
c.do_status()
c.cmdloop()
if __name__ == "__main__":
main()
#!/bin/sh
# Zope configure script
# $Id: configure,v 1.2 2003/03/18 21:27:49 fdrake Exp $
# $Revision: 1.2 $
#####################################################################
# BEGIN EDITABLE PARAMETERS #
#####################################################################
# Place the optimal target version number for Zope (as returned by sys.version)
# below
TARGET="2.2.2"
# Order a list of "acceptable" python version numbers (as returned by
# sys.version) below in "best" to "worst" order. Up to six
# acceptable python versions are allowed. Do not include the target
# version number in this list.
ACCEPTABLE="2.3 2.3a1 2.3a0"
# provide the executable names for all the acceptable versions
# (and the target version) below
EXENAMES="python python2 python2.1 python2.2 python2.3"
#####################################################################
# END EDITABLE PARAMETERS #
#####################################################################
# where are we?
HERE=`dirname $0`
usage()
{
echo
echo "configure [--help] [--with-python=path] [--prefix=path] "
echo " [--ignore-largefile]"
echo
echo " Creates a Makefile suitable for building and installing Zope"
echo
echo " Options: "
echo " --help shows usage and quits"
echo " --with-python specify a path to a Python interpreter to use"
echo " --prefix specify an installation path for binary data"
echo " --ignore-largefile ignore large file support warnings"
echo " --ignore-zlib ignore warnings about zlib"
echo
echo " Given no options, configure will search your PATH for a suitable"
echo " Python interpreter and will use '/usr/local/zope' as a prefix."
echo
}
# bootstrap ourselves by finding a Python interpreter if necessary
get_python() {
OLDIFS="$IFS"
IFS=":"
FOUND=""
VERSION=""
echo "Testing for an acceptable Python interpreter..."
echo
for DIR in $PATH; do
IFS="$OLDIFS"
for EXECUTABLE in $EXENAMES; do
FULL="$DIR/$EXECUTABLE"
if [ -x "$FULL" ]; then
CMD="import string,sys;print string.split(sys.version)[0]"
VERSION=`$FULL -c "$CMD"`
echo " Python version $VERSION found at $FULL"
if [ "$VERSION" = "$TARGET" ]; then
FOUND="$FULL"
FOUNDVERSION=$VERSION
break 2
else
i=1;
for ACC in $ACCEPTABLE; do
let "i = i + 1"
if [ "$VERSION" = "$ACC" ]; then
eval "FOUND$i=$FULL"
eval "FOUNDVERSION$i=$VERSION"
fi
done
fi
fi
done
done
if [ "$VERSION" = "$TARGET" ]; then
echo
echo " The optimimum Python version ($TARGET) was found at $FOUND."
elif [ -z "$FOUND1" ] && [ -z "$FOUND2" ] && [ -z "$FOUND3" ] &&
[ -z "$FOUND4" ] && [ -z "$FOUND5" ] && [ -z "$FOUND6" ] ; then
echo
echo " No suitable Python version found. You should install Python"
echo " version $TARGET before continuing. Versions $ACCEPTABLE"
echo " also work, but not as optimally."
exit 1
else
if [ -n "$FOUND1" ]; then
FOUND=$FOUND1
FOUNDVERSION=$FOUNDVERSION1
elif [ -n "$FOUND2" ]; then
FOUND=$FOUND2
FOUNDVERSION=$FOUNDVERSION2
elif [ -n "$FOUND3" ]; then
FOUND=$FOUND3
FOUNDVERSION=$FOUNDVERSION3
elif [ -n "$FOUND4" ]; then
FOUND=$FOUND4
FOUNDVERSION=$FOUNDVERSION4
elif [ -n "$FOUND5" ]; then
FOUND=$FOUND5
FOUNDVERSION=$FOUNDVERSION5
elif [ -n "$FOUND6" ]; then
FOUND=$FOUND6
FOUNDVERSION=$FOUNDVERSION6
fi
echo
echo " !! WARNING !! "
echo " An acceptable, but non-optimal Python version ($FOUNDVERSION) "
echo " was found at '$FOUND'."
echo " But consider installing version '$TARGET' before running "
echo " 'make'. If this isn't the Python version or interpreter "
echo " instance you wish to use, you may specify a Python interpreter"
echo " manually by rerunning the ./configure script with the "
echo " '--with-python' option."
fi
echo
}
NEWOPTS=""
for OPT in $@; do
case "$OPT" in
--h* | -h*)
usage
exit 0
;;
--with-python=*)
# pop this argument from the arglist, it is not valid to
# pass this along to the Python configurator.
shift;
FOUND=`echo $OPT | sed -e 's/--with-python\=//'`
# use eval to do tilde expansion below
eval "FOUND='$FOUND'"
echo
echo "Using Python interpreter at $FOUND"
;;
*)
NEWOPTS="$NEWOPTS $OPT"
;;
esac
done
echo
echo "Configuring Zope installation"
echo
if [ -z "$FOUND" ]; then
get_python
fi
# run the Python configurator
"$FOUND" "$HERE/inst/configure.py" $NEWOPTS
# Zope2 build and install Makefile.
# We do as much as possible in Python in order to avoid needing to
# learn autoconf or some other awful thing. ;-)
NAME=Zope
MAJOR_VERSION=<<ZOPE_MAJOR_VERSION>>
MINOR_VERSION=<<ZOPE_MINOR_VERSION>>
RELEASE_TAG=<<VERSION_RELEASE_TAG>>
PACKAGE_NAME=${NAME}-${MAJOR_VERSION}.${MINOR_VERSION}-${RELEASE_TAG}
PYTHON="<<PYTHON>>"
TARGET_DIR=<<TARGET_DIR>>
BUILD_DIR=<<BUILD_DIR>>
RM=rm -f
RMRF=rm -rf
FIND=find
XARGS=xargs
CD=cd
LN=ln -sf
CP=cp
INSTALL_COPY=${PYTHON} inst/install.py
WRITE_INFILE=${PYTHON} inst/file_from_infile.py
.PHONY : clean install uninstall instance links hacklinks untestinst testinst
.PHONY : default
default: build
@echo
@echo Zope built. Next, do \'make install\' \(or \'make instance\'
@echo to run a Zope instance directly from the build directory\).
@echo
build:
${PYTHON} inst/setup.py <<DISTUTILS_OPTS>> build_ext -i
install: build
${PYTHON} inst/setup.py <<DISTUTILS_OPTS>> install \
--home="${TARGET_DIR}" <<OPT_FLAGS>>
@echo
@echo Zope binaries installed successfully.
@echo Now run \'${TARGET_DIR}/bin/mkzopeinstance\'
instance: build
${PYTHON} bin/mkzopeinstance .
# testinst makes an instance home in the build directory without asking
# any questions. this is useful when testing. instances made with
# this can be removed via "make untestinst"
testinst: build
${PYTHON} bin/mkzopeinstance --user=admin:admin .
# remove the instance files made with testinst (w/ prejudice)
untestinst:
${RM} bin/zopectl.py
${RM} bin/ntservice.py
${RMRF} etc
${RMRF} log
uninstall:
${RMRF} "${TARGET_DIR}"
TESTOPTS=-v1 -d lib/python
test: build
${PYTHON} utilities/testrunner.py ${TESTOPTS}
clean:
${RMRF} build lib/python/build
${FIND} . -name '*.py[co]' -o -name 'core*' | ${XARGS} ${RM}
clobber: clean untestinst
${FIND} lib/python -name '*.so' | ${XARGS} ${RM}
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
##############################################################################
"""
Create a Makefile for building and installing Zope.
"""
import getopt
import os
import sys
import versions
if sys.platform == 'win32':
TARGET_DIR = 'c:\\Zope-' + versions.ZOPE_MAJOR_VERSION
IN_MAKEFILE = 'Makefile.win.in'
MAKE_COMMAND='the Visual C++ batch file "VCVARS32.bat" and then "nmake build"'
else:
TARGET_DIR = '/opt/Zope-' + versions.ZOPE_MAJOR_VERSION
IN_MAKEFILE = 'Makefile.in'
MAKE_COMMAND='make'
def main():
# below assumes this script is in the BUILD_DIR/inst directory
BUILD_DIR=os.path.abspath(os.path.dirname(os.path.dirname(sys.argv[0])))
PYTHON=sys.executable
MAKEFILE=open(os.path.join(BUILD_DIR, 'inst', IN_MAKEFILE)).read()
REQUIRE_LF_ENABLED = 1
REQUIRE_ZLIB=1
OPT_FLAGS = ''
zope_home = TARGET_DIR
build_dir = BUILD_DIR
python = PYTHON
try:
longopts = ["help", "ignore-largefile", "ignore-zlib", "prefix=",
"optimize"]
opts, args = getopt.getopt(sys.argv[1:], "h", longopts)
except getopt.GetoptError, v:
print v
usage()
sys.exit(1)
for o, a in opts:
if o in ('-h', '--help'):
usage()
sys.exit()
if o == '--prefix':
zope_home=os.path.abspath(os.path.expanduser(a))
if o == "--ignore-largefile":
REQUIRE_LF_ENABLED=0
if o == "--ignore-zlib":
REQUIRE_ZLIB=0
if o == "--optimize":
OPT_FLAGS = '--optimize=1 --no-compile'
if REQUIRE_LF_ENABLED:
test_largefile()
if REQUIRE_ZLIB:
test_zlib()
print " - Zope top-level binary directory will be %s." % zope_home
if OPT_FLAGS:
print " - Distutils install flags will be '%s'" % OPT_FLAGS
distutils_opts = ""
if sys.version[:3] < "2.3":
distutils_opts = "-q"
idata = {
'<<PYTHON>>':python,
'<<TARGET_DIR>>':zope_home,
'<<BUILD_DIR>>':build_dir,
'<<OPT_FLAGS>>':OPT_FLAGS,
'<<ZOPE_MAJOR_VERSION>>':versions.ZOPE_MAJOR_VERSION,
'<<ZOPE_MINOR_VERSION>>':versions.ZOPE_MINOR_VERSION,
'<<VERSION_RELEASE_TAG>>':versions.VERSION_RELEASE_TAG,
'<<DISTUTILS_OPTS>>':distutils_opts,
}
for k,v in idata.items():
MAKEFILE = MAKEFILE.replace(k, v)
f = open(os.path.join(BUILD_DIR, 'makefile'), 'w')
f.write(MAKEFILE)
print " - Makefile written."
print
print " Next, run %s." % MAKE_COMMAND
print
def usage():
usage = ("""
%(program)s configures and writes a Makefile for Zope.
Defaults for options are specified in brackets.
Configuration:
-h, --help display this help and exit
Options:
--ignore-zlib allow configuration to proceeed if
Python zlib module is not found.
--ignore-largefile allow configuration to proceed without
Python large file support.
--optimize compile Python files as .pyo files
instead of as .pyc files
Installation directories:
--prefix=DIR install Zope files in DIR [%(zope_home)s]
By default, 'make install' will install Zope software files in
'%(target_dir)s' You can specify an alternate location for these
files by using '--prefix', for example: '--prefix=$HOME/zope'.
""" % ({'program':sys.argv[0], 'target_dir':TARGET_DIR})
)
print usage
def test_zlib():
try:
import zlib
except ImportError:
print (
"""
The Python interpreter you are using does not appear to have the 'zlib'
library module installed. For Zope to be able to run, you must install a
Python interpreter which includes the zlib module, or install the zlib library
into your Python interpreter manually. The file which represents the library
is named 'zlib.so' (UNIX) or 'zlib.dll' (Windows) and is typically located in
the 'lib-dynload' directory of your Python's library directory. Some
Python packagers ship the zlib module as a separate installable binary. If you
are using a system-provided Python installation, you may want to look for
a 'python-zlib' package (or something like it) and install it to make the
Python zlib module available to Zope.
Run the configure script with the --ignore-zlib option to prevent this
warning with the understanding that Zope will not start properly until
you've installed the zlib module.
"""
)
sys.exit(1)
except:
print 'An error occurred while trying to import zlib!'
import traceback; traceback.print_exc()
sys.exit(1)
def test_largefile():
OK=0
f = open(sys.argv[0], 'r')
try:
# 2**31 == 2147483648
f.seek(2147483649L)
f.close()
OK=1
except (IOError, OverflowError):
f.close()
if OK:
return
print (
"""
This Python interpreter does not have 'large file support' enabled. Large
file support is required to allow the default Zope ZODB database to grow
larger than 2GB on most platforms. Either install a Python interpreter with
large file support (see
http://www.python.org/doc/current/lib/posix-large-files.html) or run this
program again with the --ignore-largefile option to prevent this warning,
with the understanding that your Zope may fail if the ZODB database
size ever exceeds 2GB.
"""
)
sys.exit(1)
if __name__ == '__main__':
main()
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
##############################################################################
"""
Reads a file named by 'src', performs textual replacements on the
file based on sed-style markup, and writes the result to the file named
by 'dst' unless 'dst' already exists.
"""
import getopt, os, sys
from os.path import abspath, split, dirname
import shutil
import versions
default_map = {
'PYTHON' : sys.executable,
'BASE_DIR' : abspath(split(dirname(sys.argv[0]))[0]),
'ZOPE_MAJOR_VERSION' : versions.ZOPE_MAJOR_VERSION,
'ZOPE_MINOR_VERSION' : versions.ZOPE_MINOR_VERSION,
'ZOPE_BRANCH_NAME' : versions.ZOPE_BRANCH_NAME,
'VERSION_RELEASE_TAG' : versions.VERSION_RELEASE_TAG,
}
def main(source, dest, map, force):
if not force and os.path.exists(dest):
print '%s exists, so I left it alone' % dest
else:
txt = open(source, 'rb').read()
for k, v in map.items():
txt = txt.replace('<<%s>>' % k, v)
outfile = open(dest, 'wb')
outfile.write(txt)
outfile.close()
shutil.copystat(source, dest)
print "Wrote %s from %s" % (dest, source)
def usage():
print "%s [opts] src dst" % sys.argv[0]
print
print "Reads a file named by 'src', performs textual replacements on "
print "the file based on sed-style markup embedded in the infile, and "
print "and writes the result to the file named by 'dst' unless 'dst'."
print "already exists. The generated file will have the same permissions"
print "and other mode bit settings as the source file."
print
print "Options:"
print
print " --force Force replacement of dst even if it already exists."
for name, value in default_map.items():
print (" --%s=value controls text replacement, default '%s'"
% (name, value))
if __name__ == '__main__':
if len(sys.argv) < 3:
usage()
sys.exit(127)
map = default_map.copy()
force = 0
try:
longopts = ['help', 'force']
for name in default_map.keys():
longopts.append('%s=' % name)
opts, args = getopt.getopt(sys.argv[1:], 'h', longopts)
except getopt.GetoptError, v:
print v
usage()
sys.exit(1)
try:
source, dest = args
except:
usage()
sys.exit(1)
for o, a in opts:
if o in ('-h', '--help'):
usage()
sys.exit()
if o == '--force':
force = 1
if o in map.keys():
map[o] = a
main(source, dest, map, force)
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
##############################################################################
"""
Generic file and directory installer.
Typically called when installing Zope via the Makefile written by
'configure.py' in the 'make install' step.
"""
import getopt
import os
import re
import shutil
import stat
import sys
# RE that, if a pathname's base name matches, causes it to be ignored
# when copying that file or directory.
default_omitpattern = r'(\..*|CVS|.*~)$'
def main(src, dst, dirmode=0755, fmode=0644,
omitpattern=default_omitpattern, retain_xbit=1):
"""
Copy a file or directory named by src to a file or directory named by
dst, normalizing mode bit settings as necessary. Recursively copies
directory trees using shutil.copy2().
Errors are reported to standard output.
- 'dirmode' is the directory creation mode. All directories
are created with this mode.
- 'fmode' is the default file creation mode. This mode
is modified by the status of the source file. If the source
file is executable, mod the fmode to be +wgo executable.
- omitpattern is a Python-style regex pattern. If a file
or directory name matches this pattern, it will never be copied.
- if the dst directory already exists, don't raise an error.
"""
try:
if os.path.isdir(src):
copydir(src, dst, dirmode, fmode, omitpattern,
retain_xbit)
else:
names = omit([src], omitpattern)
names and copyfile(names[0], dst, fmode, retain_xbit)
except (IOError, os.error), why:
print "Can't copy %s to %s: %s" % (`src`, `dst`, str(why))
def copydir(src, dst, dirmode, fmode, omitpattern, retain_xbit):
names = omit(os.listdir(src), omitpattern)
try:
# always create directories with dirmode
os.makedirs(dst, dirmode)
except os.error, why:
if why[0] == 17:
# directory already exists
pass
else:
raise
for name in omit(names, omitpattern):
srcname = os.path.join(src, name)
dstname = os.path.join(dst, name)
if os.path.isdir(srcname):
copydir(srcname, dstname, dirmode,fmode,omitpattern,
retain_xbit)
else:
copyfile(srcname, dstname, fmode, retain_xbit)
def copylink(src, dst):
linkto = os.readlink(src)
os.symlink(linkto, dst)
def copyfile(src, dst, mode, retain_xbit):
shutil.copy2(src, dst)
# change dest file mode to fmode but
# make +wgo executable if source file is executable
dstmode = mode
st = os.stat(src)
srcmode = st[stat.ST_MODE]
if retain_xbit and (srcmode & stat.S_IEXEC):
dstmode = (mode | 0111)
if os.path.isdir(dst):
# if dst is a directory, copy the file in to it
os.chmod(os.path.join(dst, os.path.split(src)[-1]), dstmode)
else:
os.chmod(dst, dstmode)
omitcache = {}
def omit(names, omitpattern):
return [ n for n in names
if not re.match(omitpattern, os.path.basename(n)) ]
def usage():
print "%s [opts] source dest" % sys.argv[0]
print
print "Copies a file or directory specified by 'source' to 'dest'"
print "normalizing mode bit settings as necessary."
print
print "If src is a file and dst is a directory, the file will be"
print "copied into the dst directory. However, if src is a directory"
print "and dst is a directory, the contents of src will be copied into"
print "dst."
print
print "opts: --dirmode=mode --fmode=mode --omitpattern=patt"
print
print " --dontcopyxbit when copying a file marked as executable,"
print " don't make the copy executable."
print " --dirmode mode bit settings of dest dirs (e.g. '755')"
print " --fmode mode bit settings of dest files (e.g. '644')"
print " (modified wgo+x when dontcopyxbit is not"
print " specified)"
print " --omitpattern a Python-style regex pattern. File and"
print " directory names which match this pattern will "
print " not be copied. The default omitpattern is"
print " '%s'" % default_omitpattern
if __name__ == '__main__':
if len(sys.argv) < 3:
print "too few arguments"
usage()
sys.exit(2)
dirmode = 0755
fmode = 0644
omitpattern = default_omitpattern
retain_xbit = 1
longopts = ['dirmode=', 'fmode=', 'omitpattern=', 'help',
'copyxmode' ]
try:
opts, args = getopt.getopt(sys.argv[1:], 'h', longopts)
except getopt.GetoptError, v:
print v
usage()
sys.exit(2)
try:
source, dest = args
except:
print "wrong number of arguments"
usage()
sys.exit(2)
for o, a in opts:
if o in ('-h', '--help'):
usage()
sys.exit()
if o == '--dirmode':
if not a.startswith('0'):
a = '0%s' % a
dirmode = eval(a)
if o == '--fmode':
if not a.startswith('0'):
a = '0%s' % a
fmode = eval(a)
if o == '--omitpattern':
omitpattern = a
if o == '--dontcopyxbit':
retain_xbit = 0
main(source, dest, dirmode, fmode, omitpattern, retain_xbit)
This diff is collapsed.
ZOPE_MAJOR_VERSION = '2.7'
ZOPE_MINOR_VERSION = '0'
ZOPE_BRANCH_NAME = '$Name$'[6:] or 'no-branch'
# always start prerelease branches with '0' to avoid upgrade
# issues in RPMs
VERSION_RELEASE_TAG = '0test'
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