Merge lp:~cr3/checkbox/tools into lp:checkbox

Proposed by Marc Tardif
Status: Merged
Approved by: Marc Tardif
Approved revision: 1705
Merged at revision: 1714
Proposed branch: lp:~cr3/checkbox/tools
Merge into: lp:checkbox
Diff against target: 162 lines (+147/-0)
2 files modified
debian/changelog (+1/-0)
lint (+146/-0)
To merge this branch: bzr merge lp:~cr3/checkbox/tools
Reviewer Review Type Date Requested Status
Marc Tardif (community) Needs Resubmitting
Brendan Donegan (community) Approve
Review via email: mp+126706@code.launchpad.net

Commit message

Merged ./lint script to check syntax consistently.

Description of the change

To post a comment you must log in.
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

We can refine this over time with different checks and so on, the principle is good though!

review: Approve
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Attempt to merge into lp:checkbox failed due to conflicts:

text conflict in debian/changelog

lp:~cr3/checkbox/tools updated
1705. By Marc Tardif

Merged from trunk.

Revision history for this message
Marc Tardif (cr3) wrote :

Merged from trunk to resolve conflict.

review: Needs Resubmitting

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2012-09-27 09:00:46 +0000
3+++ debian/changelog 2012-09-27 16:35:27 +0000
4@@ -87,6 +87,7 @@
5 * checkbox/parsers/description.py: Fixed the PURPOSE and STEPS parts
6 of the description parser to automatically fix bad descriptions.
7 * plugins/suites_prompt.py: Fixed tree view in selection window (LP #1056432)
8+ * [FEATURE] tools/lint: Added script to consistently check syntax.
9
10 [Sean Feole]
11 * [FEATURE] scripts/battery_test: measures battery capacity before and after
12
13=== added file 'lint'
14--- lint 1970-01-01 00:00:00 +0000
15+++ lint 2012-09-27 16:35:27 +0000
16@@ -0,0 +1,146 @@
17+#!/bin/bash
18+#
19+# Runs pep8 on files changed from parent branch.
20+
21+# Fail if any of the required tools are not installed.
22+if ! which pep8 >/dev/null; then
23+ echo "Error: pep8 is not installed."
24+ echo " Install the pep8 package."
25+ exit 1
26+fi
27+
28+EXIT=0
29+
30+if [ -z "$1" ]; then
31+ bzr diff > /dev/null
32+ diff_status=$?
33+ if [ $diff_status -eq 0 ] ; then
34+ # No uncommitted changes in the tree.
35+ bzr status | grep "^Current thread:" > /dev/null
36+ if [ $? -eq 0 ] ; then
37+ # This is a loom, lint changes relative to the lower thread.
38+ rev_option="-r thread:"
39+ else
40+ # Lint changes relative to the parent.
41+ rev=`bzr info | sed \
42+ '/parent branch:/!d; s/ *parent branch: /ancestor:/'`
43+ rev_option="-r $rev"
44+ fi
45+ elif [ $diff_status -eq 1 ] ; then
46+ # Uncommitted changes in the tree, return those files.
47+ rev_option=""
48+ else
49+ # bzr diff failed
50+ exit 1
51+ fi
52+ # Extract filename from status line. Strip the @ that mark symlinks.
53+ files=`bzr st --short $rev_option |
54+ sed -e '/^.[MN]/!d; s/.* //' -e 's/@$//'`
55+else
56+ # Add newlines so grep filters out pyfiles correctly later.
57+ files=`echo $* | tr " " "\n"`
58+fi
59+
60+echo "= lint ="
61+echo
62+echo "Checking for conflicts and issues in changed files."
63+
64+if [ -z "$files" ]; then
65+ echo "No changed files detected."
66+ exit 0
67+else
68+ echo
69+ echo "Linting changed files:"
70+ for file in $files; do
71+ echo " $file"
72+ done
73+fi
74+
75+pep8_header=0
76+pep8_notices() {
77+ if [ $pep8_header -eq 0 ]; then
78+ pep8_header=1
79+ echo
80+ echo
81+ echo "== pep8 notices =="
82+ fi
83+
84+ # Format file:line:message output as lines grouped by file.
85+ file_name=""
86+ echo "$1" | sed 's,\(^[^ :<>=+]*:\),~~\1\n,' | while read line; do
87+ current=`echo $line | sed '/^~~/!d; s/^~~\(.*\):$/\1/;'`
88+ if [ -z "$current" ]; then
89+ echo " $line"
90+ elif [ "$file_name" != "$current" ]; then
91+ file_name="$current"
92+ echo
93+ echo "$file_name"
94+ fi
95+ done
96+}
97+
98+conflicts=""
99+for file in $files; do
100+ # NB. Odd syntax on following line to stop lint.sh detecting conflict
101+ # markers in itself.
102+ if [ ! -f "$file" ]; then
103+ continue
104+ fi
105+ if grep -q -e '<<<''<<<<' -e '>>>''>>>>' $file; then
106+ conflicts="$conflicts $file"
107+ fi
108+done
109+
110+if [ "$conflicts" ]; then
111+ echo
112+ echo
113+ echo "== conflict notices =="
114+ echo
115+ for conflict in $conflicts; do
116+ echo "$conflict"
117+ done
118+ EXIT=1
119+fi
120+
121+pyfiles=`echo "$files" | egrep '^scripts|\.py$'`
122+if [ ! -z "$pyfiles" ]; then
123+ # The grep pattern must be generated from the pep8.py file in the
124+ # pep8 package of the latest stable release:
125+ #
126+ # dpkg -L pep8 \
127+ # | grep pep8.py \
128+ # | head -n 1 \
129+ # | xargs cat \
130+ # | sed -n 's/.*\<\(E[[:digit:]][[:digit:]][[:digit:]]\)\>.*/\1/p' \
131+ # | sort -u \
132+ # | tr '\n' '|'
133+ grep_pattern="\
134+(E101|E111|E112|E113|E201|E202|E203|E211|E221|E222|E223|E224|E225|E231\
135+|E241|E242|E251|E261|E262|E301|E302|E303|E304|E401|E501|E701|E702)"
136+
137+ # Source files
138+ srcfiles=`echo "$pyfiles" | egrep '\.py$'`
139+ if [ ! -z "$srcfiles" ]; then
140+ result=`pep8 $srcfiles | egrep "$grep_pattern"`
141+ if [ ! -z "$result" ]; then
142+ pep8_notices "$result"
143+ EXIT=1
144+ fi
145+ fi
146+
147+ # Script files
148+ scriptfiles=`echo "$pyfiles" | egrep '^scripts'`
149+ if [ ! -z "$scriptfiles" ]; then
150+ for file in $scriptfiles; do
151+ if file "$file" | grep -q "python"; then
152+ result=`pep8 $file | egrep "$grep_pattern"`
153+ if [ ! -z "$result" ]; then
154+ pep8_notices "$result"
155+ EXIT=1
156+ fi
157+ fi
158+ done
159+ fi
160+fi
161+
162+exit $EXIT

Subscribers

People subscribed via source and target branches