root/scripts/trailing_whitespace_report.py

Revision 559:352e5cce339c, 1.3 kB (checked in by David Anderson <dave@…>, 7 months ago)

Add a top-level scripts directory for general development helpers.

The main helper right now is configure-repos.py, which sets up
a .hg/hgrc with useful paths and hook scripts to perform basic
sanity checking.

  • Property exe set to *
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright (c) 2008 the NxOS developers
5#
6# See AUTHORS for a full list of the developers.
7#
8# Redistribution of this file is permitted under
9# the terms of the GNU Public License (GPL) version 2.
10#
11# Receives a unified diff on standard input. Looks for adds that
12# insert trailing whitespace, and reports them along with
13# file/line/function info. If any added trailing whitespace is found,
14# exits in error. Also reports win32 EOLs.
15
16import os
17import sys
18
19file = '<file unknown>'
20function = '<function unknown>'
21ok = True
22
23for line in sys.stdin:
24    if line.startswith('+++'):
25        file = line.split()[1][2:]
26        function = '<function unknown>'
27        continue
28    elif line.startswith('@@'):
29        function = line.split('@@')[2].strip() or '<function unknown>'
30        continue
31    elif line.startswith('+'):
32        line = line.rstrip('\n')
33        if line.endswith(' ') or line.endswith('\t'):
34            print 'Trailing whitespace at %s in %s:' % (file, function)
35            print line
36            ok = False
37        if line.endswith('\r'):
38            print 'Windows-style EOL at %s in %s:' % (file, function)
39            print line
40            ok = False
41
42if ok:
43    sys.exit(0)
44else:
45    os.system('hg tip --template {desc} >commit.msg')
46    print 'Commit message saved in commit.msg'
47    sys.exit(1)
Note: See TracBrowser for help on using the browser.