Commits

Anonymous committed 7eae2cb

New installer for POSIX

  • Participants
  • Parent commits 0cd6f25

Comments (0)

Files changed (6)

 all:
 
 install:
-	@(PREFIX=$(PREFIX) PYTHON=$(PYTHON) ./scripts/install-posix)
+	@($(PYTHON) scripts/install-posix $(PREFIX))
 
 uninstall:
-	@(PREFIX=$(PREFIX) ./scripts/uninstall-posix)
+	@(PREFIX=$(PREFIX) /bin/sh ./scripts/_uninstall-posix.sh)

File scripts/_install-posix.py

+# -*- coding: utf-8 -*-
+"""
+    POSIX Installation
+    ~~~~~~~~~~~~~~~~~~
+
+    This script is invoked by the makefile to install Zine on a POSIX system.
+
+    :copyright: 2008 by Armin Ronacher.
+    :license: BSD, see LICENSE for more details.
+"""
+import sys
+import os
+from subprocess import call as run
+from glob import glob
+
+
+join = os.path.join
+
+
+PACKAGES = '_dynamic _ext importers utils views websetup i18n docs'.split()
+SCRIPTS = 'create-apache-config server shell'.split()
+
+
+def copy_folder(src, dst, recurse=True):
+    if recurse:
+        shutil.copytree(src, dst)
+    else:
+        for filename in os.path.listdir(src):
+            filename = join(src, dst)
+            if os.path.isfile(filename):
+                shutil.copy2(filename, dst)
+
+
+def copy_servers(source, destination, lib_dir, python):
+    silent(os.makedirs, destination)
+    for filename in os.path.listdir(source):
+        f = file(join(source, filename))
+        try:
+            lines = list(f)
+            if lines[0].startswith('#!'):
+                lines[0] = '#!%s\n' % python
+            for idx, line in enumerate(lines):
+                if line.startswith('ZINE_LIB ='):
+                    lines[idx] = 'ZINE_LIB = %r\n' % lib_dir
+                    break
+        finally:
+            f.close()
+        f = file(join(destination, filename), 'w')
+        try:
+            f.write(''.join(lines))
+        finally:
+            f.close()
+
+
+def copy_scripts(source, destination, lib_dir):
+    silent(os.makedirs, destination)
+    f = file(join(source, '_init_zine.py'))
+    try:
+        contents = f.read().replace('ZINE_LIB = None',
+                                    'ZINE_LIB = %r' % lib_dir)
+    finally:
+        f.close()
+    f = file(join(destination, filename), 'w')
+    try:
+        f.write(contents)
+    finally:
+        f.close()
+    for script in SCRIPTS:
+        shutil.copy2(join(source, script), destination)
+
+
+def main(prefix):
+    python = sys.executable
+    source = os.path.abspath('..')
+    zine_source = join(source, 'zine')
+    lib_dir = join(prefix, 'lib', 'zine')
+    share_dir = join(prefix, 'share', 'zine')
+
+    print 'Installing to ' + prefix
+    print 'Using ' + python
+
+    # create some folders for us
+    silent(os.makedirs, join(lib_dir, 'zine'))
+    silent(os.makedirs, share_dir)
+
+    # copy the packages and modules into the zine package
+    copy_folder(zine_source, join(lib_dir, 'zine'),
+                recurse=False)
+    for package in packages:
+        copy_folder(join(zine_source, package),
+                    join(lib_dir, 'zine', package))
+
+    # copy the plugins over
+    copy_folder(join(zine_source, 'plugins'),
+                join(lib_dir, 'plugins'))
+
+    # compile all files
+    run([sys.executable, '-O', '-mcompileall', '-qf',
+         join(lib_dir, 'zine'), join(lib_dir, 'plugins')])
+
+    # templates and shared data
+    copy_folder(join(zine_source, 'shared'),
+                join(share_dir, 'htdocs'))
+    copy_folder(join(zine_source, 'templates'),
+                join(share_dir, 'templates'))
+
+    # copy the server files
+    copy_servers(join(source, 'servers'),
+                 join(share_dir, 'servers'), lib_dir, python)
+
+    # copy the scripts
+    copy_scripts(join(source, 'scripts'),
+                 join(share_dir, 'scripts'), lib_dir)
+    print 'All done.'
+
+
+if __name__ == '__main__':
+    if len(sys.args) != 2:
+        print >> sys.stderr, 'error: install script only accepts a prefix'
+        sys.exit(1)
+    main(sys.args[1])

File scripts/_uninstall-posix.sh

+#!/bin/bash
+# This script uninstalls zine from PREFIX which defaults
+# to /usr.
+
+if [ x$PREFIX == x ]; then
+  PREFIX=/usr
+fi
+
+echo "Uninstalling Zine from $PREFIX"
+rm -rf $PREFIX/lib/zine
+rm -rf $PREFIX/share/zine
+echo "All done."

