/usr/share/pyshared/pychecker2/main.py is in pychecker 0.8.19-12.
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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | import sys
from os.path import dirname, realpath
import os
def userPath(dirname=''):
"""'safer' function to find user path."""
# 'safer' function to find user path: look for one of these directories
try:
path = os.path.expanduser("~")
if os.path.isdir(path):
return os.path.join(path, dirname)
except:
pass
for evar in ('HOME', 'USERPROFILE', 'TMP'):
try:
path = os.environ[evar]
if os.path.isdir(path):
return os.path.join(path, dirname)
except:
pass
#if no match found, use module directory
return os.path.join(os.path.dirname(os.path.abspath(__file__)), dirname)
CACHE_FILE = userPath(".pychecker_cache")
sys.path.append(dirname(dirname(realpath(sys.argv[0]))))
from pychecker2.Check import CheckList
from pychecker2 import Options
from pychecker2 import ParseChecks
from pychecker2 import OpChecks
from pychecker2 import VariableChecks
from pychecker2 import ScopeChecks
from pychecker2 import ImportChecks
from pychecker2 import ClassChecks
from pychecker2 import ReachableChecks
from pychecker2 import ReturnChecks
from pychecker2 import ConditionalChecks
from pychecker2 import FormatStringChecks
def print_warnings(f, out):
if not f.warnings:
return 0
f.warnings.sort()
last_line = -1
last_msg = None
for line, warning, args in f.warnings:
if warning.value:
msg = warning.message % args
if msg != last_msg or line != last_line:
print >>out, \
'%s:%s %s' % (f.name, line or '[unknown line]', msg)
last_msg, last_line = msg, line
if last_msg:
print >>out
return 1
def create_checklist(options):
checks = [ ParseChecks.ParseCheck(),
OpChecks.OpCheck(),
OpChecks.ExceptCheck(),
OpChecks.CompareCheck(),
ReachableChecks.ReachableCheck(),
ConditionalChecks.ConstantCheck(),
ClassChecks.ReprCheck(),
ImportChecks.ImportCheck(),
FormatStringChecks.FormatStringCheck(),
VariableChecks.ShadowCheck(),
VariableChecks.UnpackCheck(),
VariableChecks.UnusedCheck(),
VariableChecks.UnknownCheck(),
VariableChecks.SelfCheck(),
VariableChecks.UsedBeforeSetCheck(),
ReturnChecks.MixedReturnCheck(),
ClassChecks.AttributeCheck(),
ClassChecks.SpecialCheck(),
ClassChecks.InitCheck(),
ScopeChecks.RedefineCheck(),
]
for checker in checks:
checker.get_warnings(options)
checker.get_options(options)
return CheckList(checks)
def main():
import cPickle
options = Options.Options()
try:
checker = cPickle.load(open(CACHE_FILE, 'rb'))
except (EOFError, IOError, ImportError):
checker = create_checklist(options)
try:
files = options.process_options(sys.argv[1:])
except Options.Error, detail:
print >> sys.stderr, "Error: %s" % detail
options.usage(sys.argv[0], sys.stderr)
return 1
# Properly load local modules relative to the file which is being checked
sys_path = sys.path[:]
for f in files:
f_dir = dirname(f.name)
sys.path= sys_path[:]
if f_dir not in sys.path:
sys.path.insert(0,f_dir)
checker.check_file(f)
if options.incremental and not options.profile:
print_warnings(f, sys.stdout)
sys.path = sys_path
result = 0
if not options.incremental and not options.profile:
files.sort()
for f in files:
result |= print_warnings(f, sys.stdout)
if not result and options.verbose:
print >>sys.stdout, None
fp = open(CACHE_FILE, 'wb')
cPickle.dump(checker, fp, 1)
fp.close()
return result
if __name__ == "__main__":
if '--profile' in sys.argv:
print 'profiling'
import hotshot.stats
import time
hs = hotshot.Profile('logfile.dat')
now = time.time()
hs.run('main()')
print 'total run time', time.time() - now
hs.close()
stats = hotshot.stats.load('logfile.dat')
stats.sort_stats('time', 'cum').print_stats(50)
else:
sys.exit(main())
|