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
1 changed files with 42 additions and 24 deletions

View File

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