Add --vagrant switch to the php style-checker

Added -V|--vagrant switch to the php style-checker
to run the checks in the Vagrant VM

refs #4264
This commit is contained in:
Johannes Meyer 2013-06-14 13:13:50 +02:00
parent 747d8b31e8
commit a7a8836b5b

View File

@ -3,6 +3,7 @@
import os import os
import sys import sys
import subprocess import subprocess
from pipes import quote
from optparse import OptionParser, BadOptionError, AmbiguousOptionError from optparse import OptionParser, BadOptionError, AmbiguousOptionError
@ -10,6 +11,7 @@ APPLICATION = 'phpcs'
DEFAULT_ARGS = ['-p', '--standard=PSR2', '--extensions=php', DEFAULT_ARGS = ['-p', '--standard=PSR2', '--extensions=php',
'--encoding=utf-8'] '--encoding=utf-8']
VAGRANT_SCRIPT = '/vagrant/test/php/checkswag'
REPORT_DIRECTORY = '../../build/log' REPORT_DIRECTORY = '../../build/log'
@ -70,39 +72,55 @@ def parse_commandline():
parser.add_option('-e', '--exclude', metavar='PATTERN', action='append', parser.add_option('-e', '--exclude', metavar='PATTERN', action='append',
help='Exclude specific files/test cases. ' help='Exclude specific files/test cases. '
'(Can be supplied multiple times.)') '(Can be supplied multiple times.)')
parser.add_option('-V', '--vagrant', action='store_true',
help='Run in vagrant VM')
return parser.parse_args() return parser.parse_args()
def main(): def main():
options, arguments = parse_commandline() options, arguments = parse_commandline()
# Environment preparation and verification if options.vagrant and os.environ['USER'] != 'vagrant':
os.chdir(get_script_directory()) # Check if vagrant is installed
application_path = execute_command('which {0}'.format(APPLICATION), vagrant_path = execute_command('which vagrant', True, True).strip()
True, True).strip() if not vagrant_path:
if not application_path: print 'ERROR: vagrant not found!'
print 'ERROR: {0} not found!'.format(APPLICATION) return 2
return 2
# Commandline preparation # Call the script in the Vagrant VM with the same parameters
command_options = [] commandline = ' '.join(quote(p) for p in sys.argv[1:])
if options.verbose: return execute_command('vagrant ssh -c "{0} {1}"'
command_options.append('-v') ''.format(VAGRANT_SCRIPT, commandline),
if options.build: shell=True)
command_options.append('--report-checkstyle=' + os.path.join(get_report_directory(), 'phpcs_results.xml'))
if options.exclude:
command_options.extend(['--ignore=' + ','.join(options.exclude)])
if options.include:
arguments.extend(options.include)
else: else:
arguments.extend(['../../application', '../../bin', # Environment preparation and verification
'../../library/Icinga']) os.chdir(get_script_directory())
application_path = execute_command('which {0}'.format(APPLICATION),
True, True).strip()
if not application_path:
print 'ERROR: {0} not found!'.format(APPLICATION)
return 2
# Application invocation.. # Commandline preparation
execute_command([application_path] + DEFAULT_ARGS + command_options = []
command_options + arguments) if options.verbose:
command_options.append('-v')
return 0 if options.build:
result_path = os.path.join(get_report_directory(),
'phpcs_results.xml')
command_options.append('--report-checkstyle=' + result_path)
if options.exclude:
command_options.append('--ignore=' + ','.join(options.exclude))
if options.include:
arguments.extend(options.include)
else:
arguments.extend(['../../application', '../../bin',
'../../library/Icinga'])
# Application invocation..
execute_command([application_path] + DEFAULT_ARGS +
command_options + arguments)
return 0
if __name__ == '__main__': if __name__ == '__main__':