[FIX] website_mail_group: restore missing snippet icon
[odoo/odoo.git] / openerpcommand / grunt_tests.py
1 """
2 Search for Gruntfile.js files in all the addons and launch them using the 'grunt test' command.
3 """
4
5 import common
6 import fnmatch
7 import os
8 import re
9 import sys
10 import subprocess
11
12 def grunt_tester(directories, log = sys.stdout):
13     result = 0
14
15     matches = []
16     for direc in directories:
17         for root, dirnames, filenames in os.walk(direc):
18             for filename in fnmatch.filter(filenames, 'Gruntfile.js'):
19                 full = os.path.join(root, filename)
20                 if re.match(r"(^.*?/node_modules/.*$)|(^.*?/lib/.*$)", full):
21                     continue
22                 matches.append(full)
23
24     for file_ in matches:
25         folder = os.path.dirname(file_)
26         p = subprocess.Popen(['npm', 'install'], cwd=folder)
27         if p.wait() != 0:
28             raise Exception("Failed to install dependencies for Gruntfile located in folder %s" % folder)
29
30         p = subprocess.Popen(['grunt', 'test', '--no-color'], cwd=folder, stdout=log, stderr=log)
31         if p.wait() != 0:
32             result = 1
33
34     return result
35
36 def run(args):
37     if args.addons:
38         args.addons = args.addons.split(':')
39     else:
40         args.addons = []
41     result = grunt_tester(args.addons)
42     if result != 0:
43         sys.exit(result)
44
45 def add_parser(subparsers):
46     parser = subparsers.add_parser('grunt-tests',
47         description='Run the tests contained in Gruntfile.js files.')
48     common.add_addons_argument(parser)
49
50     parser.set_defaults(run=run)