Enter sha256 binary sum in report files
[releng-anteater.git] / anteater / src / patch_scan.py
index 0bc4e72..3097d00 100644 (file)
@@ -47,7 +47,10 @@ def prepare_patchset(project, patchset):
     file_audit_list, file_audit_project_list = lists.file_audit_list(project)
 
     # Get file content black list and project waivers
-    master_list, project_list_re = lists.file_content_list(project)
+    master_list, ignore_list = lists.file_content_list(project)
+
+    # Get File Ignore Lists
+    file_ignore = lists.file_ignore()
 
     # Get Licence Lists
     licence_ext = lists.licence_extensions()
@@ -66,8 +69,8 @@ def prepare_patchset(project, patchset):
         # Perform binary and file / content checks
         scan_patch(project, patch_file, binary_list,
                    file_audit_list, file_audit_project_list,
-                   master_list, project_list_re, licence_ext,
-                   licence_ignore)
+                   master_list, ignore_list, licence_ext,
+                   file_ignore, licence_ignore)
 
     # Process each file in patch set using waivers generated above
     # Process final result
@@ -76,7 +79,7 @@ def prepare_patchset(project, patchset):
 
 def scan_patch(project, patch_file, binary_list, file_audit_list,
                file_audit_project_list, master_list,
-               project_list_re, licence_ext, licence_ignore):
+               ignore_list, licence_ext, file_ignore, licence_ignore):
     """ Scan actions for each commited file in patch set """
     global failure
     if is_binary(patch_file):
@@ -99,6 +102,9 @@ def scan_patch(project, patch_file, binary_list, file_audit_list,
                     as gate_report:
                 gate_report.write('Non Whitelisted Binary file: {0}\n'.
                                   format(patch_file))
+                gate_report.write('Submit patch with the following hash: {0}\n'.
+                                  format(hasher.hexdigest()))
+
     else:
         # Check file names / extensions
         if file_audit_list.search(patch_file) and not \
@@ -118,32 +124,34 @@ def scan_patch(project, patch_file, binary_list, file_audit_list,
         try:
             fo = open(patch_file, 'r')
             lines = fo.readlines()
+            file_exists = True
         except IOError:
-            logger.error('%s does not exist', patch_file)
-            sys.exit(1)
-
-        for line in lines:
-            for key, value in master_list.iteritems():
-                regex = value['regex']
-                desc = value['desc']
-                if re.search(regex, line) and not re.search(project_list_re, line):
-                    logger.error('File contains violation: %s', patch_file)
-                    logger.error('Flagged Content: %s', line.rstrip())
-                    logger.error('Matched Regular Exp: %s', regex)
-                    logger.error('Rationale: %s', desc.rstrip())
-                    failure = True
-                with open(reports_dir + "contents_" + project + ".log",
-                          "a") as gate_report:
-                    gate_report.write('File contains violation: {0}\n'.
-                                      format(patch_file))
-                    gate_report.write('Flagged Content: {0}'.
-                                      format(line))
-                    gate_report.write('Matched Regular Exp: {0}'.
-                                      format(regex))
-                    gate_report.write('Rationale: {0}'.
-                                      format(desc.rstrip()))
-        # Run license check
-        licence_check(project, licence_ext, licence_ignore, patch_file)
+            file_exists = False
+
+        if file_exists and not patch_file.endswith(tuple(file_ignore)):
+            for line in lines:
+                for key, value in master_list.iteritems():
+                    regex = value['regex']
+                    desc = value['desc']
+                    if re.search(regex, line) and not re.search(
+                            ignore_list, line):
+                        logger.error('File contains violation: %s', patch_file)
+                        logger.error('Flagged Content: %s', line.rstrip())
+                        logger.error('Matched Regular Exp: %s', regex)
+                        logger.error('Rationale: %s', desc.rstrip())
+                        failure = True
+                        with open(reports_dir + "contents_" + project + ".log",
+                                  "a") as gate_report:
+                            gate_report.write('File contains violation: {0}\n'.
+                                              format(patch_file))
+                            gate_report.write('Flagged Content: {0}'.
+                                              format(line))
+                            gate_report.write('Matched Regular Exp: {0}\n'.
+                                              format(regex))
+                            gate_report.write('Rationale: {0}\n'.
+                                              format(desc.rstrip()))
+            # Run license check
+            licence_check(project, licence_ext, licence_ignore, patch_file)
 
 
 def licence_check(project, licence_ext,