commit 8909e2a7352ef72940b3b7ce43189e735f98bb1c
Author: Jan Pokorný <jpokorny(a)redhat.com>
Date: Sat Feb 25 18:20:59 2012 +0100
bootstrap process: move few steps further
It will still get stuck at paste commands.
Signed-off-by: Jan Pokorný <jpokorny(a)redhat.com>
README.txt | 13 ++++--
dist-files/setup.cfg | 1 +
input-files/bootstrap-create.py | 33 ++++++++--------
input-files/bootstrap-recipe.py | 50 ++++++++++++++++--------
prepare-common.py | 6 +++
prepare-devel.py | 15 ++++---
setup | 18 ++++++---
bootstrap-virtualenv.py => sunzi-bootstrap.py | 52 +++++++++++++++++--------
8 files changed, 122 insertions(+), 66 deletions(-)
---
diff --git a/README.txt b/README.txt
index 0154130..51e5e92 100644
--- a/README.txt
+++ b/README.txt
@@ -39,13 +39,16 @@ to also initialize third-party bundles, necessary for successful
package build.
Another enabling step is to get an initial `setup.cfg` file (unless you want
-to provide all the parameters in command-line). To do so, either run::
+to provide all the parameters in command-line) as a copy of the default one::
- python setup.py prepare --gen defaultcfg
+ cp dist-files/setup.cfg .
-or, equivalently, grab a copy from `dist-files/setup.cfg` location.
-Most convenient way is to use `./setup` shell wrapper of `python setup.py`
-that will ensure `setup.cfg` exists, copying it if needed, for you.
+Probably more convenient is to use `./setup` shell wrapper at places you
+would use `python setup.py`. This will ensure you have pristine version
+of `setup.cfg` (from the path above) before actually performing requested
+`setup.py` command(s), which can prevent "oh, I had edited setup.cfg and
+forgot". To preserve a copy of `setup.cfg`, just use `python setup.py`
+as usual.
.. ``TODO``
.. Prerequisities for successful build/installation/deployment:
diff --git a/dist-files/setup.cfg b/dist-files/setup.cfg
index 18f89b6..d201377 100644
--- a/dist-files/setup.cfg
+++ b/dist-files/setup.cfg
@@ -30,6 +30,7 @@ pamdir = /etc/pam.d
sasl2dir = /etc/sasl2
[aliases]
+cfg = prepate --gen defaultcfg
stylesheet = prepare --gen stylesheet
specfile = prepare --gen specfile
tarball = prepare --gen-all sdist --formats=gztar
diff --git a/input-files/bootstrap-create.py b/input-files/bootstrap-create.py
old mode 100644
new mode 100755
index a21428b..b699ab2
--- a/input-files/bootstrap-create.py
+++ b/input-files/bootstrap-create.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
# Copyright 2012 Red Hat, Inc.
# Part of sunzi project
# Licensed under GPLv2 (a copy included /
http://gnu.org/licenses/gpl-2.0.txt)
@@ -6,25 +7,25 @@
Use ``python dist-files/bootstrap-create.py`` to update ``bootstrap-virtualenv.py``.
"""
from __future__ import print_function
-import sys
from os import path
import virtualenv
-import textwrap
-SCRIPT_NAME = '../bootstrap-virtualenv.py'
-EXTRA_TEXT_NAME = 'bootstrap-recipe.py'
+this_dir = path.dirname(path.abspath(__file__))
+parent_dir = path.dirname(this_dir)
+SCRIPT_NAME = path.join(parent_dir, 'sunzi-bootstrap.py')
+EXTRA_TEXT_NAME = path.join(this_dir, 'bootstrap-recipe.py')
-def main(argv):
- here = path.dirname(argv[0])
- script_name = path.normpath(path.join(here, SCRIPT_NAME))
- extra_text_name = path.normpath(path.join(here, EXTRA_TEXT_NAME))
-
- try:
- with open(extra_text_name) as f:
- extra_text = f.read()
- except EnvironmentError, exc:
- print('Unable to open/read %s' % extra_text_name)
- exit
+# NOTE: can be extended by custom options (hint: extend_parser)
+def main(script_name, extra_text_name=None):
+ if extra_text_name:
+ try:
+ with open(extra_text_name) as f:
+ extra_text = f.read()
+ except EnvironmentError:
+ print('Unable to open/read %s' % extra_text_name)
+ raise
+ else:
+ extra_text = ''
new_script = virtualenv.create_bootstrap_script(extra_text)
if path.exists(script_name):
@@ -41,4 +42,4 @@ def main(argv):
f.write(new_script)
if __name__ == '__main__':
- main(sys.argv)
+ main(SCRIPT_NAME, EXTRA_TEXT_NAME)
diff --git a/input-files/bootstrap-recipe.py b/input-files/bootstrap-recipe.py
index 9a142d6..eb736a6 100644
--- a/input-files/bootstrap-recipe.py
+++ b/input-files/bootstrap-recipe.py
@@ -6,36 +6,54 @@
Used by bootstrap-create.py that includes this into final bootstrap script.
"""
import subprocess
-from os.path import join
+from os import environ
+from os.path import join, curdir, abspath
-SUNZI_GIT = 'git://git.fedorahosted.org/sunzi.git'
+# TODO: switch for RO an RW git access (RO only now) + branch
+SUNZI_GIT_RO = 'git://git.fedorahosted.org/sunzi.git'
+SUNZI_GIT_RW = 'ssh://git.fedorahosted.org/git/sunzi.git'
+SUNZI_GIT_BRANCH = 'development'
+# subdir to be created within a new virtualenv environment
SUNZI_DIR = 'sunzi'
+def from_cwd(prog):
+ return join(curdir, prog)
+
def after_install(options, home_dir):
- sunzi_dir = join(home_dir, 'SUNZI_DIR')
- python = join(home_dir, 'bin', 'python')
- #paster = path.join(home_dir, 'bin', 'paster')
+ sunzi_dir = join(home_dir, SUNZI_DIR)
+ # path of virtualenv-infected programs
+ python = abspath(join(home_dir, 'bin', 'python'))
+ paster = abspath(join(home_dir, 'bin', 'paster'))
+
+ env = environ.copy()
+ env['PYTHON'] = python
cmds = [
- dict(cmd=['git','clone', SUNZI_GIT, sunzi_dir]),
- # just to ensure existing setup.cfg
- dict(cmd=[join(sunzi_dir, 'setup')]),
- dict(cwd=sunzi_dir,
- cmd=[join('third-party','init.sh'), 'all']),
+ # see also README.txt
+
dict(args=['git','clone','-b',SUNZI_GIT_BRANCH,SUNZI_GIT_RO,sunzi_dir],
+ keepgoing=True),
+ dict(cwd=join(sunzi_dir, 'third-party'),
+ args=[from_cwd('init.sh'),'all']),
+ # just to ensure existing setup.cfg (PYTHON from env)
dict(cwd=sunzi_dir,
- cmd=[python, 'setup.py', 'prepare', '--develop']),
- # TODO: see dev.sh at luci
+ args=[from_cwd('setup'),'prepare','--develop']),
+ # TODO: see also dev.sh at luci
#dict(cwd=sunzi_dir,
# cmd=['paster', 'make-config', 'sunzi',
'development.ini'],
#dict(cwd=sunzi_dir,
# cmd=['paster', 'setup-app', 'sunzi',
'development.ini'],
]
+ run_commands(cmds, env)
+def run_commands(cmds, env=None):
for cmd in cmds:
- print('Running `%s\'' % ' '.join(cmd['cmd']))
- ret = subprocess.call(**cmd)
+ args = cmd.pop('args')
+ keepgoing = cmd.pop('keepgoing', False)
+ print('Running `%s\' with CWD: `%s\''
+ % (' '.join(args), cmd.get('cwd', '(no change)')))
+ ret = subprocess.call(args, env=env, **cmd)
if ret > 0:
print('Nonzero exit code: %d' % ret)
elif ret < 0:
print('Killed by signal %d' % -ret)
- if ret != 0:
- return
+ if ret != 0 and not keepgoing:
+ break
diff --git a/prepare-common.py b/prepare-common.py
index 025a349..17e1890 100644
--- a/prepare-common.py
+++ b/prepare-common.py
@@ -14,6 +14,12 @@ from os.path import join, basename
# basic setup
# TODO
+gen_file('defaultcfg',
+ join('dist-files','setup.cfg'),
+ 'setup.cfg',
+ incl=False,
+)
+
nonoptions(
package = PACKAGE,
)
diff --git a/prepare-devel.py b/prepare-devel.py
index c3d0627..ec5c4e4 100644
--- a/prepare-devel.py
+++ b/prepare-devel.py
@@ -11,6 +11,15 @@ from os.path import join, exists, isfile, basename, splitext, normpath,
sep
from shutil import copy2
from fnmatch import fnmatch
+# this can be used instead of ./setup wrapper, e.g.: python setup.py cfg build
+# where "cfg" is a standard alias to "prepare --gen defaultcfg", but
only
+# once any setup.cfg already exists (initally use "cp dist-files/setup.cfg .")
+gen_file('defaultcfg',
+ join('dist-files','setup.cfg'),
+ 'setup.cfg',
+ incl=False,
+)
+
#
# JavaScript and stylesheets
#
@@ -171,9 +180,3 @@ gen_file('stylesheet',
)
# similarly for JavaScript files (but 1:1 mapping kept)
javascript_items.make_params(PACKAGE,PUBLIC,JAVASCRIPT_ROOT)
-
-gen_file('defaultcfg',
- join('dist-files','setucfg'),
- 'setup.cfg',
- subst=True, incl=False,
-)
diff --git a/setup b/setup
index ec08964..bdd391e 100755
--- a/setup
+++ b/setup
@@ -9,17 +9,23 @@
if [ -z "$PYTHON" ]; then
PYTHON=python
fi
-
+ORIG=dist-files/setup.cfg
+USED=setup.cfg
ARCHIVE=$(ls -1v *.tar.gz 2>/dev/null | head -n1)
+
if [ -n "$ARCHIVE" ] ; then
# refresh files from the newest archive if any present
+ echo "extracting necessary files from archive ${ARCHIVE}..."
EXTRACT='*/setup* */prepare-{common,dist}.py */metadata.py'
tar xf "$ARCHIVE" --strip-components=1 --wildcards "$EXTRACT"
+elif diff "$USED" "$ORIG" >/dev/null 2>&1; then
+ # no change detected
+ echo "using existing ${USED}..."
else
- # or at least, start with pristine setup.cfg if missing
- # hint: you can always run python setup.py directly
- cp dist-files/setup.cfg . 2>/dev/null
- # alternatively: $PYTHON setup.py prepare --gen defaultcfg
+ # either change detected or missing $USED
+ # hint: you can always run python setup.py directly to avoid this
+ echo "using pristine ${USED} from ${ORIG} (making backup if needed)..."
+ mv -f -- "$USED" "${ORIG}.$(date +%y%m%d-%H%M%S)" 2>/dev/null
+ cp -f -- "$ORIG" "$USED"
fi
-
[ $# -eq 0 ] || "$PYTHON" setup.py "$@"
diff --git a/bootstrap-virtualenv.py b/sunzi-bootstrap.py
similarity index 98%
rename from bootstrap-virtualenv.py
rename to sunzi-bootstrap.py
index ead3082..53dbfb1 100644
--- a/bootstrap-virtualenv.py
+++ b/sunzi-bootstrap.py
@@ -1544,39 +1544,57 @@ def create_bootstrap_script(extra_text,
python_version=''):
Used by bootstrap-create.py that includes this into final bootstrap script.
"""
import subprocess
-from os.path import join
-
-SUNZI_GIT = 'git://git.fedorahosted.org/sunzi.git'
+from os import environ
+from os.path import join, curdir, abspath
+
+# TODO: switch for RO an RW git access (RO only now) + branch
+SUNZI_GIT_RO = 'git://git.fedorahosted.org/sunzi.git'
+SUNZI_GIT_RW = 'ssh://git.fedorahosted.org/git/sunzi.git'
+SUNZI_GIT_BRANCH = 'development'
+# subdir to be created within a new virtualenv environment
SUNZI_DIR = 'sunzi'
+def from_cwd(prog):
+ return join(curdir, prog)
+
def after_install(options, home_dir):
- sunzi_dir = join(home_dir, 'SUNZI_DIR')
- python = join(home_dir, 'bin', 'python')
- #paster = path.join(home_dir, 'bin', 'paster')
+ sunzi_dir = join(home_dir, SUNZI_DIR)
+ # path of virtualenv-infected programs
+ python = abspath(join(home_dir, 'bin', 'python'))
+ paster = abspath(join(home_dir, 'bin', 'paster'))
+
+ env = environ.copy()
+ env['PYTHON'] = python
cmds = [
- dict(cmd=['git','clone', SUNZI_GIT, sunzi_dir]),
- # just to ensure existing setup.cfg
- dict(cmd=[join(sunzi_dir, 'setup')]),
- dict(cwd=sunzi_dir,
- cmd=[join('third-party','init.sh'), 'all']),
+ # see also README.txt
+
dict(args=['git','clone','-b',SUNZI_GIT_BRANCH,SUNZI_GIT_RO,sunzi_dir],
+ keepgoing=True),
+ dict(cwd=join(sunzi_dir, 'third-party'),
+ args=[from_cwd('init.sh'),'all']),
+ # just to ensure existing setup.cfg (PYTHON from env)
dict(cwd=sunzi_dir,
- cmd=[python, 'setup.py', 'prepare', '--develop']),
- # TODO: see dev.sh at luci
+ args=[from_cwd('setup'),'prepare','--develop']),
+ # TODO: see also dev.sh at luci
#dict(cwd=sunzi_dir,
# cmd=['paster', 'make-config', 'sunzi',
'development.ini'],
#dict(cwd=sunzi_dir,
# cmd=['paster', 'setup-app', 'sunzi',
'development.ini'],
]
+ run_commands(cmds, env)
+def run_commands(cmds, env=None):
for cmd in cmds:
- print('Running `%s\'' % ' '.join(cmd['cmd']))
- ret = subprocess.call(**cmd)
+ args = cmd.pop('args')
+ keepgoing = cmd.pop('keepgoing', False)
+ print('Running `%s\' with CWD: `%s\''
+ % (' '.join(args), cmd.get('cwd', '(no change)')))
+ ret = subprocess.call(args, env=env, **cmd)
if ret > 0:
print('Nonzero exit code: %d' % ret)
elif ret < 0:
print('Killed by signal %d' % -ret)
- if ret != 0:
- return
+ if ret != 0 and not keepgoing:
+ break
def convert(s):