[Checkins] SVN: refline.srccheck/ initial upload

Adam Groszer cvs-admin at zope.org
Mon Apr 2 14:17:26 UTC 2012


Log message for revision 124883:
  initial upload

Changed:
  _U  refline.srccheck/
  A   refline.srccheck/CHANGES.txt
  A   refline.srccheck/COPYRIGHT.txt
  A   refline.srccheck/LICENSE.txt
  A   refline.srccheck/README.txt
  A   refline.srccheck/TODO.txt
  A   refline.srccheck/bootstrap.py
  A   refline.srccheck/buildout.cfg
  A   refline.srccheck/setup.py
  A   refline.srccheck/src/
  A   refline.srccheck/src/refline/
  A   refline.srccheck/src/refline/__init__.py
  A   refline.srccheck/src/refline/srccheck/
  A   refline.srccheck/src/refline/srccheck/README.txt
  A   refline.srccheck/src/refline/srccheck/__init__.py
  A   refline.srccheck/src/refline/srccheck/checker.py
  A   refline.srccheck/src/refline/srccheck/pyflakes.py
  A   refline.srccheck/src/refline/srccheck/testing/
  A   refline.srccheck/src/refline/srccheck/testing/__init__.py
  A   refline.srccheck/src/refline/srccheck/testing/bad.py
  A   refline.srccheck/src/refline/srccheck/tests.py

-=-

Property changes on: refline.srccheck
___________________________________________________________________
Added: svn:ignore
   + bin
.installed.cfg
develop-eggs
parts


Added: refline.srccheck/CHANGES.txt
===================================================================
--- refline.srccheck/CHANGES.txt	                        (rev 0)
+++ refline.srccheck/CHANGES.txt	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1,7 @@
+CHANGES
+=======
+
+0.5 (unreleased)
+----------------
+
+Initial release on Cheeseshop.


Property changes on: refline.srccheck/CHANGES.txt
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native

Added: refline.srccheck/COPYRIGHT.txt
===================================================================
--- refline.srccheck/COPYRIGHT.txt	                        (rev 0)
+++ refline.srccheck/COPYRIGHT.txt	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1 @@
+Zope Foundation and Contributors
\ No newline at end of file


Property changes on: refline.srccheck/COPYRIGHT.txt
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native

Added: refline.srccheck/LICENSE.txt
===================================================================
--- refline.srccheck/LICENSE.txt	                        (rev 0)
+++ refline.srccheck/LICENSE.txt	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1,44 @@
+Zope Public License (ZPL) Version 2.1
+
+A copyright notice accompanies this license document that identifies the
+copyright holders.
+
+This license has been certified as open source. It has also been designated as
+GPL compatible by the Free Software Foundation (FSF).
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions in source code must retain the accompanying copyright
+notice, this list of conditions, and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the accompanying copyright
+notice, this list of conditions, and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+3. Names of the copyright holders must not be used to endorse or promote
+products derived from this software without prior written permission from the
+copyright holders.
+
+4. The right to distribute this software or to use it for any purpose does not
+give you the right to use Servicemarks (sm) or Trademarks (tm) of the
+copyright
+holders. Use of them is covered by separate agreement with the copyright
+holders.
+
+5. If any files are modified, you must cause the modified files to carry
+prominent notices stating that you changed the files and the date of any
+change.
+
+Disclaimer
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Property changes on: refline.srccheck/LICENSE.txt
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native

Added: refline.srccheck/README.txt
===================================================================
--- refline.srccheck/README.txt	                        (rev 0)
+++ refline.srccheck/README.txt	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1 @@
+This is a generic package that does some source checking/linting jobs.


Property changes on: refline.srccheck/README.txt
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native

Added: refline.srccheck/TODO.txt
===================================================================
--- refline.srccheck/TODO.txt	                        (rev 0)
+++ refline.srccheck/TODO.txt	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1,6 @@
+To-do
+-----
+
+- Add CSS validation
+
+- Add some more files to run the checks on. e.g. to refline.srccheck.testing


Property changes on: refline.srccheck/TODO.txt
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native

Added: refline.srccheck/bootstrap.py
===================================================================
--- refline.srccheck/bootstrap.py	                        (rev 0)
+++ refline.srccheck/bootstrap.py	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1,48 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                     ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+    os.P_WAIT, sys.executable, sys.executable,
+    '-c', 'from setuptools.command.easy_install import main; main()',
+    '-mqNxd', tmpeggs, 'zc.buildout',
+    {'PYTHONPATH':
+     ws.find(pkg_resources.Requirement.parse('setuptools')).location
+     },
+    ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)


