File pre_checkin.sh of Package python3

#!/bin/bash
# This script is called automatically during autobuild checkin.
#
#
#
# ...or is it? 
# it really doesn't seem so, you know. go run it manually.

master=python3-base.spec

# calculate version number from newest tar name
VERSION=`ls *.tar.bz2 | grep '^Python-' | tail -n 1 | sed -r 's/^Python-([0-9]+\.[0-9]+.[0-9a-z]+)\.tar.*$/\1/'`
if echo $VERSION | grep -q Python; then
    echo "Version is $VERSION and that's not right, fix the script."
    exit 1
fi
# VERSION = 3.3.0

Version=${VERSION/[a-z]*/}      # 3.3.0
tar_suffix=${VERSION#$Version}  # b3
a_version=(${Version//\./ })    # 3 3 0

python_version=${VERSION:0:3}                   # 3.3
python_version_abitag=${python_version//./}     # 33
python_version_soname=${python_version//./_}    # 3_3

if [ -n "$tar_suffix" ]; then
    # we want to generate:
    # 3.2.3 -> 3.2.2.99
    # 3.3.0 -> 3.2.99
    (( last_elem = ${#a_version[@]} - 1 ))
    if [ ${a_version[$last_elem]} -eq 0 ]; then
        unset a_version[$last_elem]
        (( last_elem-- ))
    fi
    # this will fail when python 4.0 comes out. mwahaha
    (( a_version[$last_elem]-- ))
    Version=${a_version[*]}
    Version=${Version// /.}.99$tar_suffix  # 3.2.99b1

    tarversion=$VERSION                    # 3.3.0b1
else
    tarversion="%{version}"
fi

sed -i -r 's/(^Version:[ \t]+).*/\1'"$Version"'/' python3{-base,}.spec
sed -i -r 's/(^%define[ \t]+tarversion[ \t]+).*/\1'$tarversion'/' python3*.spec

#sed -i -r 's/(^Version:[ \t]+).*/\1'"$python_version"'/' python3-doc.spec
sed -i -r 's/(^%define[ \t]+pyver[ \t]+).*/\1'$Version'/' python3-doc.spec

for varname in python_version{,_abitag,_soname}; do
    eval varvalue=\$$varname
    sed -i -r 's/(^%define[ \t]+'$varname'[ \t]+).*/\1'$varvalue'/' $master
done


# copy definition sections


sections="COMMON-PATCH COMMON-DEF COMMON-PREP"

for slave in python3.spec python3-doc.spec; do
{
    prev=1
    for section in $sections; do
        begin="/$section-BEGIN/"
        end="/$section-END/"
        sed -n -e "${prev},${begin}p" $slave
        sed -n -e "${begin},${end}p" $master | head -n -1 | tail -n +2
        prev=$end
    done
    sed -n -e "${prev},\$p" $slave
} > $slave.tmp && mv $slave.tmp $slave
done

osc service localrun format_spec_file


# create import_failed.map from package definitions

MAPFILE=import_failed.map
function new_map_line () {
    if [ -z "$1" -o -z "$2" ]; then
        return
    fi
    if [ "$1" == "python3-base" ]; then
        return
    fi
    echo "$1:$2" >> $MAPFILE.tmp
}

for spec in *.spec; do
    basename=${spec%.spec}
    package=
    modules=
    while read line; do
        case $line in
            "%files -n "*)
                new_map_line $package "$modules"
                package=${line#"%files -n "}
                modules=
                ;;
            "%files "*)
                new_map_line $package "$modules"
                package=$basename-${line#"%files "}
                modules=
                ;;
            "%files")
                new_map_line $package "$modules"
                package=$basename
                modules=
                ;;
            "%{sitedir}/"*)
                word=${line#"%{sitedir}/"}
                if ! echo $word | grep -q /; then
                    modules="$modules $word"
                fi
                ;;
            "%{dynlib "*"}")
                word=${line#"%{dynlib "}
                word=${word%"}"}
                modules="$modules $word"
                ;;
        esac
    done < $spec
    new_map_line $package "$modules"
done

mv $MAPFILE.tmp $MAPFILE
openSUSE Build Service is sponsored by