~launchpad-pqm/launchpad/devel

7176.4.1 by Tom Haddon
Only create/recreate the bzr_version_info file if it's changed/needed
1
#!/bin/bash
2
#
8687.15.23 by Karl Fogel
Add the copyright header block to more files.
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
#
7176.4.1 by Tom Haddon
Only create/recreate the bzr_version_info file if it's changed/needed
6
# Update bzr-version-info.py -- but only if the revision number has
7
# changed
8
#
9
10
if ! which bzr > /dev/null || !  test -x $(which bzr); then
11
    echo "No working 'bzr' executable found"
12
    exit 1
13
fi
14
7176.4.2 by Tom Haddon
Filename is bzr-version-info not bzr_version_info
15
newfile=bzr-version-info-${RANDOM}.py
9641.1.6 by Gary Poster
fix a variety of tests found by running this branch in karmic.
16
bzr version-info --format=python > $newfile 2>/dev/null;
7176.4.1 by Tom Haddon
Only create/recreate the bzr_version_info file if it's changed/needed
17
# There's a leading space here that I don't care to trim.. 
18
revno=$(python $newfile | grep revision: | cut -d: -f2)
7176.4.2 by Tom Haddon
Filename is bzr-version-info not bzr_version_info
19
if ! [ -f bzr-version-info.py ]; then
20
    echo "Creating bzr-version-info.py at revno$revno"
21
    mv ${newfile} bzr-version-info.py
7176.4.1 by Tom Haddon
Only create/recreate the bzr_version_info file if it's changed/needed
22
else
23
    # Here we compare the actual output instead of the contents of the
24
    # file because bzr includes a build-date that is actually updated
25
    # every time you run bzr version-info.
26
    newcontents=$(python $newfile)
7176.4.2 by Tom Haddon
Filename is bzr-version-info not bzr_version_info
27
    oldcontents=$(python bzr-version-info.py)
7176.4.1 by Tom Haddon
Only create/recreate the bzr_version_info file if it's changed/needed
28
    if [ "$newcontents" != "$oldcontents" ]; then
7176.4.2 by Tom Haddon
Filename is bzr-version-info not bzr_version_info
29
        echo "Updating bzr-version-info.py to revno$revno"
30
        mv ${newfile} bzr-version-info.py
7176.4.1 by Tom Haddon
Only create/recreate the bzr_version_info file if it's changed/needed
31
    else
7176.4.2 by Tom Haddon
Filename is bzr-version-info not bzr_version_info
32
        echo "Skipping bzr-version-info.py update; already at revno$revno"
7176.4.1 by Tom Haddon
Only create/recreate the bzr_version_info file if it's changed/needed
33
        rm ${newfile}
34
    fi
35
fi