Property changes on: refline.srccheck/bootstrap.py
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native

Added: refline.srccheck/buildout.cfg
===================================================================
--- refline.srccheck/buildout.cfg	                        (rev 0)
+++ refline.srccheck/buildout.cfg	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1,7 @@
+[buildout]
+develop = .
+parts = test
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = refline.srccheck [test]


Property changes on: refline.srccheck/buildout.cfg
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native

Added: refline.srccheck/setup.py
===================================================================
--- refline.srccheck/setup.py	                        (rev 0)
+++ refline.srccheck/setup.py	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1,60 @@
+##############################################################################
+#
+# Copyright (c) Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Setup for refline.srccheck package
+"""
+import os
+from setuptools import setup, find_packages
+
+
+def read(*rnames):
+    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+setup(
+    name="refline.srccheck",
+    version="0.5.0dev",
+    url="http://pypi.python.org/pypi/refline.srccheck/",
+    install_requires=[
+        'setuptools',
+        'pyflakes == 0.4.0',  # pyflakes 0.5.0 does not like python 2.6's AST
+        'polib',
+    ],
+    extras_require=dict(
+        test=[]),
+    packages=find_packages('src'),
+    package_dir={'': 'src'},
+
+    namespace_packages=['refline'],
+
+    author='Zope Foundation and Contributors',
+    author_email='zope-dev at zope.org',
+    description="Source checking/linting tool",
+    long_description=(
+        read('README.txt')
+        + '\n\n' +
+        read('CHANGES.txt')
+        ),
+    license='ZPL 2.1',
+    keywords="zope zope3",
+    classifiers=[
+        'Development Status :: 5 - Production/Stable',
+        'Environment :: Web Environment',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: Zope Public License',
+        'Programming Language :: Python',
+        'Natural Language :: English',
+        'Operating System :: OS Independent',
+        'Topic :: Internet :: WWW/HTTP',
+        'Framework :: Zope3'],
+    zip_safe=False,
+    )


Property changes on: refline.srccheck/setup.py
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native


Property changes on: refline.srccheck/src
___________________________________________________________________
Added: svn:ignore
   + refline.srccheck.egg-info


Added: refline.srccheck/src/refline/__init__.py
===================================================================
--- refline.srccheck/src/refline/__init__.py	                        (rev 0)
+++ refline.srccheck/src/refline/__init__.py	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1,7 @@
+# this is a namespace package
+try:
+    import pkg_resources
+    pkg_resources.declare_namespace(__name__)
+except ImportError:
+    import pkgutil
+    __path__ = pkgutil.extend_path(__path__, __name__)


Property changes on: refline.srccheck/src/refline/__init__.py
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native

Added: refline.srccheck/src/refline/srccheck/README.txt
===================================================================
--- refline.srccheck/src/refline/srccheck/README.txt	                        (rev 0)
+++ refline.srccheck/src/refline/srccheck/README.txt	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1,39 @@
+Source checking/linting tool
+----------------------------
+
+It's easy to use.
+
+Import the package yuou want to check:
+
+  >>> import refline.srccheck
+
+Import the checker:
+
+  >>> from refline.srccheck.checker import checker
+
+Run the checks.
+It will pinpoint the problems found.
+
+  >>> c = checker(refline.srccheck)
+  >>> c.run()
+  <BLANKLINE>
+  testing/bad.py
+  --------------
+    Tab found in file
+  <BLANKLINE>
+  testing/bad.py
+  --------------
+    undefined name 'bar'
+    6:     foo = bar
+
+
+Just in case you cannot / do not want to avoid those problems,
+fix them in the doctest as above.
+
+To ignore files:
+
+- With the string `checker_ignore_this_file` in the file
+
+- With the checker `ignoreFiles` parameter
+
+- With `##ignore PyflakesChecker##` in the file
\ No newline at end of file


Property changes on: refline.srccheck/src/refline/srccheck/README.txt
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native

Added: refline.srccheck/src/refline/srccheck/__init__.py
===================================================================
--- refline.srccheck/src/refline/srccheck/__init__.py	                        (rev 0)
+++ refline.srccheck/src/refline/srccheck/__init__.py	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1 @@
+#
\ No newline at end of file


Property changes on: refline.srccheck/src/refline/srccheck/__init__.py
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native

Added: refline.srccheck/src/refline/srccheck/checker.py
===================================================================
--- refline.srccheck/src/refline/srccheck/checker.py	                        (rev 0)
+++ refline.srccheck/src/refline/srccheck/checker.py	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1,314 @@
+##############################################################################
+#
+# Copyright (c) Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Sourcecode checker, to be used in unittests
+"""
+
+import os
+import os.path
+import string
+import polib
+import fnmatch
+
+from refline.srccheck import pyflakes
+
+INDENT = '  '
+
+
+class BaseChecker(object):
+    fnameprinted = False
+    filename = None
+    basename = None
+    error = None
+
+    def log(self, lineidx, line=None, pos=None):
+        if not self.fnameprinted:
+            # always slash please, for cross platform stability
+            filename = self.filename.replace('\\', '/')
+            filename = filename[len(self.basename) + 1:]
+            print
+            print filename
+            print '-' * len(filename)
+
+        if line is None:
+            #no details
+            if not self.fnameprinted:
+                print "%s%s" % (INDENT, self.error)
+            self.fnameprinted = True
+            return
+
+        self.fnameprinted = True
+
+        print "%s%s" % (INDENT, self.error)
+        lineidx = str(lineidx + 1) + ': '
+        print "%s%s%s" % (INDENT, lineidx, line)
+        if pos is not None:
+            print "%s%s^" % (INDENT, ' ' * (len(lineidx) + pos))
+
+    def check(self, filename, content, lines):
+        pass
+
+    def __call__(self, basename, filename, content, lines):
+        self.fnameprinted = False
+        self.filename = filename
+        self.basename = basename
+
+        return self.check(filename, content, lines)
+
+
+class TabChecker(BaseChecker):
+    error = 'Tab found in file'
+
+    def check(self, filename, content, lines):
+        for idx, line in enumerate(lines):
+            if '\t' in line:
+                self.log(idx)
+
+VALIDCHARS = string.printable
+
+
+class NonAsciiChecker(BaseChecker):
+    error = 'Non ASCII char found in line'
+
+    def check(self, filename, content, lines):
+        for idx, line in enumerate(lines):
+            for cidx, c in enumerate(line):
+                if c not in VALIDCHARS:
+                    self.log(idx, line, cidx)
+                    break
+
+
+class BreakChecker(BaseChecker):
+    error = 'Breakpoint found in line'
+
+    def check(self, filename, content, lines):
+        for idx, line in enumerate(lines):
+            if 'pdb.set_trace' in line \
+                and not (-1 < line.find('#') < line.find('pdb.set_trace')):
+                self.log(idx, line)
+
+            if 'from dbgp.client import brk; brk(' in line \
+                and not (-1 < line.find('#') < line.find('dbgp.client.brk')):
+                self.log(idx, line)
+
+            if 'import rpdb2; rpdb2.start_embedded_debugger' in line \
+                and not (-1 < line.find('#') < line.find(
+                'rpdb2.start_embedded_debugger')):
+                self.log(idx, line)
+
+
+class OpenInBrowserChecker(BaseChecker):
+    error = 'openInBrowser found in line'
+
+    def check(self, filename, content, lines):
+        for idx, line in enumerate(lines):
+            if 'openInBrowser' in line \
+                and not (-1 < line.find('#') < line.find('openInBrowser')):
+                self.log(idx, line)
+
+
+class PyflakesChecker(BaseChecker):
+    error = 'pyflakes warning'
+
+    def fixcontent(self, lines):
+        if not lines:
+            return ''
+        #pyflakes does not like CRLF linefeeds
+        #and files ending with comments
+        idx = len(lines) - 1
+        lastline = lines[idx].strip()
+        while idx >= 1 and (lastline == '' or lastline.startswith('#')):
+            del lines[idx]
+            idx -= 1
+            lastline = lines[idx].strip()
+
+        content = '\n'.join(lines)
+        return content
+
+    def check(self, filename, content, lines):
+        if not content:
+            return
+        if "##ignore PyflakesChecker##" in content:
+            return
+
+        content = self.fixcontent(lines)
+        try:
+            result = pyflakes.check(content, filename)
+        except Exception, e:
+            result = "Fatal exception in pyflakes: %s" % e
+
+        if isinstance(result, basestring):
+            #something fatal occurred
+            self.error = result
+            self.log(0)
+        else:
+            #there are messages
+            for warning in result:
+                if ('undefined name' in warning.message
+                    and not 'unable to detect undefined names' in warning.message):
+                    self.error = warning.message % warning.message_args
+                    self.log(warning.lineno - 1, lines[warning.lineno - 1])
+
+
+class ConsoleLogChecker(BaseChecker):
+    error = 'Breakpoint found in line'
+
+    def check(self, filename, content, lines):
+        for idx, line in enumerate(lines):
+            if 'console.log' in line \
+                and not (-1 < line.find('//') < line.find('console.log')):
+                self.log(idx, line)
+
+
+class POChecker(BaseChecker):
+    error = 'Fuzzy/untranslated found'
+
+    def check(self, filename, content, lines):
+        pos = polib.pofile(filename)
+        untrans = pos.untranslated_entries()
+        fuzzy = pos.fuzzy_entries()
+
+        if len(untrans) > 0:
+            self.log(0, "%s untranslated items" % len(untrans))
+
+        if len(fuzzy) > 0:
+            self.log(0, "%s fuzzy items" % len(fuzzy))
+
+
+class JPGChecker(BaseChecker):
+    error = 'Image bloat found'
+
+    def check(self, filename, content, lines):
+        if "ns.adobe.com" in content:
+            self.log(0, "Adobe Photoshop bloat found")
+            return
+
+        if "<rdf:RDF" in content:
+            self.log(0, "RDF bloat found")
+            return
+
+        if len(content) < 500:
+            return
+
+        compressed = content.encode('zlib')
+        ratio = len(compressed) / float(len(content) - 200)
+        #200= circa static header length
+
+        if ratio < 0.8:
+            self.log(0, "Some other bloat found, compression ratio: %s" %ratio)
+            return
+
+
+class PTFragmentNeedsDomain(BaseChecker):
+    error = "A PT fragment needs i18n:domain otherwise it won't be translated"
+
+    def check(self, filename, content, lines):
+        if '<html' in content:
+            #not a fragment
+            return
+
+        if not 'i18n:translate' in content:
+            #no translation
+            return
+
+        if not 'i18n:domain' in content:
+            #bummer, here we go
+            self.log(0, '')
+
+
+PY_CHECKS = [
+    TabChecker(),
+    NonAsciiChecker(),
+    BreakChecker(),
+    OpenInBrowserChecker(),
+    PyflakesChecker(),
+    ]
+PT_CHECKS = [
+    TabChecker(),
+    NonAsciiChecker(),
+    ConsoleLogChecker(),
+    PTFragmentNeedsDomain(),
+    ]
+JS_CHECKS = [
+    TabChecker(),
+    NonAsciiChecker(),
+    ConsoleLogChecker(),
+    ]
+TXT_CHECKS = [
+    TabChecker(),
+    NonAsciiChecker(),
+    BreakChecker(),
+    OpenInBrowserChecker(),
+    ]
+PO_CHECKS = [
+    POChecker(),
+]
+JPG_CHECKS = [
+    JPGChecker(),
+]
+ZCML_CHECKS = [
+]
+
+CHECKS = {
+    'py':   PY_CHECKS,
+    'pt':   PT_CHECKS,
+    'html': PT_CHECKS,
+    'js':   JS_CHECKS,
+    'txt':  TXT_CHECKS,
+    'po':   PO_CHECKS,
+    'jpg':  JPG_CHECKS,
+    'zcml': ZCML_CHECKS,
+}
+
+
+class checker(object):
+    checks = None
+    extensions = None
+
+    def __init__(self, module, checks=CHECKS, ignoreFiles=()):
+        self.module = module
+        self.checks = checks
+
+        self.extensions = tuple(checks.keys())
+        self.ignoreFiles = ignoreFiles
+
+    def run(self):
+        top = os.path.dirname(self.module.__file__)
+
+        for root, dirs, files in os.walk(top, topdown=True):
+            #keep the name order
+            dirs.sort()
+            files.sort()
+            for name in files:
+                ignoreThis = False
+                for ignore in self.ignoreFiles:
+                    if fnmatch.fnmatch(name, ignore):
+                        ignoreThis = True
+                if ignoreThis:
+                    continue
+
+                justname, ext = os.path.splitext(name)
+                fullname = os.path.join(root, name)
+                ext = ext.replace('.', '')
+
+                if ext in self.extensions:
+                    #read file once, pass the content to checkers
+                    content = open(fullname, 'rb').read()
+
+                    if 'checker_ignore_this_file' in content:
+                        continue
+
+                    lines = content.splitlines()
+
+                    for check in self.checks[ext]:
+                        check(top, fullname, content, lines)


