Add --vagrant switch to the javascript style-checker
Added -V|--vagrant switch to the javascript style-checker to run the checks in the Vagrant VM refs #4264
This commit is contained in:
parent
d7ebe7fa08
commit
5e48999478
|
@ -3,6 +3,7 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from pipes import quote
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
from optparse import OptionParser, BadOptionError, AmbiguousOptionError
|
from optparse import OptionParser, BadOptionError, AmbiguousOptionError
|
||||||
|
|
||||||
|
@ -10,6 +11,7 @@ from optparse import OptionParser, BadOptionError, AmbiguousOptionError
|
||||||
APPLICATION = 'jshint'
|
APPLICATION = 'jshint'
|
||||||
DEFAULT_ARGS = []
|
DEFAULT_ARGS = []
|
||||||
|
|
||||||
|
VAGRANT_SCRIPT = '/vagrant/test/js/checkswag'
|
||||||
REPORT_DIRECTORY = '../../build/log'
|
REPORT_DIRECTORY = '../../build/log'
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,62 +72,80 @@ 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.build:
|
return execute_command('vagrant ssh -c "{0} {1}"'
|
||||||
command_options.extend(['--reporter', 'jslint'])
|
''.format(VAGRANT_SCRIPT, commandline),
|
||||||
|
shell=True)
|
||||||
else:
|
else:
|
||||||
command_options.append('--verbose')
|
# Environment preparation and verification
|
||||||
if options.verbose:
|
os.chdir(get_script_directory())
|
||||||
command_options.append('--show-non-errors')
|
application_path = execute_command('which {0}'.format(APPLICATION),
|
||||||
path_args = [arguments.remove(a) or a
|
True, True).strip()
|
||||||
for a in arguments[:len(arguments)]
|
if not application_path:
|
||||||
if os.path.isfile(a) or os.path.isdir(a)]
|
print 'ERROR: {0} not found!'.format(APPLICATION)
|
||||||
if not path_args:
|
return 2
|
||||||
path_args = ['../../application', '../../bin', '../../library/Icinga']
|
|
||||||
if options.include:
|
|
||||||
path_args = [os.path.join(r, f) for a in path_args
|
|
||||||
for r, _, fs in os.walk(a)
|
|
||||||
for f in fs
|
|
||||||
if any(fnmatch(os.path.join(r, f), p)
|
|
||||||
for p in options.include)]
|
|
||||||
if options.exclude:
|
|
||||||
walk = lambda p: os.walk(p) if os.path.isdir(p) else \
|
|
||||||
[(os.path.dirname(p), None, [os.path.basename(p)])]
|
|
||||||
path_args = [os.path.join(r, f)
|
|
||||||
for a in path_args
|
|
||||||
for r, _, fs in walk(a)
|
|
||||||
for f in fs
|
|
||||||
if not any(fnmatch(os.path.join(r, f), p)
|
|
||||||
for p in options.exclude)]
|
|
||||||
|
|
||||||
# Application invocation..
|
# Commandline preparation
|
||||||
if options.build:
|
command_options = []
|
||||||
result_data = execute_command([application_path] + DEFAULT_ARGS +
|
if options.build:
|
||||||
command_options + arguments +
|
command_options.extend(['--reporter', 'jslint'])
|
||||||
path_args, True)
|
else:
|
||||||
result_path = os.path.join(get_report_directory(),
|
command_options.append('--verbose')
|
||||||
'jshint_results.xml')
|
if options.verbose:
|
||||||
with open(result_path, 'w') as result_file:
|
command_options.append('--show-non-errors')
|
||||||
result_file.write(result_data)
|
path_args = [arguments.remove(a) or a
|
||||||
else:
|
for a in arguments[:len(arguments)]
|
||||||
execute_command([application_path] + DEFAULT_ARGS +
|
if os.path.isfile(a) or os.path.isdir(a)]
|
||||||
command_options + arguments + path_args)
|
if not path_args:
|
||||||
return 0
|
path_args = ['../../application', '../../bin',
|
||||||
|
'../../library/Icinga']
|
||||||
|
if options.include:
|
||||||
|
path_args = [os.path.join(r, f)
|
||||||
|
for a in path_args
|
||||||
|
for r, _, fs in os.walk(a)
|
||||||
|
for f in fs
|
||||||
|
if any(fnmatch(os.path.join(r, f), p)
|
||||||
|
for p in options.include)]
|
||||||
|
if options.exclude:
|
||||||
|
walk = lambda p: os.walk(p) if os.path.isdir(p) else \
|
||||||
|
[(os.path.dirname(p), None,
|
||||||
|
[os.path.basename(p)])]
|
||||||
|
path_args = [os.path.join(r, f)
|
||||||
|
for a in path_args
|
||||||
|
for r, _, fs in walk(a)
|
||||||
|
for f in fs
|
||||||
|
if not any(fnmatch(os.path.join(r, f), p)
|
||||||
|
for p in options.exclude)]
|
||||||
|
|
||||||
|
# Application invocation..
|
||||||
|
if options.build:
|
||||||
|
result_data = execute_command([application_path] + DEFAULT_ARGS +
|
||||||
|
command_options + arguments +
|
||||||
|
path_args, True)
|
||||||
|
result_path = os.path.join(get_report_directory(),
|
||||||
|
'jshint_results.xml')
|
||||||
|
with open(result_path, 'w') as result_file:
|
||||||
|
result_file.write(result_data)
|
||||||
|
else:
|
||||||
|
execute_command([application_path] + DEFAULT_ARGS +
|
||||||
|
command_options + arguments + path_args)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue