pre-upload: Allow --include_regex and --exclude_regex in check_cros_license

This will support files in a specific repository that are copied from an
external source and so do not contain the default ChromeOS license and
copyright. One example is checkpatch.pl in this repohooks repository,
which comes from the kernel tree and contains that copyright format.

BUG=None
TEST=Passes pre-upload_unittest.py, tested with an extra exclude.

Change-Id: Ic0decf09718ef4c407f983bfef36cf87ac8abea4
Signed-off-by: Filipe Brandenburger <filbranden@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/305030
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index 011457f..74ae0fa 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -10,6 +10,7 @@
 
 from __future__ import print_function
 
+import argparse
 import collections
 import ConfigParser
 import fnmatch
@@ -920,7 +921,7 @@
                        MAX_FIRST_LINE_LEN)
 
 
-def _check_cros_license(_project, commit):
+def _check_cros_license(_project, commit, options=()):
   """Verifies the Chromium OS license/copyright header.
 
   Should be following the spec:
@@ -944,11 +945,18 @@
   )
   copyright_re = re.compile(COPYRIGHT_LINE)
 
+  parser = argparse.ArgumentParser()
+  parser.add_argument('--exclude_regex', action='append')
+  parser.add_argument('--include_regex', action='append')
+  opts = parser.parse_args(options)
+  included = opts.include_regex or []
+  excluded = opts.exclude_regex or []
+
   bad_files = []
   bad_copyright_files = []
   files = _filter_files(_get_affected_files(commit, relative=True),
-                        COMMON_INCLUDED_PATHS,
-                        COMMON_EXCLUDED_PATHS)
+                        included + COMMON_INCLUDED_PATHS,
+                        excluded + COMMON_EXCLUDED_PATHS)
 
   for f in files:
     contents = _get_file_content(f, commit)