Property changes on: refline.srccheck/src/refline/srccheck/checker.py
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native

Added: refline.srccheck/src/refline/srccheck/pyflakes.py
===================================================================
--- refline.srccheck/src/refline/srccheck/pyflakes.py	                        (rev 0)
+++ refline.srccheck/src/refline/srccheck/pyflakes.py	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1,98 @@
+
+# this is a !!MODIFIED!!! version of the original pyflakes script
+# this one returns the warnings instead of printing them to stdout
+
+"""
+Implementation of the command-line I{pyflakes} tool.
+"""
+
+import compiler, sys
+import os
+
+checker = __import__('pyflakes.checker').checker
+
+def check(codeString, filename):
+    """
+    Check the Python source given by C{codeString} for flakes.
+
+    @param codeString: The Python source to check.
+    @type codeString: C{str}
+
+    @param filename: The name of the file the source came from, used to report
+        errors.
+    @type filename: C{str}
+
+    @return: List of warnings emitted.
+    """
+    # Since compiler.parse does not reliably report syntax errors, use the
+    # built in compiler first to detect those.
+    try:
+        try:
+            compile(codeString, filename, "exec")
+        except MemoryError:
+            # Python 2.4 will raise MemoryError if the source can't be
+            # decoded.
+            if sys.version_info[:2] == (2, 4):
+                raise SyntaxError(None)
+            raise
+    except (SyntaxError, IndentationError), value:
+        msg = value.args[0]
+
+        (lineno, offset, text) = value.lineno, value.offset, value.text
+
+        # If there's an encoding problem with the file, the text is None.
+        if text is None:
+            # Avoid using msg, since for the only known case, it contains a
+            # bogus message that claims the encoding the file declared was
+            # unknown.
+            return  ["%s: problem decoding source" % (filename, )]
+        else:
+            line = text.splitlines()[-1]
+
+            if offset is not None:
+                offset = offset - (len(text) - len(line))
+
+            result = '%s:%d: %s\n%s' % (filename, lineno, msg, line)
+
+            if offset is not None:
+                result += '\n'+" " * offset+"^"
+
+        return [result]
+    else:
+        # Okay, it's syntactically valid.  Now parse it into an ast and check
+        # it.
+        tree = compiler.parse(codeString)
+        w = checker.Checker(tree, filename)
+        w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
+        return w.messages
+
+
+def checkPath(filename):
+    """
+    Check the given path, printing out any warnings detected.
+
+    @return: the number of warnings printed
+    """
+    try:
+        return check(file(filename, 'U').read() + '\n', filename)
+    except IOError, msg:
+        print >> sys.stderr, "%s: %s" % (filename, msg.args[1])
+        return 1
+
+
+def main():
+    warnings = 0
+    args = sys.argv[1:]
+    if args:
+        for arg in args:
+            if os.path.isdir(arg):
+                for dirpath, dirnames, filenames in os.walk(arg):
+                    for filename in filenames:
+                        if filename.endswith('.py'):
+                            warnings += checkPath(os.path.join(dirpath, filename))
+            else:
+                warnings += checkPath(arg)
+    else:
+        warnings += check(sys.stdin.read(), '<stdin>')
+
+    raise SystemExit(warnings > 0)


