[Zope-Checkins] CVS: Zope/inst - source_install.py:1.1.2.1 configure.py:1.1.2.5

Chris McDonough chrism@zope.com
Wed, 28 Aug 2002 00:12:31 -0400


Update of /cvs-repository/Zope/inst
In directory cvs.zope.org:/tmp/cvs-serv3154/inst

Modified Files:
      Tag: chrism-install-branch
	configure.py 
Added Files:
      Tag: chrism-install-branch
	source_install.py 
Log Message:
Do a better job of copying files and directories to the target directory.  Set sane permissions for each file and directory copied.

Moved lots of logic into Python to avoid the vagaries of cross-platform shell scripting.


=== Added File Zope/inst/source_install.py ===
##############################################################################
#
# 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
#
##############################################################################
"""
Installer which copies source directory and its contents to dest directory,
optionally removing files in the dest directory.

Typically called when installing Zope via the Makefile written by
'configure.py' in the 'make install' step.
"""
import sys, getopt, os, stat, glob, fnmatch
from shutil import copy2, rmtree

def main():
    source = None
    dest   = None
    rmlist = []
    try:
        longopts = ["src=", "dst=", "rm-from-dst=", "help"]
        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  == '--src':
            source = a
        if o == '--dst':
            dest = a
        if o == '--rm-from-dst':
            rmlist = a.split()
    if source is None or dest is None:
        usage()
        sys.exit(127)
    try:
        copytree(source, dest)
        for name in rmlist:
            fname = os.path.join(dest, name)
            names = glob.glob(fname)
            for name in names:
                try:
                    if os.path.isdir(name):
                        rmtree(name)
                    else:
                        os.remove(name)
                except os.error, why:
                    print "Could not remove %s from target dir" % name
    except:
        import traceback
        traceback.print_exc()
        usage()
        sys.exit(127)

def usage():
    print ("%s --src=sourcedir --dst=destdir "
           "[--rm-from-dst=filename-list]") % sys.argv[0]

def copytree(src, dst, symlinks=1, dirmode=0755, fmode=0644,
             omitpattern=".*"):
    """Recursively copy a directory tree using copy2().

    Errors are reported to standard output.

    If the optional symlinks flag is true, symbolic links in the
    source tree result in symbolic links in the destination tree; if
    it is false, the contents of the files pointed to by symbolic
    links are copied.

    This differs from the shutils.copytree function in these ways:

      - symlinks are 'on' by default.
      - '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 defines a UNIX-style filename 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.

    """
    names = os.listdir(src)
    names = [ n for n in names if not fnmatch.fnmatch(n, 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 names:
        srcname = os.path.join(src, name)
        dstname = os.path.join(dst, name)
        try:
            if symlinks and os.path.islink(srcname):
                linkto = os.readlink(srcname)
                os.symlink(linkto, dstname)
            elif os.path.isdir(srcname):
                copytree(srcname, dstname, symlinks, dirmode, fmode)
            else:
                copy2(srcname, dstname)
                # change dest file mode to fmode but
                # make +wgo executable if source file is executable
                dstmode = fmode
                st = os.stat(srcname)
                srcmode = st[stat.ST_MODE]
                if srcmode & stat.S_IEXEC:
                    dstmode = (fmode | 0111)
                os.chmod(dstname, dstmode)
        except (IOError, os.error), why:
            print "Can't copy %s to %s: %s" % (`srcname`, `dstname`, str(why))


if __name__ == '__main__':
    main()
    


=== Zope/inst/configure.py 1.1.2.4 => 1.1.2.5 ===
--- Zope/inst/configure.py:1.1.2.4	Mon Aug 26 12:52:08 2002
+++ Zope/inst/configure.py	Wed Aug 28 00:12:30 2002
@@ -21,49 +21,8 @@
 BUILD_DIR     = os.path.abspath(os.path.split(os.path.dirname(sys.argv[0]))[0])
 ZOPE_HOME     = '/usr/local/zope'
 PYTHON        = sys.executable
-MAKEINSTANCE  = """#!/bin/sh
-%(python)s %(zope_home)s/inst/make_instance.py
-"""
-
-MAKEFILE = """
-PYTHON=%(python)s
-ZOPE_HOME=%(zope_home)s
-BUILD_DIR=%(build_dir)s
-CPRU=cp -R
-MKDIR=mkdir -p
-RM=rm -rf
-FIND=find
-TOUCH=touch
-XARGS=xargs
-
-.PHONY : clean install uninstall
-
-build:
-	${PYTHON} ${BUILD_DIR}/inst/compile_all.py
-	${TOUCH} ${BUILD_DIR}/build
-	@echo
-	@echo Zope built.  Next, do \\'make install\\'.
-
-install: build
-	${MKDIR} ${ZOPE_HOME}
-	${CPRU} ${BUILD_DIR}/* ${ZOPE_HOME}
-	${RM} ${ZOPE_HOME}/{Makefile,configure,stupid_clean}
-	${RM} ${ZOPE_HOME}/{w_pcgi.py,wo_pcgi.py,setup.py}
-	${RM} ${ZOPE_HOME}/{start,stop,build,inituser}
-	${RM} ${ZOPE_HOME}/*.py[co]
-	@echo
-	@echo Zope binaries installed successfully.
-	@echo Now run \"${ZOPE_HOME}/makeinstance.\"
-
-uninstall:
-	${RM} ${ZOPE_HOME}
-
-clean:
-	${FIND} ${BUILD_DIR} -name '*.o' -o -name '*.so' -o -name '*.py[co]' \
-          -o -name 'core*' | ${XARGS} rm -f
-	${RM} ${BUILD_DIR}/build
-"""
-
+MAKEINSTANCE  = open(os.path.join(BUILD_DIR, 'makeinstance.in')).read()
+MAKEFILE = open(os.path.join(BUILD_DIR, 'Makefile.in')).read()
 def main():
     REQUIRE_LF_ENABLED = 1
     zope_home = ZOPE_HOME
@@ -81,7 +40,7 @@
             usage()
             sys.exit()
         if o == '--prefix':
-            zope_home=a
+            zope_home=os.path.abspath(os.path.expanduser(a))
         if o == "--ignore-largefile":
             REQUIRE_LF_ENABLED=0
     if REQUIRE_LF_ENABLED: