4017.1.2
by Andrew Bennetts
Just use the system bzr in utilities/lint.sh, rather than mucking about with PYTHONPATH. |
1 |
#!/bin/bash
|
2173
by Canonical.com Patch Queue Manager
[trivial] Landing initial version of linter script -- use it before committing\! |
2 |
#
|
11636.1.4
by Henning Eggers
Hm, yummy dogfood\! |
3 |
# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
|
8687.15.5
by Karl Fogel
Add the copyright header block to another file. |
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
8452.3.3
by Karl Fogel
* utilities/: Add copyright header block to source files that were |
5 |
#
|
11090.2.2
by Curtis Hovey
Replace all the shell hacks with a single call to pocketlint. |
6 |
# Runs pocketlint on files changed from parent branch.
|
7 |
||
4935.3.3
by Curtis Hovey
Updated a few files to illustrate how lint works. |
8 |
|
10713.1.1
by Gary Poster
use new version of z3c.recipe.filetemplate and zc.buildout fork to use relative paths. |
9 |
${shell-relative-path-setup} |
10 |
||
11 |
utilitiesdir=${buildout:directory/utilities|shell-path} |
|
5722.5.1
by James Henstridge
* Add pyflakes-doctest.py program, which performs pyflakes tests against |
12 |
[ -z "$utilitiesdir" ] && utilitiesdir=. |
4935.3.5
by Curtis Hovey
Revised the lint script and the pylint rules. |
13 |
|
14 |
||
2175
by Canonical.com Patch Queue Manager
[trivial] re-adding conflict marker support to lint.sh, darn |
15 |
if [ -z "$1" ]; then |
11636.1.1
by Henning Eggers
Extracted find-changed-files. |
16 |
# No command line argument provided, lint all changed files.
|
17 |
files=$($utilitiesdir/find-changed-files.sh) |
|
2173
by Canonical.com Patch Queue Manager
[trivial] Landing initial version of linter script -- use it before committing\! |
18 |
else
|
4935.3.9
by Curtis Hovey
Minor changes to lint.sh |
19 |
# Add newlines so grep filters out pyfiles correctly later.
|
2513
by Canonical.com Patch Queue Manager
[trivial] Implement make lintmerge. |
20 |
files=`echo $* | tr " " "\n"` |
2173
by Canonical.com Patch Queue Manager
[trivial] Landing initial version of linter script -- use it before committing\! |
21 |
fi
|
22 |
||
4935.3.5
by Curtis Hovey
Revised the lint script and the pylint rules. |
23 |
|
4935.3.9
by Curtis Hovey
Minor changes to lint.sh |
24 |
echo "= Launchpad lint =" |
25 |
echo "" |
|
11090.2.2
by Curtis Hovey
Replace all the shell hacks with a single call to pocketlint. |
26 |
echo "Checking for conflicts and issues in changed files." |
4935.3.9
by Curtis Hovey
Minor changes to lint.sh |
27 |
|
28 |
if [ -z "$files" ]; then |
|
29 |
echo "No changed files detected." |
|
30 |
exit 0 |
|
3691.422.10
by David Allouche
Print the list of checked files. |
31 |
else
|
32 |
echo
|
|
33 |
echo "Linting changed files:" |
|
34 |
for file in $files; do |
|
35 |
echo " $file" |
|
36 |
done
|
|
4935.3.9
by Curtis Hovey
Minor changes to lint.sh |
37 |
fi
|
38 |
||
39 |
||
11090.2.2
by Curtis Hovey
Replace all the shell hacks with a single call to pocketlint. |
40 |
# Are there patches to the schema or changes to current.sql?
|
6501.1.1
by Curtis Hovey
Added support to detect changes to sampeldata. |
41 |
sample_dir="database/sampledata" |
8567.1.1
by Gary Poster
fix lint |
42 |
current_sql="$sample_dir/current.sql" |
43 |
current_dev_sql="$sample_dir/current-dev.sql" |
|
44 |
lintdata_sql="$sample_dir/lintdata.sql" |
|
45 |
lintdata_dev_sql="$sample_dir/lintdata-dev.sql" |
|
11090.2.2
by Curtis Hovey
Replace all the shell hacks with a single call to pocketlint. |
46 |
database_changes=$(echo $files | sed '/database.*\(patch-\|current\)/!d') |
8567.1.1
by Gary Poster
fix lint |
47 |
if [ -n "$database_changes" ]; then |
6887.3.1
by Curtis Hovey
Added a contraint to only check sampledata when there is a change to a patch or |
48 |
make -C database/schema lintdata > /dev/null |
8567.1.1
by Gary Poster
fix lint |
49 |
sql_diff=$(diff -q "$current_sql" "$lintdata_sql") |
6852.1.1
by Gavin Panella
Don't bother people with sampledata out-of-date complaints if they've not gone anywhere near the database. |
50 |
if [ -z "$sql_diff" ]; then |
6887.3.1
by Curtis Hovey
Added a contraint to only check sampledata when there is a change to a patch or |
51 |
rm $lintdata_sql
|
6852.1.1
by Gavin Panella
Don't bother people with sampledata out-of-date complaints if they've not gone anywhere near the database. |
52 |
fi
|
8567.1.1
by Gary Poster
fix lint |
53 |
sql_dev_diff=$(diff -q "$current_dev_sql" "$lintdata_dev_sql") |
7245.1.4
by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB. |
54 |
if [ -z "$sql_dev_diff" ]; then |
55 |
rm $lintdata_dev_sql
|
|
56 |
fi
|
|
6852.1.1
by Gavin Panella
Don't bother people with sampledata out-of-date complaints if they've not gone anywhere near the database. |
57 |
else
|
58 |
sql_diff="" |
|
7245.1.4
by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB. |
59 |
sql_dev_diff="" |
6852.1.1
by Gavin Panella
Don't bother people with sampledata out-of-date complaints if they've not gone anywhere near the database. |
60 |
fi
|
61 |
||
6501.1.1
by Curtis Hovey
Added support to detect changes to sampeldata. |
62 |
karma_bombs=`sed '/INTO karma /!d; /2000-/d; /2001-/d' $current_sql` |
6852.1.1
by Gavin Panella
Don't bother people with sampledata out-of-date complaints if they've not gone anywhere near the database. |
63 |
|
7245.1.4
by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB. |
64 |
echo_sampledata_changes () { |
65 |
echo " $2 differs from $1." |
|
66 |
echo " Patches to the schema, or manual edits to $1" |
|
67 |
echo " do not match the dump of the $3 database." |
|
68 |
echo " If $2 is correct, copy it to" |
|
69 |
echo " $1." |
|
70 |
echo " Otherwise update $1 and run:" |
|
71 |
echo " make schema" |
|
72 |
echo " make newsampledata" |
|
8567.1.1
by Gary Poster
fix lint |
73 |
echo " cd $sample_dir" |
7245.1.4
by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB. |
74 |
echo " cp $4 $1" |
75 |
echo " Run make schema again to update the test/dev database." |
|
76 |
}
|
|
10713.1.1
by Gary Poster
use new version of z3c.recipe.filetemplate and zc.buildout fork to use relative paths. |
77 |
|
7245.1.4
by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB. |
78 |
if [ -n "$sql_diff" -o -n "$sql_dev_diff" -o -n "$karma_bombs" ]; then |
79 |
echo "" |
|
80 |
echo "" |
|
81 |
echo "== Schema ==" |
|
82 |
echo "" |
|
83 |
fi
|
|
84 |
||
10713.1.1
by Gary Poster
use new version of z3c.recipe.filetemplate and zc.buildout fork to use relative paths. |
85 |
#
|
6835.4.4
by Guilherme Salgado
A few changes as requested by Gavin. |
86 |
if [ -n "$sql_diff" -o -n "$karma_bombs" ]; then |
6501.1.1
by Curtis Hovey
Added support to detect changes to sampeldata. |
87 |
echo "$current_sql" |
6835.4.4
by Guilherme Salgado
A few changes as requested by Gavin. |
88 |
fi
|
89 |
if [ -n "$sql_diff" ]; then |
|
7245.1.4
by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB. |
90 |
echo_sampledata_changes \
|
91 |
"$current_sql" "$lintdata_sql" "launchpad_ftest_template"\ |
|
92 |
"newsampledata.sql"
|
|
6835.4.4
by Guilherme Salgado
A few changes as requested by Gavin. |
93 |
fi
|
94 |
if [ -n "$karma_bombs" ]; then |
|
6501.1.1
by Curtis Hovey
Added support to detect changes to sampeldata. |
95 |
echo " Karma time bombs were added to sampledata." |
6501.1.5
by Curtis Hovey
Changes per review. |
96 |
echo " The Karma table has dates after 2002-01-01; either revise" |
97 |
echo " them or remove rows if they are unneeded." |
|
6501.1.1
by Curtis Hovey
Added support to detect changes to sampeldata. |
98 |
fi
|
99 |
||
7245.1.4
by Guilherme Salgado
make schema will now create two new DBs (launchpad_dev_template and launchpad_ftest_playground). make newsampledata will use different DBs for the dev/test sampledata and lint.sh will complain if either current.sql or current-dev.sql don't match dumps of their DB. |
100 |
if [ -n "$sql_dev_diff" ]; then |
101 |
echo "" |
|
102 |
echo "$current_sql" |
|
103 |
echo_sampledata_changes \
|
|
104 |
"$current_dev_sql" "$lintdata_dev_sql" "launchpad_dev_template"\ |
|
105 |
"newsampledata-dev.sql"
|
|
106 |
fi
|
|
6501.1.1
by Curtis Hovey
Added support to detect changes to sampeldata. |
107 |
|
11090.2.2
by Curtis Hovey
Replace all the shell hacks with a single call to pocketlint. |
108 |
|
109 |
# Sample data contains auto generated files with long lines.
|
|
12599.4.2
by Leonard Richardson
Merge from trunk. |
110 |
pocketlint_files=`echo "$files" | env -i grep -v ".sql$"` |
11090.2.2
by Curtis Hovey
Replace all the shell hacks with a single call to pocketlint. |
111 |
if [ -z "$pocketlint_files" ]; then |
4935.3.5
by Curtis Hovey
Revised the lint script and the pylint rules. |
112 |
exit 0 |
113 |
fi
|
|
114 |
||
11090.2.2
by Curtis Hovey
Replace all the shell hacks with a single call to pocketlint. |
115 |
echo "" |
116 |
pocketlint $pocketlint_files 2>&1 |