r417 - scripts/trunk

Eddy Petrisor eddyp-guest at costa.debian.org
Mon Apr 3 04:54:56 UTC 2006


Author: eddyp-guest
Date: 2006-04-03 04:54:55 +0000 (Mon, 03 Apr 2006)
New Revision: 417

Modified:
   scripts/trunk/preprel
Log:
bug: made code and help consistent with each other
feat: added a small function that can change automatically the suite
feat: skeleton function for the actual prepare
feat: function that extracts data from the changelog
feat: other helper functions


Modified: scripts/trunk/preprel
===================================================================
--- scripts/trunk/preprel	2006-04-02 02:05:27 UTC (rev 416)
+++ scripts/trunk/preprel	2006-04-03 04:54:55 UTC (rev 417)
@@ -54,11 +54,11 @@
 
  Invocation:
 
-  $0 --release [[-c|--nocommit]|[-t|--notag]] [-s|--suite SUITE] PACK
+  $(basename $0) --release [[-c|--nocommit]|[-t|--notag]] [-s|--suite SUITE] PACK
       or
-  $0 --rebuild DEBVERSION PACK
+  $(basename $0) --rebuild DEBVERSION PACK
 
- --forrelease
+ --release
      Searches through the file packs.prep for the
      SVN link to the package in question, identifies the latest
      Debian package version (by reading debian/changelog) that
@@ -66,7 +66,7 @@
      is absent, it will change the suite and commit into SVN, tag
      the newly committed version, increment the Debian version,
      change the suite to UNRELEASED and then commit yet again.
- -n | --nocommit
+ -c | --nocommit
      If this parameter is given, no automatic SVN commiting will
      be done. This will not allow the relased version to be tagged.
  -t | --notag
@@ -78,33 +78,45 @@
      The default suite name is 'unstable'. The suite name can be
      overridden with this option.
 
+ PACK
+     The name of package that should be worked upon. Only one
+     package name is allowed.
+
  Note: in the current directory there should be a file called
-    packs.prep which should contain the package options needed by
-    the prepare script.
+    packs.prep which should contain some the package options 
+    needed by the prepare script.
 EOH
 }
 
-syntax_error()
+syntax_error ()
 {
-    echo -e 2>&1 "$(basename $0): $*"
+    echo -e 2>&1 "S:$(basename $0): $*"
     help
     exit 1
+}	
+
+error ()
+{
+    echo -e 2>&1 "E:$(basename $0): $*"
+	exit 2
 }
 
-warning()
+warning ()
 {
-    echo -e 2>&1 "$(basename $0): $*"
+    echo -e 2>&1 "W:$(basename $0): $*"
 }
 
 init ()
 {
     # Assume a few default variables
-    [ -z $SUITE ] && SUITE=unstable
-    [ -z $COMMIT ] && COMMIT=yes
-    [ -z $TAG ] && TAG=yes
-    [ -z $PACK ] && PACK="NOPACK"
+    [ -z "$SUITE" ] && SUITE=unstable
+    [ -z "$COMMIT" ] && COMMIT=yes
+    [ -z "$TAG" ] && TAG=yes
+    [ -z "$PACK" ] && PACK="NOPACK"
+    [ -z "$PACKOPT" ] && PACKOPTFILE=pack.prep
+    RELEASE=yes
 
-    while [ $# -gt 0 ]
+    while [ $# -gt 1 ]
     do
         case $1 in
         --suite=*)
@@ -113,7 +125,7 @@
             ;;
         --suite|-s)
             if [ $# -lt 2 ]; then syntax_error "$1 needs an argument"; fi
-            METHOD=$2
+            SUITE=$2
             shift
             shift
             ;;
@@ -127,21 +139,191 @@
             [ "$TAG" = "yes" ] && warning "$1 will not allow tagging"
             shift
             ;;
+        --rebuild)
+            COMMIT=no
+            TAG=no
+            DEBVERSION=$2
+            RELEASE=no
+            shift
+            shift
+            ;;
+        --rebuild=*)
+            DEBVERSION=${1#--rebuild=}
+            shift
+            ;;
         -*)
-            syntax_error "Unknown option \`$1'"
+            syntax_error "Unknown option \'$1'"
             ;;
         *)
