From: cajus Date: Mon, 4 Oct 2010 08:53:05 +0000 (+0000) Subject: Moved to new script X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f6d6d250ca525432e2e63ceb2e162a1c65f1066b;p=gosa.git Moved to new script git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6@19907 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/contrib/build-gosa b/gosa-core/contrib/build-gosa new file mode 100755 index 000000000..a020489d0 --- /dev/null +++ b/gosa-core/contrib/build-gosa @@ -0,0 +1,205 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- +import os +import re +import sys +import shutil +import tarfile +import subprocess +import logging +from optparse import OptionParser +from os.path import join +from tempfile import mkdtemp + +# Version setter +VERSION = "1.0" +methods = {} + + +# Check if pysvn is installed +try: + import pysvn + + def load_svn(base_url, release, tmp_dir): + source = base_url + "/" + release + svn = pysvn.Client() + + for part in ["gosa-core", "gosa-plugins"]: + print("Retrieving %s from SVN..." % part) + rev = svn.export(source + "/" + part, join(tmp_dir, part)) + + return "svn" + str(rev.number) + + methods["svn"] = load_svn +except: + pass + + +def tar_extract(name, target): + tar = tarfile.open(name, "r:gz") + tar.extractall(target) + tar.close() + +def tar_create(name, source): + tar = tarfile.open(name, "w:gz") + tar.add(source) + tar.close() + +def build(release, base_url, target="/tmp", method="svn", key_id=None, cleanup=True): + + # Absolutize target + target = os.path.abspath(target) + + # Create target and temporary directory + try: + tmp_dir = mkdtemp() + target_dir = join(target, "gosa") + os.makedirs(target_dir) + + # Get data + if method in methods: + rev = methods[method](base_url, release, tmp_dir) + else: + print("Error: method '%s' is notavailable" % method) + + # Prepare gosa-core for archiving + core_dir = join(tmp_dir, "gosa", "gosa-core") + os.makedirs(join(tmp_dir, "gosa")) + shutil.move(join(tmp_dir, "gosa-core"), join(tmp_dir, "gosa")) + shutil.move(join(core_dir, "debian"), target_dir) + + # Remove all but .php files provided by GOsa + smarty_dir = join(core_dir, "include", "smarty") + for rfile in [f for f in os.listdir(join(smarty_dir, "plugins")) + if not f in ["block.render.php", "block.t.php", "function.msgPool.php", + "function.factory.php"]]: + + os.remove(join(smarty_dir, "plugins", rfile)) + + for rfile in [join(smarty_dir, f) for f in os.listdir(smarty_dir)]: + if os.path.basename(rfile) != "plugins": + if os.path.isdir(rfile): + shutil.rmtree(rfile) + else: + os.remove(rfile) + + # Get target version number + version = None + with open(join(core_dir, "Changelog")) as f: + for line in f.readlines(): + if line.startswith("* gosa"): + version = line.split(" ")[2].strip() + break + + # If we're in trunk or branches, add revision to version + if re.match(r"^(trunk|branches/)", release): + version = "%s+%s" % (version, rev) + os.chdir(target_dir) + subprocess.call(["dch", "--newversion=" + version + "-1", + "--no-force-save-on-release", "Development snapshot"]) + + # Build gosa-core tar file + os.chdir(tmp_dir) + tar_create(join(target, "gosa_%s.orig.tar.gz" % version), "gosa") + + # Clean up and build plugin archives + tars = [] + os.chdir(join(tmp_dir, "gosa-plugins")) + for f in os.listdir(join(tmp_dir, "gosa-plugins")): + pth = join(target, "gosa_%s.orig-%s.tar.gz" % (version, f)) + if os.path.exists(join(tmp_dir, "gosa-plugins", f, "plugin.dsc")): + os.remove(join(tmp_dir, "gosa-plugins", f, "plugin.dsc")) + tar_create(pth, f) + tars.append(pth) + + # Stage build directory + tar_extract(join(target, "gosa_%s.orig.tar.gz" % version), target) + for tar_file in tars: + tar_extract(tar_file, target_dir) + + # Build packages + print("Building packages to %s" % target) + os.chdir(target_dir) + if key_id: + status = subprocess.call(["dpkg-buildpackage", "-k", key_id, "-rfakeroot"]) + else: + status = subprocess.call(["dpkg-buildpackage", "-uc", "-us", "-rfakeroot"]) + + # Bail out? + if status: + raise Exception("Build failed: exit code %s" % status) + + except Exception as detail: + print("Error:", str(detail)) + + # Cleanup + finally: + if cleanup: + if os.path.exists(tmp_dir): + shutil.rmtree(tmp_dir) + if os.path.exists(target_dir): + shutil.rmtree(target_dir) + +def main(): + # Sanity check + for cli, pkg in [("/usr/bin/dpkg-buildpackage", "dpkg-dev"), + ("/usr/bin/fakeroot", "fakeroot"), + ("/usr/bin/dch", "devscripts"), + ("/usr/bin/dh", "debhelper")]: + + if not os.path.exists(cli): + print("Error: %s is missing, please install %s" % (cli, pkg)) + exit(1) + + # Methods available? + if not methods: + print("Error: no retrieval methods available, please install python-svn") + exit(1) + + # Parse commandline options + op = OptionParser(usage="%prog - GOsa packaging aid", + version="%prog " + VERSION) + op.add_option("-s", "--source", dest="source", + default="https://oss.gonicus.de/repositories/gosa", + help="retrieval base path [%default]", metavar="URL") + op.add_option("-t", "--target", dest="target", + default=".", + help="target directory [%default]", metavar="PATH") + op.add_option("-m", "--method", dest="method", + default="svn", + help="retrieval method [%default]", metavar="METHOD") + op.add_option("-n", "--no-cleanup", action="store_false", + dest="cleanup", default=True, + help="don't clean up temporary files") + op.add_option("-k", "--key-id", dest="key_id", + default=None, + help="GPG key ID used for signing if applicable", metavar="KEY_ID") + + (options, args) = op.parse_args() + if len(args) != 1: + op.print_help() + exit(1) + + # Allow version shortcut, but prepend tags/ + release = args[0] + if re.match(r"^[0-9]", release): + release = "tags/" + release + + # Validate release + if not re.match(r"^(tags/.|branches/.|trunk$)", release): + print("Error: release must be in the format tags/x (or just x), branches/x or trunk") + exit(1) + + # Start build + build(release, options.source, options.target, + options.method, options.key_id, options.cleanup) + + +""" Main GOsa packaging aid """ +if __name__ == '__main__': + if not sys.stdout.encoding: + sys.stdout = codecs.getwriter('utf8')(sys.stdout) + if not sys.stderr.encoding: + sys.stderr = codecs.getwriter('utf8')(sys.stderr) + + main() diff --git a/gosa-core/contrib/make-gosa-package b/gosa-core/contrib/make-gosa-package deleted file mode 100755 index 297eb5920..000000000 --- a/gosa-core/contrib/make-gosa-package +++ /dev/null @@ -1,422 +0,0 @@ -#!/bin/bash -# This code is part of GOsa (http://www.gosa-project.org) -# Copyright (C) 2008 GONICUS GmbH -# -# ID: $$Id$$ -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -# Define defaults -RELEASE_REASON="GOsa svn snapshot" -BRANCH="trunk" -SECTION="web" -SI_SECTION="utils" -TARGET_RELEASE="etch" -MAKE_PLUGINS="" -MAKE_GOTO="" -GOTO="" -PBUILDER="" -NOT_RELEASED="heimdal dak dfs glpi apache2" -GOTO_NOT_RELEASED="apache-directory-studio goto-cd libresourcepool-net-ldap-perl-1.002 libresourcepool-perl-1.0104 openproj ptc syslinux konch ldm openssh-4.3p2" -DEBIAN_PKG="remove" -NO_SVN="use" -EXTRACT=`pwd` - -usage() { - cat <<-EOF - GOsa Debian package build tool. Build snapshots from selected SVN locations or local directories. - Usage: ${0##*/} [options] - - Options: - -b|--branch Branch to export [$BRANCH] - -p|--plugins Comma seperate list of plugins to build. Leave empty to build all. - -e|--experimental Build not released plugins (for testers and developers only) - -r|--release Debian release to build for [$TARGET_RELEASE] - -c|--changelog Debian changelog entry [$RELEASE_REASON] - -s|--section Debian section to place GOsa in [$SECTION] - -i|--si-section Debian section to place GOsa-SI in [$SI_SECTION] - -d|--debian-pkg Don't clear up debian packages for plugins (for developers only) - -n|--no-svn Don't extract gosa from svn (when internet connectivity is not present) - -x|--extract-dir Directory where the checkout is for no-svn - -g|--build-goto Build the goto2 packages - -l|--use-pbuilder Use pbuilder to build the packages - -h|--help this help - - EOF - exit 1 -} - -for cmd in dh-make-gosa debchange dpkg-buildpackage dpkg-source svn; do - if ! which $cmd >/dev/null; then - echo "Error: cannot find '$cmd' command in path!"; - exit 1 - fi -done - -# Import command line parameters -PARMS=`getopt -o e::d::b:r:s:c:i:p:n:x:g::l::,h --long branch:,changelog:,plugins:,section:,si-section:,release:,help -n "${0##*/}" -- "$@"` -eval set -- "$PARMS" - -while true; do - case "$1" in - -b|--branch) - BRANCH=$2; shift 2 ;; - -r|--release) - TARGET_RELEASE=$2; shift 2 ;; - -c|--changelog) - RELEASE_REASON=$2; shift 2 ;; - -p|--plugins) - MAKE_PLUGINS=$(echo $2 | tr ',' ' '); shift 2 ;; - -e|--experimental) - NOT_RELEASED=""; shift 2;; - -s|--section) - SECTION=$2; shift 2 ;; - -i|--si-section) - SI_SECTION=$2; shift 2 ;; - -d|--debian-pkg) - DEBIAN_PKG=""; shift 2 ;; - -n|--no-svn) - NO_SVN=""; shift 2;; - -x|--extract-dir) - EXTRACT=$2; shift 2;; - -g|--build-goto) - GOTO="use"; shift 2;; - -l|--use-pbuilder) - PBUILDER="use"; shift 2;; - -h|--help) - usage ;; - --) - shift; break ;; - *) - echo "getopt error" ;; - esac -done - -if [ "$NO_SVN" = "use" ] -then - echo "Loading svn information for gosa '${BRANCH}'..." - svn co -N https://oss.gonicus.de/repositories/gosa/${BRANCH} gosa-info/ > /dev/null - BRANCH_REV=$(LANG=C svn info gosa-info | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p') - rm -rf gosa-info - - if [ "$GOTO" = "use" ] - then - echo "Loading svn information for goto '${BRANCH}'..." - svn co -N https://oss.gonicus.de/repositories/goto/${BRANCH} goto-info/ > /dev/null - GOTO_BRANCH_REV=$(LANG=C svn info goto-info | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p') - rm -rf goto-info - fi -else - echo "Loading svn information for gosa '${BRANCH}' from local checkout ..." - BRANCH_REV=$(LANG=C svn info $EXTRACT/gosa-core | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p') - - if [ "$GOTO" = "use" ] - then - echo "Loading svn information for goto '${BRANCH}' from local checkout ..." - GOTO_BRANCH_REV=$(LANG=C svn info $EXTRACT/goto | sed -n -e 's/^Last Changed Rev: \([0-9]*\).*$/\1/p') - fi -fi - -if [ "$NO_SVN" = "use" ] -then - # Load current revision from logs - VERSION=$(svn cat -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-core/debian/changelog \ - | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p') - if [ "$BRANCH" == "trunk" ]; then - GOSA_VER="${VERSION}+svn${BRANCH_REV}" - - if [ "$GOTO" = "use" ] - then - GOTO_VER="+svn${GOTO_BRANCH_REV}" - fi - else - GOSA_VER="${VERSION}" - - if [ "$GOTO" = "use" ] - then - GOTO_VER="" - fi - - fi - -else - # Load current revision from logs - VERSION=$(cat $EXTRACT/gosa-core/debian/changelog | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p') - - if [ "$BRANCH" == "trunk" ]; then - GOSA_VER="${VERSION}+svn${BRANCH_REV}" - else - GOSA_VER="${VERSION}" - fi - echo $GOSA_VER -fi - -GOSA_DIR="gosa-${GOSA_VER}" - -ORIG_FILE="gosa_${GOSA_VER}.orig.tar.gz" - -if [ "$NO_SVN" = "use" ] -then - # Export from svn... - BNAME=$(basename $BRANCH) - [ -d "gosa-${BNAME}" ] && rm -rf gosa-$BNAME - echo "Exporting current GOsa (rev: ${BRANCH_REV}) from '${BRANCH}'..." - svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-core gosa-${BNAME} > /dev/null - svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-si gosa-si-${BNAME} > /dev/null - svn export -r "${BRANCH_REV}" https://oss.gonicus.de/repositories/gosa/${BRANCH}/gosa-plugins gosa-plugins-${BNAME} > /dev/null - - if [ "$GOTO" = "use" ] - then - echo "Exporting current GOto (rev: ${GOTO_BRANCH_REV}) from '${BRANCH}'..." - svn export -r "${GOTO_BRANCH_REV}" https://oss.gonicus.de/repositories/goto/${BRANCH}/ goto-${BNAME} > /dev/null - fi -else - # Export from local checkout... - echo "Exporting current GOsa (rev: ${BRANCH_REV}) from localcheckout '${BRANCH}'..." - BNAME=$(basename $BRANCH) - cp -r gosa-core gosa-${GOSA_VER} - mv gosa-si gosa-si-${GOSA_VER} - mv gosa-plugins gosa-plugins-${BNAME} - - if [ "$GOTO" = "use" ] - then - echo "Exporting current GOto (rev: ${GOTO_BRANCH_REV}) from localcheckout '${BRANCH}'..." - BNAME=$(basename $BRANCH) - mv goto goto-${BNAME} - fi -fi - -if [ "$NO_SVN" = "use" ] -then - VERSION=$(cat "gosa-${BNAME}/debian/changelog" | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p') -fi - -GOSA_DIR="gosa-${GOSA_VER}" -GOSA_SI_DIR="gosa-si-${GOSA_VER}" -GOTO_DIR="goto-${BNAME}" - -if [ "$NO_SVN" = "use" ] -then - if [ "$BNAME" != "$GOSA_VER" ] - then - rm -rf "gosa-${GOSA_VER}" - fi -fi - -if [ "$NO_SVN" = "use" ] -then - if [ "$BNAME" != "$GOSA_VER" ] - then - mv "gosa-${BNAME}" "gosa-${GOSA_VER}" - mv "gosa-si-${BNAME}" "gosa-si-${GOSA_VER}" - fi -fi - -echo "cleaning svn entries from sources" -find ${GOSA_DIR} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1 -find ${GOSA_SI_DIR} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1 -find gosa-plugins-${BNAME} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1 - -if [ "$GOTO" = "use" ] -then - find goto-${BNAME} -type d -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1 -fi - -echo "Creating original sources 'gosa-${GOSA_VER}'..." -tar -c --exclude "${GOSA_DIR}"/debian -f "gosa_${GOSA_VER}.orig.tar" "${GOSA_DIR}" -tar -c --exclude "${GOSA_SI_DIR}"/debian -f "gosa-si_${GOSA_VER}.orig.tar" "${GOSA_SI_DIR}" - -echo "Compressing sources..." -gzip -f -9 "gosa_${GOSA_VER}.orig.tar" -gzip -f -9 "gosa-si_${GOSA_VER}.orig.tar" - -export OVERRIDE_VERSION="$GOSA_VER" -if [ -z "$MAKE_PLUGINS" ]; then - MAKE_PLUGINS=$(ls -1 gosa-plugins-${BNAME}/*/plugin.dsc | sed 's/^.*\/\([^\/]*\)\/plugin.dsc$/\1/') - for i in $NOT_RELEASED; do - MAKE_PLUGINS=$(echo -n $MAKE_PLUGINS | sed "s/$i//") - done -fi - -if [ "TARGET_RELEASE" == "etch" ]; then - NOBREAKS="--no-break" -fi - -for plugin in $MAKE_PLUGINS; do - - GOSA_PLUG_DIR="gosa-plugin-$plugin-${GOSA_VER}" - - echo "gosa plugin dir" $GOSA_PLUG_DIR - - mv "gosa-plugins-${BNAME}/$plugin" . - - echo "Debianizing plugin $plugin" - yes | dh-make-gosa $NOBREAKS --section $SECTION $plugin - rm -rf "$plugin" - - echo "Packing original sources 'gosa-plugin-$plugin-${GOSA_VER}'..." - tar -c --exclude "gosa-plugin-${plugin}-${GOSA_VER}/debian" -f "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar" "${GOSA_PLUG_DIR}" - - echo "Compressing sources..." - gzip -f -9 "gosa-plugin-${plugin}_${GOSA_VER}.orig.tar" -done - -rm -rf gosa-plugins-${BNAME} - -if [ "$GOTO" = "use" ] -then - MAKE_GOTO=$(ls -1 goto-${BNAME}/) - - for i in $GOTO_NOT_RELEASED; do - MAKE_GOTO=$(echo -n $MAKE_GOTO | sed "s/$i//") - done - - for goto in $MAKE_GOTO; do - - mv "goto-${BNAME}/$goto" . - - echo "Packing original sources '$goto'..." - GOTO_VERSION=$(cat $goto/debian/changelog | head -n 1 | sed -n -e 's/.*(\([^-]*\).*/\1/p') - - if [ "$GOTO_VER" = "" ] - then - tar -c --exclude "$goto/debian" -f "${goto}_${GOTO_VERSION}.orig.tar" $goto - echo "Compressing sources..." - gzip -f -9 "${goto}_${GOTO_VERSION}.orig.tar" - else - tar -c --exclude "$goto/debian" -f "${goto}_${GOTO_VERSION}${GOTO_VER}.orig.tar" $goto - - echo "Compressing svn sources..." - gzip -f -9 "${goto}_${GOTO_VERSION}${GOTO_VER}.orig.tar" - - echo "Adapting version in $goto" - (cd "$goto"; echo | debchange -v "${GOTO_VERSION}${GOTO_VER}-1${TARGET_RELEASE}1" -D "$TARGET_RELEASE" "$RELEASE_REASON") - fi - - done - - rm -rf goto-${BNAME} -fi - -echo "Deploying patches..." -for patch in $(find patches -type f | grep -v .svn); do - - if echo $patch | grep -q gosa-plugin; then - plugin=$(echo $patch | sed 's/^.*gosa-plugin-\([^-]*\).*$/\1/g') - echo "* gosa-plugin-$plugin patch: $patch" - [ -d "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches" ] || mkdir -p "gosa-plugin-${plugin}-${GOSA_VER}/debian/patches" - cp "$patch" gosa-plugin-${plugin}-${GOSA_VER}/debian/patches - else - echo "* gosa-core patch: $patch" - [ -d "${GOSA_DIR}/debian/patches" ] && mkdir -p "${GOSA_DIR}/debian/patches" - cp "$patch" ${GOSA_DIR}/debian/patches - fi -done - -# Put section in GOsa_DIR -sed -i "s#^Section: web#Section: $SECTION#g" ${GOSA_DIR}/debian/control -sed -i "s#^Section: utils#Section: $SI_SECTION#g" ${GOSA_SI_DIR}/debian/control - -for plugin in $MAKE_PLUGINS; do - GOSA_PLUGIN_DIRS="$GOSA_PLUGIN_DIRS gosa-plugin-$plugin-${GOSA_VER}" -done - -if [ "$GOTO" = "use" ] -then - for goto in $MAKE_GOTO; do - GOTO_DIRS="$GOTO_DIRS $goto" - done -fi - -for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do - echo "Adapting version in $dir" - if [ "$TARGET_RELEASE" == "unstable" ]; then - (cd "$dir"; echo | debchange -v "${GOSA_VER}" "$RELEASE_REASON" >/dev/null 2>&1) - else - (cd "$dir"; echo | debchange -v "${GOSA_VER}-1${TARGET_RELEASE}1" -D "$TARGET_RELEASE" "$RELEASE_REASON" >/dev/null 2>&1) - fi - [ -d $dir/debian/patches ] || continue - echo "Creating patch list for $dir" - ls -1 $dir/debian/patches | grep -v 00list | sed 's%^.*/%%g' > $dir/debian/patches/00list -done - -# Update revision -sed -i "s/^\$svn_revision = .*$/\$svn_revision = '\$Revision: $BRANCH_REV \$';/g" $GOSA_DIR/include/functions.inc - -if [ "$1" = "-s" ] -then - echo "Creating debian sources..." - for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do - dpkg-source -b "$dir" - done - - if [ "$GOTO" = "use" ] - then - echo "Creating GOto sources..." - for dir in $GOTO_DIRS; do - dpkg-source -b "$dir" - done - fi -else - echo "Creating debian packages..." - - for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do - if [ "$PBUILDER" = "use" ] - then - echo "using pbuilder to build gosa gosa-si gosa-plugins" - (cd "$dir"; pdebuild --debbuildopts -sa; debsign) - else - (cd "$dir"; dpkg-buildpackage -k$DEBSIGN_KEYID -rfakeroot -sa) - fi - done - - if [ "$GOTO" = "use" ] - then - echo "Creating GOto debian packages..." - for dir in $GOTO_DIRS; do - if [ "$PBUILDER" = "use" ] - then - echo "using pbuilder to build goto debian packages" - (cd "$dir"; pdebuild --debbuildopts -sa; debsign -k$DEBSIGN_KEYID) - else - (cd "$dir"; dpkg-buildpackage -k$DEBSIGN_KEYID -rfakeroot -sa) - fi - done - fi -fi - -echo "Removing gosa snapshot..." -if [ -z "$DEBIAN_PKG" ] -then - if [ "$NO_SVN" = "use" ] - then - for dir in $GOSA_DIR; do - rm -rf "$dir" - done - fi -else - for dir in $GOSA_DIR $GOSA_SI_DIR $GOSA_PLUGIN_DIRS; do - rm -rf "$dir" - done - - if [ "$GOTO" = "use" ] - then - for dir in $GOTO_DIRs; do - rm -rf "$dir" - done - fi -fi - -