File scripts/create-package

     pass
 
 
-def find_files():
+def find_files(force):
     allowed_states = frozenset('CI?')
     client = subprocess.Popen(['hg', 'status', '-A'], stdout=subprocess.PIPE)
     for line in client.communicate()[0].splitlines():
         if len(line) != 2:
             continue
         status, filename = line
-        if status not in allowed_states:
+        if not force and status not in allowed_states:
             raise BuildError('hg unclean. Uncommited modifications?')
         if status == 'C' and not is_ignored(filename):
             yield filename
                 os.remove(filename)
 
 
-def build(dst_dir, build_dir, formats):
+def build(dst_dir, build_dir, options):
     zine_version = get_zine_version()
     release_name = 'Zine-%s' % '-'.join(zine_version.split())
     archive_base = os.path.join(dst_dir, release_name)
 
     # copy all tracked files into the build dir
     print 'Bootstrapping build directory [%s]' % build_dir
-    for filename in find_files():
+    for filename in find_files(options.force):
         target_folder = os.path.join(release_dir, os.path.dirname(filename))
         if not os.path.exists(target_folder):
             os.makedirs(target_folder)
     old_dir = os.getcwd()
     try:
         os.chdir(build_dir)
-        if formats.tar:
+        if options.tar:
             tarball_filename = archive_base + '.tar.gz'
             subprocess.call(['tar', 'vczf', tarball_filename, release_name])
             messages.append('Created tarball in %s' % tarball_filename)
-        if formats.zip:
+        if options.zip:
             zip_filename = archive_base + '.zip'
             subprocess.call(['zip', '-r', zip_filename, release_name])
             messages.append('Created zip file in %s' % zip_filename)
                       default=True, help='Do not generate a .zip file')
     parser.add_option('--no-tar', dest='tar', action='store_false',
                       default=True, help='Do not generate a tarball')
+    parser.add_option('-f', '--force', dest='force', action='store_true',
+                      default=False, help='Force build, even if local '
+                      'modifications exist.')
     options, args = parser.parse_args()
     if len(args) != 1:
         parser.error('incorrect number of arguments')

File scripts/install-posix

-#!/bin/bash
-# This script copies zine into PREFIX and compiles the python
-# files with PYTHON.  If PREFIX is not defined /usr is assumed.
-
-SRC="`dirname $0`/../zine"
-PACKAGES="_dynamic _ext importers utils views websetup i18n docs"
-SCRIPTS="create-apache-config server shell"
-
-
-if [ x$PREFIX == x ]; then
-  PREFIX=/usr
-fi
-if [ x$PYTHON == x ]; then
-  PYTHON=`which python`
-fi
-
-echo "Installing to $PREFIX"
-echo "Using $PYTHON"
-
-# make sure the target folders exist
-mkdir -p $PREFIX/lib/zine/zine
-mkdir -p $PREFIX/share/zine
-
-# the packages to copy
-cp $SRC/*.py $PREFIX/lib/zine/zine
-for package in $PACKAGES; do
-  mkdir -p $PREFIX/lib/zine/zine/$package
-  cp -R $SRC/$package $PREFIX/lib/zine/zine/
-done
-
-# all the plugins
-cp -R $SRC/plugins $PREFIX/lib/zine
-
-# compile all files
-$PYTHON -O -mcompileall -qf $PREFIX/lib/zine/{zine,plugins}
-
-# templates and shared data
-cp -R $SRC/shared $PREFIX/share/zine/htdocs
-cp -R $SRC/templates $PREFIX/share/zine/templates
-
-# copy the server files and adjust the ZINE_LIB path
-cp -R $SRC/../servers $PREFIX/share/zine
-sed -i '' -e "s|^ZINE_LIB =.*$|ZINE_LIB = '$PREFIX/lib/zine'|g" \
-    -e "s|^#!/usr/bin/python|#!$PYTHON|g" $PREFIX/share/zine/servers/*
-
-# copy some of the scripts
-mkdir -p $PREFIX/share/zine/scripts
-for script in $SCRIPTS; do
-  cp $SRC/../scripts/$script $PREFIX/share/zine/scripts
-  chmod +x $PREFIX/share/zine/scripts
-done
-cp $SRC/../scripts/_init_zine.py $PREFIX/share/zine/scripts
-sed -i '' -e "s|^ZINE_LIB = None$|ZINE_LIB = '$PREFIX/lib/zine'|g" \
-   $PREFIX/share/zine/scripts/_init_zine.py
-
-echo "All done."

File scripts/uninstall-posix

-#!/bin/bash
-# This script uninstalls zine from PREFIX which defaults
-# to /usr.
-
-if [ x$PREFIX == x ]; then
-  PREFIX=/usr
-fi
-
-echo "Uninstalling Zine from $PREFIX"
-rm -rf $PREFIX/lib/zine
-rm -rf $PREFIX/share/zine
-echo "All done."