"Fossies" - the Fresh Open Source Software Archive

Member "svnchecker-0.3/checks/RejectTabs.py" (19 Jul 2008, 1639 Bytes) of package /linux/privat/old/svnchecker-0.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "RejectTabs.py" see the Fossies "Dox" file reference documentation.

    1 # Copyright 2008 Adam Byrtek
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License");
    4 # you may not use this file except in compliance with the License.
    5 # You may obtain a copy of the License at
    6 #
    7 #     http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS,
   11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12 # See the License for the specific language governing permissions and
   13 # limitations under the License.
   14 
   15 """ Reject files with given extensions that include leading tabs. """
   16 
   17 import re
   18 
   19 def run(trans, config):
   20     check = config.getArray("RejectTabs.CheckFiles", [".*"])
   21     ignore = config.getArray("RejectTabs.IgnoreFiles", [])
   22     files = trans.getFiles(check, ignore)
   23 
   24     errors = []
   25     for filename, attr in files.iteritems():
   26         if attr not in ["A", "U"]:
   27             # Process only files which were added or updated
   28             continue
   29         if trans.hasProperty("svn:mime-type", filename) and trans.getProperty("svn:mime-type", filename) == "application/octet-stream":
   30             # Skip binary files
   31             continue
   32 
   33         file = open(trans.getFile(filename), "r")
   34         try:
   35             for line in file:
   36                 if re.match("^\s*\t", line):
   37                     errors.append("File %s contains leading tabs" % filename)
   38                     break
   39         finally:
   40             file.close()
   41 
   42     if len(errors) == 0:
   43         return ("", 0)
   44     else:
   45         return ("\n".join(errors), 1)