contrib/opie: add useful management scripts
authorPaul Eggleton <bluelightning@bluelightning.org>
Wed, 15 Dec 2010 01:04:40 +0000 (01:04 +0000)
committerPaul Eggleton <bluelightning@bluelightning.org>
Wed, 15 Dec 2010 01:04:40 +0000 (01:04 +0000)
Add scripts to aid management of Opie recipes and source tarballs

Signed-off-by: Paul Eggleton <bluelightning@bluelightning.org>
contrib/opie/opie_checksum_rewrite.py [new file with mode: 0755]
contrib/opie/opie_checksum_rewrite.sh [new file with mode: 0755]
contrib/opie/opie_create_split.sh [new file with mode: 0755]
contrib/opie/opie_release.sh [new file with mode: 0755]

diff --git a/contrib/opie/opie_checksum_rewrite.py b/contrib/opie/opie_checksum_rewrite.py
new file mode 100755 (executable)
index 0000000..5e16ee9
--- /dev/null
@@ -0,0 +1,108 @@
+#!/usr/bin/env python
+# ex:ts=4:sw=4:sts=4:et
+
+# Opie recipe checksum rewriter
+#
+# A crude script for rewriting recipes to contain checksum information
+#
+# Some portions copied from oe-source-checker.py, copyright (C) 2007 OpenedHand
+
+import os
+import sys
+
+def rewrite(recpfilename, sourcedir):
+       insrc = False
+       srcfirst = False
+       sums = ''
+       appname = ''
+       output = ''
+       f = open(recpfilename, 'r')
+       for line in f:
+               if line.startswith('require '):
+                       pn = os.path.basename(recpfilename)
+                       pn = pn[0:pn.find("_")]
+                       incfilename = line[8:].strip().replace("${PN}", pn)
+                       f2 = open(os.path.join(os.path.dirname(recpfilename), incfilename))
+                       for line2 in f2:
+                               if line2.startswith('APPNAME '):
+                                       appname = line2[line2.find('"'):].strip('\n\r"')
+                       f2.close()
+                       output = output + line
+                       continue
+               
+               if line.startswith('SRC_URI['):
+                       continue
+
+               if line.startswith('APPNAME '):
+                       appname = line[line.find('"'):].strip('\n\r"')
+                       output = output + line
+                       continue
+
+               if not insrc and line.startswith('SRC_URI '):
+                       insrc = True
+                       srcfirst = True
+                       
+               if insrc:
+                       pos = line.find('-split_')
+                       pos2 = line.find('.tar.bz2')
+                       if pos > -1 and pos2 > -1:
+                               name = line[pos+1:pos2]
+                               name = name.replace('${APPNAME}', 'appname')
+                               output = output + line.replace('.tar.bz2', '.tar.bz2;name=%s' % name)
+                               filename = line.strip('\n\r\t "\\').replace('${APPNAME}', appname)
+                               if srcfirst:
+                                       filename = filename[filename.find('"')+1:]
+                               filename = filename.replace('http://sources.openembedded.org/', '')
+                               localpath = os.path.join(sourcedir, filename)
+                               if not os.path.isfile(localpath):
+                                       raise IOError("file %s not found" % localpath)
+                               
+                               md5pipe = os.popen('md5sum ' + localpath)
+                               md5data = (md5pipe.readline().split() or [ "" ])[0]
+                               md5pipe.close()
+
+                               shapipe = os.popen('sha256sum ' + localpath)
+                               shadata = (shapipe.readline().split() or [ "" ])[0]
+                               shapipe.close()
+                               
+                               sums = sums + 'SRC_URI[%s.md5sum] = "%s"\n' % (name, md5data)
+                               sums = sums + 'SRC_URI[%s.sha256sum] = "%s"\n' % (name, shadata)
+                               
+                       else:
+                               output = output + line
+
+                       if (srcfirst and line.count('"') > 1) or (not srcfirst and line.find('"') > -1):
+                               insrc = False
+                               if sums:
+                                       output = output + sums
+                       
+                       srcfirst = False
+               else:
+                       output = output + line
+
+       f.close()
+       
+       f = open(recpfilename, 'w')
+       f.write(output)
+       f.close()
+
+
+
+if len(sys.argv) < 3:
+    print """syntax: %s recipe dl_dir
+  recipe - recipe.bb file
+  dl_dir - location of local source files""" % sys.argv[0]
+    sys.exit(1)
+
+recipe = sys.argv[1]
+dl_dir = sys.argv[2]
+
+if not os.path.isfile(recipe):
+    print >> sys.stderr, "%s: recipe file %s not found" % recipe
+       sys.exit(1)
+
+if not os.path.isdir(dl_dir):
+    print >> sys.stderr, "%s: source dir %s not found" % dl_dir
+       sys.exit(1)
+
+rewrite(recipe, dl_dir)
diff --git a/contrib/opie/opie_checksum_rewrite.sh b/contrib/opie/opie_checksum_rewrite.sh
new file mode 100755 (executable)
index 0000000..efc3a10
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+if ! [ -d libqpe ] ; then
+    echo "Please execute at the recipes subdir of the OE source tree"
+    exit 1
+fi
+
+if [ x$2 == x ] ; then
+    echo "usage: $0 dl_dir version"
+    exit 1
+fi
+
+if ! [ -d $1 ] ; then
+    echo "Source dir $1 does not exist"
+    exit 1
+fi
+
+FILES="libqpe libqtaux libopie* libmailwrapper opie*"
+
+REWR=`readlink -m $0`
+REWR="python `dirname $REWR`/opie_checksum_rewrite.py"
+
+for i in $FILES ; do
+       for j in $i/*_$2.bb ; do
+               if [ -f $j ] ; then
+                       echo $j
+                       $REWR $j $1
+                       if [ $? -ne 0 ] ; then
+                               echo "Exiting due to error"
+                               exit 1
+                       fi
+               fi
+       done
+done
+
diff --git a/contrib/opie/opie_create_split.sh b/contrib/opie/opie_create_split.sh
new file mode 100755 (executable)
index 0000000..0b9f76e
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+if [ x$2 == x ] ; then
+    echo "usage: $0 sourcedir pathsfile [outdir]"
+    exit 1
+fi
+
+if ! [ -d $1 ] ; then
+    echo "Source dir $1 does not exist"
+    exit 1
+else
+    if ! [ -f $1/library/version.h ] ; then
+        echo "Source dir $1 doesn't contain an opie source tree"
+       exit 1
+    fi
+fi
+
+# FIXME this could be produced on the fly using some python code
+# (perhaps hack opie_checksum_rewrite.py)
+if ! [ -f $2 ] ; then
+    echo "Paths file $2 does not exist"
+    exit 1
+fi
+
+if [ x$3 != x ] ; then
+    OUT_DIR=$3
+    if ! [ -d $3 ] ; then
+        echo "Output dir $3 does not exist"
+        exit 1
+    fi
+else
+    OUT_DIR=`pwd`
+fi
+
+OLD_PWD=`pwd`
+
+PATHS_FILE=`readlink -m $2`
+
+cd $1
+OPIE_VERSION=`grep QPE_VERSION library/version.h | awk '{ print $3 }' | sed 's/"//g'`
+
+for i in `cat $PATHS_FILE`; do
+       echo $i
+       tar -c -C `dirname $i` -j -f $OUT_DIR/opie-$OPIE_VERSION-split_`echo $i | sed 's/\//_/g'`.tar.bz2 `basename $i`
+       if [ $? -ne 0 ] ; then
+               echo "Exiting due to error"
+               exit 1
+       fi
+done
+
+cd $OUT_DIR
+md5sum *.tar.bz2 > md5sums
+
+cd $OLD_PWD
+
diff --git a/contrib/opie/opie_release.sh b/contrib/opie/opie_release.sh
new file mode 100755 (executable)
index 0000000..b15b85a
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+if ! [ -d libqpe ] ; then
+    echo "Please execute at the recipes subdir of the OE source tree"
+    exit 1
+fi
+
+if [ x$1 == x ] ; then
+    echo "usage: $0 new_version"
+    exit 1
+fi
+
+FILES="libqpe libqtaux libopie* libmailwrapper nonworking/opie* opie*"
+
+NEW_VER="$1"
+
+for i in $FILES ; do
+       for j in $i/*_cvs.bb ; do
+               if [ -f $j ] ; then
+                       NEW_FILE=`echo $j | sed "s/_cvs/_$NEW_VER/"`
+                       cp $j $NEW_FILE
+                       sed 's/\${OPIE_GIT};protocol=git;subpath=/@@@/g;ta;b;:a;s/\//_/g;s/ *\"$/.tar.bz2\"/;s/ *\\$/.tar.bz2 \\/;s/@@@/http:\/\/sources.openembedded.org\/opie-VERSION-split_/' -i $NEW_FILE
+                       sed "s/opie-VERSION-split/opie-$NEW_VER-split/g" -i $NEW_FILE
+                       sed '/^PV =/d' -i $NEW_FILE
+                       sed '/^OPIE_GIT_PV/d' -i $NEW_FILE
+                       sed 's/^PR = "r.*/PR = "r0"/' -i $NEW_FILE
+                       sed 's/^PR = "\${INC_PR}\..*/PR = "\${INC_PR}.0"/' -i $NEW_FILE
+                       cat -s $NEW_FILE > $NEW_FILE.new
+                       mv $NEW_FILE.new $NEW_FILE
+                       git add $NEW_FILE
+               fi
+       done
+done
+
+cp opie-icon-reload/opie-icon-reload_1.2.5.bb opie-icon-reload/opie-icon-reload_$NEW_VER.bb
+git add opie-icon-reload/opie-icon-reload_$NEW_VER.bb