#!/usr/bin/env python
# $Id: check.py,v 1.1 2005/10/29 18:38:42 devel Exp $
# Author: Jim E. Brooks http://www.jimbrooks.org
# Compile-time checks on Python source code.

import sys, os
from string import *

def CheckTabs( fileList ):
    """ Check if a Python source file contains any tab chars.
        Returns True if no tabs were found. """
    for fname in fileList:
        # Try block in case file list is an unexpanded glob.
        try:
            f = open( fname )
            buf = f.read( -1 )
            f.close()
            if buf.find( '\t' ) != -1:
                sys.stderr.write( "ERROR: found tab char in " + fname + "\n" )
                #sys.exit(1)    # doesn't work in a try block, exit code would be 0
                return False
        except:
            pass
        return True

i = -1
for arg in sys.argv:
    i += 1
    if arg == "-tabs":
        if not CheckTabs( sys.argv[i+1:] ):
            sys.exit(1)

sys.exit(0)
