/usr/share/pyshared/DjangoLint/script.py is in python-django-lint 0.13-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# django-lint -- Static analysis tool for Django projects and applications
# Copyright (C) 2008-2009 Chris Lamb <chris@chris-lamb.co.uk>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
from pylint import checkers, lint
from optparse import OptionParser
from DjangoLint import AstCheckers
def main():
usage = """ %prog [options] target
Django Lint is a tool that statically analyses Django projects and
applications, checking for programming errors and bad code smells. For
example, it reports nullable "CharField" fields, as well as reporting for
unspecified options in settings.py.
The `target` argument is mandatory and can specify either a directory
containing a Django project, a single application or a single file.
""".rstrip()
parser = OptionParser(usage=usage)
parser.add_option(
'-r',
'--reports',
dest='report',
action='store_true',
default=False,
help='generate report',
)
parser.add_option(
'-p',
'--pylint',
dest='pylint',
action='store_true',
default=False,
help='run normal PyLint checks',
)
parser.add_option(
'-e',
'--errors',
dest='errors',
action='store_true',
default=False,
help='only show errors',
)
options, args = parser.parse_args()
try:
target = args[0]
except IndexError:
target = '.'
target = os.path.abspath(target)
if not os.path.exists(target):
raise parser.error(
"The specified target (%r) does not exist" \
% target
)
path = target
while True:
flag = False
for django_file in ('manage.py', 'models.py', 'urls.py'):
if os.path.exists(os.path.join(path, django_file)):
sys.path.insert(0, os.path.dirname(path))
flag = True
break
if flag:
break
path = os.path.dirname(path)
if path == '/':
raise parser.error(
"The specified target (%r) does not appear to be part of a " \
"Django application" % target
)
try:
import django
except ImportError:
print >>sys.stderr, "E: Cannot import `django' module, exiting.."
return 1
linter = lint.PyLinter()
linter.set_option('reports', options.report)
if options.errors:
linter.set_option('disable-msg-cat', 'WCRI')
linter.set_option('reports', False)
linter.set_option('persistent', False)
if options.pylint:
checkers.initialize(linter)
for msg in ('C0111', 'C0301'):
linter.disable_message(msg)
AstCheckers.register(linter)
linter.check([target])
return linter.msg_status
|