~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
#
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
#
# Runs pocketlint on files changed from parent branch.


${shell-relative-path-setup}

utilitiesdir=${buildout:directory/utilities|shell-path}
[ -z "$utilitiesdir" ] && utilitiesdir=.


bzr() {
    # For pylint to operate properly, PYTHONPATH must point to the ./lib
    # directory in the launchpad tree. This directory includes a bzrlib. When
    # this script calls bzr, we want it to use the system bzrlib, not the one
    # in the launchpad tree.
    PYTHONPATH='' `which bzr` "$@"
}


if [ -z "$1" ]; then
    # No command line argument provided, use the default logic.
    bzr diff > /dev/null
    diff_status=$?
    if [ $diff_status -eq 0 ] ; then
        # No uncommitted changes in the tree.
        bzr status | grep "^Current thread:" > /dev/null
        if [ $? -eq 0 ] ; then
            # This is a loom, lint changes relative to the lower thread.
            rev_option="-r thread:"
        else
            if test "$(bzr pipes | sed -n -e "/^\\*/q;p" | wc -l)" -gt 0; then
                # This is a pipeline with at least one pipe before the
                # current, lint changes relative to the previous pipe
                rev_option="-r ancestor::prev"
            else
                # Lint changes relative to the parent.
                rev=`bzr info | sed \
                    '/parent branch:/!d; s/ *parent branch: /ancestor:/'`
                rev_option="-r $rev"
            fi
        fi
    elif [ $diff_status -eq 1 ] ; then
        # Uncommitted changes in the tree, lint those changes.
        rev_option=""
    else
        # bzr diff failed
        exit 1
    fi
    # Extract filename from status line.  Strip the @ that mark symlinks.
    files=`bzr st --short $rev_option |
        sed -e '/^.[MN]/!d; s/.* //' -e 's/@$//'`
else
    # Add newlines so grep filters out pyfiles correctly later.
    files=`echo $* | tr " " "\n"`
fi


echo "= Launchpad lint ="
echo ""
echo "Checking for conflicts and issues in changed files."

if [ -z "$files" ]; then
    echo "No changed files detected."
    exit 0
else
    echo
    echo "Linting changed files:"
    for file in $files; do
        echo "  $file"
    done
fi


# Are there patches to the schema or changes to current.sql?
sample_dir="database/sampledata"
current_sql="$sample_dir/current.sql"
current_dev_sql="$sample_dir/current-dev.sql"
lintdata_sql="$sample_dir/lintdata.sql"
lintdata_dev_sql="$sample_dir/lintdata-dev.sql"
database_changes=$(echo $files | sed '/database.*\(patch-\|current\)/!d')
if [ -n "$database_changes" ]; then
    make -C database/schema lintdata > /dev/null
    sql_diff=$(diff -q "$current_sql" "$lintdata_sql")
    if [ -z "$sql_diff" ]; then
        rm $lintdata_sql
    fi
    sql_dev_diff=$(diff -q "$current_dev_sql" "$lintdata_dev_sql")
    if [ -z "$sql_dev_diff" ]; then
        rm $lintdata_dev_sql
    fi
else
    sql_diff=""
    sql_dev_diff=""
fi

karma_bombs=`sed '/INTO karma /!d; /2000-/d; /2001-/d' $current_sql`

echo_sampledata_changes () {
    echo "    $2 differs from $1."
    echo "    Patches to the schema, or manual edits to $1"
    echo "    do not match the dump of the $3 database."
    echo "    If $2 is correct, copy it to"
    echo "    $1."
    echo "    Otherwise update $1 and run:"
    echo "        make schema"
    echo "        make newsampledata"
    echo "        cd $sample_dir"
    echo "        cp $4 $1"
    echo "    Run make schema again to update the test/dev database."
}

if [ -n "$sql_diff" -o -n "$sql_dev_diff" -o -n "$karma_bombs" ]; then
    echo ""
    echo ""
    echo "== Schema =="
    echo ""
fi

#
if [ -n "$sql_diff" -o -n "$karma_bombs" ]; then
    echo "$current_sql"
fi
if [ -n "$sql_diff" ]; then
    echo_sampledata_changes \
        "$current_sql" "$lintdata_sql" "launchpad_ftest_template"\
       	"newsampledata.sql"
fi
if [ -n "$karma_bombs" ]; then
    echo "    Karma time bombs were added to sampledata."
    echo "        The Karma table has dates after 2002-01-01; either revise"
    echo "        them or remove rows if they are unneeded."
fi

if [ -n "$sql_dev_diff" ]; then
    echo ""
    echo "$current_sql"
    echo_sampledata_changes \
        "$current_dev_sql" "$lintdata_dev_sql" "launchpad_dev_template"\
       	"newsampledata-dev.sql"
fi


# Sample data contains auto generated files with long lines.
pocketlint_files=`echo "$files" | grep -v "$sample_dir"`
if [ -z "$pocketlint_files" ]; then
    exit 0
fi

echo ""
pocketlint $pocketlint_files 2>&1