handle %license
authorAnas Nashif <anas.nashif@intel.com>
Fri, 10 May 2013 20:25:54 +0000 (16:25 -0400)
committerAnas Nashif <anas.nashif@intel.com>
Wed, 29 May 2013 08:41:52 +0000 (04:41 -0400)
DocFilesCheck.py
Pkg.py

index 4463579..f668aed 100644 (file)
@@ -71,6 +71,12 @@ class DocFilesCheck(AbstractCheck.AbstractCheck):
             if docfile.endswith("/INSTALL"):
                 printWarning(pkg, "install-file-in-docs", docfile)
 
+    def __checkLicenseFiles(self, pkg):
+
+        for docfile in pkg.docFiles():
+            if docfile.endswith("/COPYING") or docfile.endswith("/LICENSE"):
+                printWarning(pkg, "license-file-in-docs", docfile)
+
     def check(self, pkg):
 
         if pkg.isSource() or not pkg.docFiles():
@@ -78,6 +84,7 @@ class DocFilesCheck(AbstractCheck.AbstractCheck):
 
         self.__checkRequirements(pkg)
         self.__checkUnwantedFiles(pkg)
+        self.__checkLicenseFiles(pkg)
 
 
 check = DocFilesCheck()
@@ -94,6 +101,11 @@ included in the package.  Such instructions are often not relevant for already
 installed packages; if this is the case for this file and it does not contain
 any information that is of interest after the package has been built and
 installed, do not include the file in the binary package.''',
+'license-file-in-docs',
+'''A file whose name suggests that it contains a license is
+included in the package as a document. Such files need to be marked with %license
+and not with %doc, which will install them in a special directory seperated
+from the documentation.''',
 )
 
 # DocFilesCheck.py ends here
diff --git a/Pkg.py b/Pkg.py
index 7f09990..226eae6 100644 (file)
--- a/Pkg.py
+++ b/Pkg.py
@@ -421,6 +421,7 @@ class Pkg:
         self.current_linenum = None
         self._config_files = None
         self._doc_files = None
+        self._license_files = None
         self._noreplace_files = None
         self._ghost_files = None
         self._missingok_files = None
@@ -572,6 +573,14 @@ class Pkg:
         self._doc_files = [x.name for x in self.files().values() if x.is_doc]
         return self._doc_files
 
+    # return the list of license files
+    def licenseFiles(self):
+        if self._license_files is not None:
+            return self._license_files
+
+        self._license_files = [x.name for x in self.files().values() if x.is_license]
+        return self._license_files
+
     # return the list of ghost files
     def ghostFiles(self):
         if self._ghost_files is not None:
@@ -894,6 +903,7 @@ class PkgFile(object):
 
     is_config    = property(lambda self: self.flags & rpm.RPMFILE_CONFIG)
     is_doc       = property(lambda self: self.flags & rpm.RPMFILE_DOC)
+    is_license   = property(lambda self: self.flags & rpm.RPMFILE_LICENSE)
     is_noreplace = property(lambda self: self.flags & rpm.RPMFILE_NOREPLACE)
     is_ghost     = property(lambda self: self.flags & rpm.RPMFILE_GHOST)
     is_missingok = property(lambda self: self.flags & rpm.RPMFILE_MISSINGOK)