--
Rakesh Pandit
https://fedoraproject.org/
freedom, friends, features, first
From: Rakesh Pandit
rakesh@fedoraproject.org
Date: Tue, 24 Nov 2009 10:52:07 +0000 (+0530)
Subject: ExcessDocFileCheck.py: New file.
X-Git-Url:
http://git.fedorahosted.org/git/gach.git/?p=gach.git;a=commitdiff_plain;h=41...
ExcessDocFileCheck.py: New file.
GachApplication.py, GachRPMReviewer.py, GachReviewer.py,
GachUtils.py: Adjusted accordingly.
---
diff --git a/ExcessDocFileCheck.py b/ExcessDocFileCheck.py
new file mode 100644
index 0000000..2b1146d
--- /dev/null
+++ b/ExcessDocFileCheck.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+#
+# Copyright 2009 Rakesh Pandit
rakesh@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 for warning about files in /usr/share/doc more then 1024KB or
+# 100 files and would be nice to go for a separate subpackage.
+#
+
+import os
+
+import RPMCheck
+from GachUtils import extract_rpm, rm_rf, get_folder_size
+from GachReporter import GachReporter
+
+reporter = GachReporter()
+
+class ExcessDocFileCheck(RPMCheck.RPMCheck):
+ """Check whether Doc files are in excess
+ """
+
+ def __init__(self):
+ """
+ """
+ RPMCheck.RPMCheck.__init__(self, "ExcessDocFileCheck")
+
+ def check(self, **details):
+ """
+ """
+ rpm_file = details["rpm"]
+ extract_outdir = extract_rpm(rpm_file)
+ docdir = extract_outdir + "/usr/share/doc/"
+ if os.path.exists(docdir):
+ folder_size = get_folder_size(docdir)
+ # If size greater then 1024K and 100 files
+ if int(folder_size) >= 1024:
+ reporter.printWarning("excess-doc-files-in-docdir",
Size=folder_size, File=rpm_file)
+
+ files = []
+ for dir, subdir, fl in os.walk(docdir):
+ files.append(fl)
+ # Check whether number of files >= 100
+ lg = len(files)
+ if lg >= 100:
+ reporter.printWarning("excess-doc-files-in-docdir",
Numberoffiles=lg, File=rpm_file)
+
+ rm_rf(extract_outdir)
+ return
+
+check = ExcessDocFileCheck()
+
+reporter.addDetails(
+'excess-doc-files-in-docdir',
+'''Doc files in /usr/share/doc more then 1024KB or file count >= 100.'''
+)
diff --git a/GachApplication.py b/GachApplication.py
index fd5459d..a9ea5aa 100644
--- a/GachApplication.py
+++ b/GachApplication.py
@@ -131,10 +131,11 @@ class GachApplication:
# Need to check later why this is needed
print reporter.getReport()
- # Load all src rpm checks checks
reviewer = GachReviewer()
srpmreviewer = GachSrcRPMReviewer()
+ rpmreviewer = GachRPMReviewer()
+ # Load all src rpm checks checks
for file in downloaded_files:
if file.endswith("src.rpm"):
srpmreviewer.review(file)
@@ -143,6 +144,11 @@ class GachApplication:
for file in downloaded_files:
if file.endswith("build.log"):
reviewer.review(log=file)
+ reporter.printDividerInfo("Log check ends")
+
+ # Load all rpm checks
+ for file in downloaded_files:
+ if file.endswith(".rpm") and not file.endswith("src.rpm"):
print reporter.getReport()
rm_rf(srpm_spec_downdir)
diff --git a/GachRPMReviewer.py b/GachRPMReviewer.py
index 7a820cb..b41ead4 100644
--- a/GachRPMReviewer.py
+++ b/GachRPMReviewer.py
@@ -28,14 +28,16 @@ class GachRPMReviewer(GachReviewer.GachReviewer):
def __init__(self):
"""
"""
- pass
+ # All Checks are loaded here.
+ self.default_guidelines = ("ExcessDocFileCheck",)
+ GachReviewer.GachReviewer.__init__(self,
guidelines=self.default_guidelines)
def review(self, rpm):
"""
Implements reviewer for rpm.
"""
- for guide in RPMCheck.RPMCheck.checks:
- guide.check(rpm)
+ for guide in RPMCheck.RPMCheck.rpm_checks:
+ guide.check(rpm=rpm)
return
diff --git a/GachReviewer.py b/GachReviewer.py
index f6beaca..3c7fd98 100644
--- a/GachReviewer.py
+++ b/GachReviewer.py
@@ -64,9 +64,9 @@ class GachReviewer(object):
"""
Implements the loading module.
"""
- print "Guidelines:", self.default_guidelines
+ # print "Guidelines:", self.default_guidelines
for name in self.default_guidelines:
- print "Loaded: ", name
+ # print "Loaded: ", name
file = None
path = None
description = None
diff --git a/GachUtils.py b/GachUtils.py
index b93dad8..b876081 100644
--- a/GachUtils.py
+++ b/GachUtils.py
@@ -21,6 +21,7 @@
#
import os
+import stat
import fnmatch
import glob
import sys
@@ -98,3 +99,20 @@ def istext(s):
t = s.translate(_null_trans, text_characters)
return float(len(t))/len(s) >= 0.30
+
+def get_folder_size(folder):
+ """Return folder size
+ """
+ folder_size = commands.getoutput("du -s " + folder)
+# FIXME: Current method does not ok, but below one even does not
+# work fine. Need to get it right.
+
+# folder_size = 0
+# for (path, dirs, files) in os.walk(folder):
+# for file in files:
+# filename = os.path.join(path, file)
+# if os.path.islink(filename) and not
os.path.exists(os.readlink(filename)):
+# continue
+# folder_size += os.stat(filename)[stat.ST_SIZE]
+ return folder_size.split("\t")[0]
+