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,12 +72,27 @@ 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()
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# 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:
|
||||||
# Environment preparation and verification
|
# Environment preparation and verification
|
||||||
os.chdir(get_script_directory())
|
os.chdir(get_script_directory())
|
||||||
application_path = execute_command('which {0}'.format(APPLICATION),
|
application_path = execute_command('which {0}'.format(APPLICATION),
|
||||||
|
@ -96,16 +113,19 @@ def main():
|
||||||
for a in arguments[:len(arguments)]
|
for a in arguments[:len(arguments)]
|
||||||
if os.path.isfile(a) or os.path.isdir(a)]
|
if os.path.isfile(a) or os.path.isdir(a)]
|
||||||
if not path_args:
|
if not path_args:
|
||||||
path_args = ['../../application', '../../bin', '../../library/Icinga']
|
path_args = ['../../application', '../../bin',
|
||||||
|
'../../library/Icinga']
|
||||||
if options.include:
|
if options.include:
|
||||||
path_args = [os.path.join(r, f) for a in path_args
|
path_args = [os.path.join(r, f)
|
||||||
|
for a in path_args
|
||||||
for r, _, fs in os.walk(a)
|
for r, _, fs in os.walk(a)
|
||||||
for f in fs
|
for f in fs
|
||||||
if any(fnmatch(os.path.join(r, f), p)
|
if any(fnmatch(os.path.join(r, f), p)
|
||||||
for p in options.include)]
|
for p in options.include)]
|
||||||
if options.exclude:
|
if options.exclude:
|
||||||
walk = lambda p: os.walk(p) if os.path.isdir(p) else \
|
walk = lambda p: os.walk(p) if os.path.isdir(p) else \
|
||||||
[(os.path.dirname(p), None, [os.path.basename(p)])]
|
[(os.path.dirname(p), None,
|
||||||
|
[os.path.basename(p)])]
|
||||||
path_args = [os.path.join(r, f)
|
path_args = [os.path.join(r, f)
|
||||||
for a in path_args
|
for a in path_args
|
||||||
for r, _, fs in walk(a)
|
for r, _, fs in walk(a)
|
||||||
|
|
Loading…
Reference in New Issue