Debian Codegraph @

extras/check_py24.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # QBrz - Qt frontend to Breezy commands
4 # Copyright (C) 2007 Lukáš Lalinský <[email protected]om>
5 # Copyright (C) 2007 Alexander Belchenko <[email protected]>
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21 """check_py24 command for setup.py.
22 It checks syntax of Python modules by compiling them with Python 2.4.
23 """
24
25 from distutils.core import Command
26 from distutils.errors import DistutilsPlatformError
27 from distutils import log
28 import os
29 import sys
30 import traceback
31
32
33 class check_py24(Command):
34
35 description = ("check syntax of python modules "
36 "by compiling them with Python 2.4")
37 user_options = []
38
39 def initialize_options(self):
40 pass
41
42 def finalize_options(self):
43 if sys.version_info[:2] != (2, 4):
44 raise DistutilsPlatformError(
45 'check_py24 command require Python 2.4')
46
47 def run(self):
48 for root, dirs, files in os.walk('.'):
49 for fname in sorted(files):
50 if fname.endswith('.py'):
51 fullname = os.path.join(root, fname)[2:] # first 2 characters is ./
52 # verbose: 0=quiet, 1=normal, 2=verbose
53 if self.verbose:
54 log.info('checking ' + fullname)
55 if not self.dry_run:
56 f = open(fullname, 'rU') # rU automatically converts CRLF to LF
57 content = f.read()
58 f.close()
59 try:
60 compile(content, fullname, 'exec')
61 except SyntaxError as e:
62 log.error(str(e))
63 if self.verbose:
64 traceback.print_exc(0)
65 # skip some directories
66 for dname in dirs[:]:
67 fullname = os.path.join(root, dname).replace('\\','/')
68 if fullname in ('./_lib', './build', './dist', './installer'):
69 dirs.remove(dname)