Property changes on: refline.srccheck/src/refline/srccheck/pyflakes.py
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native

Added: refline.srccheck/src/refline/srccheck/testing/__init__.py
===================================================================
--- refline.srccheck/src/refline/srccheck/testing/__init__.py	                        (rev 0)
+++ refline.srccheck/src/refline/srccheck/testing/__init__.py	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1 @@
+#
\ No newline at end of file


Property changes on: refline.srccheck/src/refline/srccheck/testing/__init__.py
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native

Added: refline.srccheck/src/refline/srccheck/testing/bad.py
===================================================================
--- refline.srccheck/src/refline/srccheck/testing/bad.py	                        (rev 0)
+++ refline.srccheck/src/refline/srccheck/testing/bad.py	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1,9 @@
+# this is a file full with problems
+
+import os
+
+def doit():
+    foo = bar
+
+def with_tab():
+	print "there's a tab"
\ No newline at end of file


Property changes on: refline.srccheck/src/refline/srccheck/testing/bad.py
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native

Added: refline.srccheck/src/refline/srccheck/tests.py
===================================================================
--- refline.srccheck/src/refline/srccheck/tests.py	                        (rev 0)
+++ refline.srccheck/src/refline/srccheck/tests.py	2012-04-02 14:17:23 UTC (rev 124883)
@@ -0,0 +1,27 @@
+##############################################################################
+#
+# Copyright (c) Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+import unittest
+import doctest
+
+
+def test_suite():
+    return unittest.TestSuite((
+        doctest.DocFileSuite('README.txt',
+            optionflags=doctest.NORMALIZE_WHITESPACE + doctest.ELLIPSIS,
+            ),
+        ))


Property changes on: refline.srccheck/src/refline/srccheck/tests.py
___________________________________________________________________
Added: svn:keywords
   + Date Author Id Revision
Added: svn:eol-style
   + native



More information about the checkins mailing list