annotate es/examples/data/check_whitespace.py @ 827:d2aacc06e562

Add more paragraph IDs
author Bryan O'Sullivan <bos@serpentine.com>
date Sun, 03 May 2009 20:27:28 -0700
parents 04c08ad7e92e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
432
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
1 #!/usr/bin/python
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
2
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
3 import re
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
4
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
5 def trailing_whitespace(difflines):
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
6 added, linenum, header = [], 0, False
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
7
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
8 for line in difflines:
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
9 if header:
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
10 # remember the name of the file that this diff affects
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
11 m = re.match(r'(?:---|\+\+\+) ([^\t]+)', line)
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
12 if m and m.group(1) != '/dev/null':
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
13 filename = m.group(1).split('/', 1)[-1]
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
14 if line.startswith('+++ '):
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
15 header = False
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
16 continue
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
17 if line.startswith('diff '):
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
18 header = True
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
19 continue
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
20 # hunk header - save the line number
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
21 m = re.match(r'@@ -\d+,\d+ \+(\d+),', line)
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
22 if m:
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
23 linenum = int(m.group(1))
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
24 continue
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
25 # hunk body - check for an added line with trailing whitespace
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
26 m = re.match(r'\+.*\s$', line)
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
27 if m:
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
28 added.append((filename, linenum))
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
29 if line and line[0] in ' +':
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
30 linenum += 1
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
31 return added
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
32
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
33 if __name__ == '__main__':
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
34 import os, sys
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
35
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
36 added = trailing_whitespace(os.popen('hg export tip'))
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
37 if added:
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
38 for filename, linenum in added:
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
39 print >> sys.stderr, ('%s, line %d: trailing whitespace added' %
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
40 (filename, linenum))
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
41 # save the commit message so we don't need to retype it
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
42 os.system('hg tip --template "{desc}" > .hg/commit.save')
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
43 print >> sys.stderr, 'commit message saved to .hg/commit.save'
04c08ad7e92e Translated svgs dummy .tex towards building
Igor TAmara <igor@tamarapatino.org>
parents:
diff changeset
44 sys.exit(1)