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
|
import os
import sys
from optparse import make_option
import random
import subprocess
from jhbuild.commands import Command, register_command
scripts_dir = os.path.dirname(__file__)
data_dir = os.path.join(scripts_dir, 'data')
pylintrc_path = os.path.join(data_dir, 'pylintrc')
class cmd_check(Command):
name = 'check'
usage_args = ''
def __init__(self):
Command.__init__(self, [
make_option('-x', '--xvfb-port', action='store',
dest='xvfb_port', default=None,
help='specify the port of the xvfb server'),
make_option('-t', '--type', action='store',
dest='type', default=None,
help='specify the check type')
])
def start_xvfb(self, port):
if port is None:
port = ':%d' % random.randrange(1000, 50000)
try:
subprocess.Popen(['Xvfb', '-ac', port],
stdout=open(os.devnull, "w"),
stderr=subprocess.STDOUT)
os.environ['DISPLAY'] = port
except OSError:
print 'Cannot execute xfvb, will use the default display.'
def run_pylint(self, args):
p = subprocess.Popen([ 'pylint' ] + args)
p.wait()
return False
def lint(self, module):
self.run_pylint([module, '--rcfile=%s' % pylintrc_path])
def lint_path(self, path):
cwd = os.getcwd()
os.chdir(path)
python_files = []
for (path, dirs, files) in os.walk('.'):
for f in files:
if f.endswith('.py'):
python_files.append(os.path.join(path, f))
args = ['--rcfile=%s' % pylintrc_path] + python_files
self.run_pylint(args)
os.chdir(cwd)
def check_pylint(self, config):
sugar_path = os.path.join(config.prefix, 'share', 'sugar')
self.lint_path(os.path.join(sugar_path, 'shell'))
self.lint_path(os.path.join(sugar_path, 'service'))
self.lint('sugar')
def run(self, config, options, args):
self.start_xvfb(options.xvfb_port)
if options.type == 'pylint':
self.check_pylint(config)
else:
return False
register_command(cmd_check)
|