-            [ $# -ne 1 ] && syntax_error "Only one package name is allowed"
+            [ $# -ne 1 ] && syntax_error "The package name should be on the last position."
             ;;
         esac
     done
+
+    #the last parameter should be the package name
+    PACK="$1"
+    # TODO: test the extracted PACK name is valid 
+    #(contains only valid characters)
+    # check "$PACK" || error "$PACK is not a valid package name"
+
+
+    get_URIs "$PACK"
 }
 
+# extracts from the packages' configuration file the URI for
+# the Debian specific package modifications and the URL from
+# where to fetch the 
+get_URIs ()
+{
+    # does the configuration file exists?
+    [ ! -f "$PACKOPTFILE" ] &&
+    error "Package configuration file $PACKOPTFILE was not found"
 
-warning "$0 is not yet complete. Please be patient."
-warning "Help follows...\n"
+    PACKCFG=`grep -e "^$1" "$PACKOPTFILE" | tr '\t' ' ' |  tr -s ' '`
+    SVNURI=`echo "$PACKCFG" | cut -f2 -d ' '`
+    # TODO: validate svn path
+    # [ "$COMMIT" = "yes" ] && check "$SVNURI" || error "Unknown SVN URI"
+	ORIGURL=`echo "$PACKCFG" | cut -f3 -d ' '`
+    # TODO: validate orig path
+    # check "$SVNURL" || error "Unknown orig URL"
+}
 
-help
-exit 13
+# Extracts the debian version number from the debian changelog.
+# It assumes the DPATH variable is set to point to the root
+# directory of the package (local copy); also the PACK variable
+# is assumed to be set to the correct value.
+extract_pack_data ()
+{
+    CHFILE="${DPATH}/debian/changelog"
+    validate_CHFILE
 
+    # extract version, and currently set suite, but not before checking
+    # that the package is the expected one
 
+    FIRSTLINE=`head -n1 $CHFILE`
+
+    DCHPACK=`echo "$FIRSTLINE" | cut -f1 -d' '`
+    [ ! "$DCHPACK" = "$PACK" ] && 
+    error "Expected package was $PACK, but found $DCHPACK"
+
+    PACKVERSION=`echo "$FIRSTLINE" | cut -f2 -d'(' | cut -f1 -d')'`
+    CURRENTSUITE=`echo "$FIRSTLINE" | cut -f1 -d';' | cut -f3 -d' '`
+}
+
+display_internal_vars ()
+{
+    echo "Package data:"
+    echo "Pack: $PACK"
+    echo "Suite: $SUITE"
+
+    echo "Current suite: $CURRENTSUITE"
+    echo "Package most recent version: $PACKVERSION"
+    echo "Handled version: $DEBVERSION"
+    echo "Subversion URI: $SVNURI"
+    echo "Original archive URL: $ORIGURL"
+
+    echo -e "\nConfiguration data:"
+    echo "Automatic commit: $COMMIT"
+    echo "Automatic tagging: $TAG"
+    echo "Package options file: $PACKOPTFILE"
+    echo
+}
+
+debug ()
+{
+	display_internal_vars 
+}
+
+validate_suite ()
+{
+    # TODO: add all possible suite names here
+    ALLSUITENAMES='stable testing unstable'
+
+    for S in $ALLSUITENAMES
+    do
+        [ "$1" = "$S" ] && return 0
+    done
+    return 1
+}
+
+validate_CHFILE ()
+{
+    [ ! -f "$CHFILE" ] &&
+    error "Debian changelog file not found at ${CHFILE}"
+}
+
+# replaces the suite name in the debian changelog with a given one
+# $1 - new suite name
+# later: $2 - suite name to be replaced with validation
+replace_suite ()
+{
+    validate_CHFILE
+    TEMP=`mktemp changelog.XXXXXX`
+    cat "$CHFILE" | sed "s/^\($PACK ($PACKVERSION) \).*;/\1$1;/" >$TEMP
+    cat "$TEMP" > "$CHFILE" && rm -f $TEMP
+}
+
+
+# needs: DEBVERSION, PACKVERSION, UPPACK, MIRROR, SVNURI, UPVERSION
+prepare ()
+{
+	# get the upstream data
+    get_upstream_data
+    # the debian data should have been extracted by now through init
+    # if this is a release, then the DEBVERSION was not set, yet
+    [ "$RELEASE" = "yes" ] && DEBVERSION="$PACKVERSION"
+
+    # do not set a builddir if it was set in the environment
+    [ -z "$BUILDDIR" ] && BUILDDIR=`pwd`
+    
+    mkdir -p $BUILDDIR/upstream
+    mkdir -p $BUILDDIR/build
+
+    cd $BUILDDIR/upstream
+    [ ! -f  "$UPPACK" ] && wget "$MIRROR/$UPPACK"
+
+
+    cd $BUILDDIR/build
+
+    # TODO: compute .orig.tag.gz name into ORIGTARBALL
+
+    cp ../upstream/$UPPACK $ORIGTARBALL
+    tar xfz $ORIGTARBALL
+    cd $PACK-$UPVERSION
+    rm -rf debian
+    svn export $SVNURI/tags/$DEBRELEASE/debian
+
+
+    # question: how will the tagging be done? before prepare?
+    # !! DPATH will have to be set before tagging !!
+
+    # set DPATH according yo new info
+    export DPATH="$BUILDDIR/build/$PACK-$UPVERSION"
+}
+################################################################################
+# program begins
+################################################################################
+warning "$(basename $0) is not yet complete. Please be patient."
+#warning "Help follows...\n"
+#help
+
+
+# get the data from the command line
+init "$*"
+
+# TODO: get the debian diff for the package from svn and
+
+
+# TODO: get the orig.tar.gz filename from somewhere
+
+
+
+# let's find out more things about the package from the changelog
+extract_pack_data
+
+
+debug # so, what is the current intrnal status?
+
+#exit 13
+
+




More information about the Pkg-games-devel mailing list