Pushed initial prototype check for following:
+# Check: Whether source contains binary files.
+# URL:
https://fedoraproject.org/wiki/Packaging/Guidelines#No_inclusion_of_pre-b...
--
Rakesh Pandit
https://fedoraproject.org/
freedom, friends, features, first
commit 37aafbe670cd4fec768b7982ce216bfa37e35873
Author: Rakesh Pandit <rakesh(a)fedoraproject.org>
Date: Tue Nov 17 14:16:47 2009 +0530
BinaryFilesCheck.py: New Check
diff --git a/BinaryFilesCheck.py b/BinaryFilesCheck.py
new file mode 100644
index 0000000..892b01d
--- /dev/null
+++ b/BinaryFilesCheck.py
@@ -0,0 +1,100 @@
+#!/usr/bin/env python
+#
+# Copyright 2009 Rakesh Pandit <rakesh(a)fedoraproject.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with translate; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+#
+# Check: Whether source contains binary files.
+# URL:
https://fedoraproject.org/wiki/Packaging/Guidelines#No_inclusion_of_pre-b...
+#
+
+import commands
+import tempfile
+import os
+import glob
+import stat
+
+import SrcRPMCheck
+from GachUtils import rm_rf, get_source_from_srpm, locate
+from GachReporter import GachReporter
+from GachUtils import istextfile
+
+reporter = GachReporter()
+
+# *.class, *.dll, *.DS_Store, *.exe, *.jar, *.o, *.pyc, *.pyo, *.so
+list_of_binary_extensions = ['*.class', '*.dll', '*.DS_Store',
'*.exe', '*.jar', '*.o', '*.pyc', '*.pyo',
'*.so']
+
+class BinaryFilesCheck(SrcRPMCheck.SrcRPMCheck):
+ """Binary files present in source files
+ """
+
+ def __init__(self):
+ """
+ """
+ SrcRPMCheck.SrcRPMCheck.__init__(self, "BinaryFilesCheck")
+
+ def check(self, **details):
+ """
+ """
+ srpm_file = details["srpm"]
+ srpm_extract_dir = tempfile.mkdtemp(prefix="gach")
+ build_dir = srpm_extract_dir + "/BUILD/"
+ get_source_from_srpm(srpm_file, srpm_extract_dir)
+
+ binary_files_with_extension = {}
+ for extension in list_of_binary_extensions:
+ matches = locate(extension, root=build_dir)
+ if matches:
+ binary_files_with_extension[extension] = matches
+
+ for extension in binary_files_with_extension:
+ for file in binary_files_with_extension[extension]:
+
reporter.printWarning("binary-extension-file-in-source", File=file)
+
+ binary_files_nontext_chars = []
+ empty_files = []
+ for dir, subdir, files in os.walk(build_dir):
+ for file in files:
+ fullpath = os.path.join(dir, file)
+ # Knock out empty files
+ if os.stat(fullpath)[stat.ST_SIZE] == 0:
+ empty_files.append(fullpath)
+ continue
+ if istextfile(fullpath):
+ binary_files_nontext_chars.append(fullpath)
+
+ if binary_files_nontext_chars:
+ for binary in binary_files_nontext_chars:
+
reporter.printWarning("binary-file-with-30%-plus-non-text-chars",
File=binary)
+
+ if empty_files:
+ for empty_file in empty_files:
+ reporter.printWarning("empty-file", File=empty_file)
+
+ rm_rf(srpm_extract_dir)
+ return
+
+check = BinaryFilesCheck()
+
+reporter.addDetails(
+'binary-extension-file-in-source',
+'''Files with *.class, *.dll, *.DS_Store, *.exe, *.jar, *.o, *.pyc,
*.pyo, *.so extensions are most probably binary files.''',
+'binary-file-with-30%-plus-non-text-chars',
+'''Binary file with 30% plus no text characters has been considered
as binary file''',
+'empty-file',
+'''Empty file'''
+)