from imhotep.tools import Tool
from collections import defaultdict
import re


class JSL(Tool):
    regex = re.compile(
        r'^(?P<type>[WE]) '
        r'(?P<filename>.*?) L(?P<line_number>\d+): (?P<message>.*)$')

    def invoke(self, dirname, filenames=set()):
        retval = defaultdict(lambda: defaultdict(list))

        cmd = 'find %s -name "*.js" | xargs jsl' % dirname
        output = self.executor(cmd)
        for line in output.split('\n'):
            match = self.regex.search(line)
            if match is None:
                continue
            message = '%s: %s' % (match.group('type'), match.group('message'))
            filename = match.group('filename')[len(dirname) + 1:]
            retval[filename][match.group('line_number')].append(message)
        return retval

@@ -316,25 +316,59 @@
 (list))%0A
-%0A
+        if len(filenames) == 0:%0A   
         
 cmd = 'f
@@ -359,16 +359,17 @@
         
+ 
 cmd = 'f
@@ -411,16 +411,248 @@
 dirname%0A
+        else:%0A            js_files = %5B%5D%0A            for filename in filenames:%0A                if '.js' in filename:%0A                    js_files.append(%22%25s/%25s%22 %25 (dirname, filename))%0A            cmd = 'jsl %25s' %25 ' '.join(js_files)%0A
         

Add support for imhotep to pass a list of filenames.