[elbe-devel] [PATCH 4/8] efilesystem: add pkglist parameter to ElbeFilesystem.write_licenses()

Torben Hohn torben.hohn at linutronix.de
Mon Oct 14 16:57:30 CEST 2019


iterating over /usr/share/doc/* and expecting a copyright file there
produces an error for /usr/share/doc/xorg

This directory is contained in xserver-xorg, which has its copyright
file under /usr/share/doc/xserver-xorg/copyright.

Make write_licenses() accept a pkglist as argument, and change both
users to provide this list.

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/commands/genlicence.py |  5 ++++-
 elbepack/efilesystem.py         | 16 +++++++++-------
 elbepack/elbeproject.py         |  5 ++++-
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/elbepack/commands/genlicence.py b/elbepack/commands/genlicence.py
index 7f9f71ac4..410958fe3 100644
--- a/elbepack/commands/genlicence.py
+++ b/elbepack/commands/genlicence.py
@@ -51,5 +51,8 @@ def run_command(argv):
         else:
             f = io.open('licence.txt', "w+", encoding='utf-8')
 
-        project.buildenv.rfs.write_licenses(f, opt.xml)
+        pkglist = project.get_rpcaptcache().get_installed_pkgs()
+        pkgnames = [p.name for p in pkglist]
+
+        project.buildenv.rfs.write_licenses(f, pkgnames, opt.xml)
         f.close()
diff --git a/elbepack/efilesystem.py b/elbepack/efilesystem.py
index 162e3947f..9b17aa6e5 100644
--- a/elbepack/efilesystem.py
+++ b/elbepack/efilesystem.py
@@ -139,22 +139,24 @@ class ElbeFilesystem(Filesystem):
         xml.xml.write(elbe_base)
         self.chmod("etc/elbe_base.xml", stat.S_IREAD)
 
-    def write_licenses(self, f, xml_fname=None):
+    def write_licenses(self, f, pkglist, xml_fname=None):
         licence_xml = copyright_xml()
-        for d in self.listdir("usr/share/doc/", skiplinks=True):
+        for pkg in pkglist:
+            copyright_file = os.path.join('/usr/share/doc', pkg, 'copyright')
+            copyright_fname = self.fname(copyright_file)
             try:
-                with io.open(os.path.join(d, "copyright"), "rb") as lic:
+                with io.open(copyright_fname, "rb") as lic:
                     lic_text = lic.read()
             except IOError as e:
                 logging.exception("Error while processing license file %s",
-                                  os.path.join(d, "copyright"))
+                                  copyright_fname)
                 lic_text = "Error while processing license file %s: '%s'" % (
-                    os.path.join(d, "copyright"), e.strerror)
+                    copyright_file, e.strerror)
 
             lic_text = unicode(lic_text, encoding='utf-8', errors='replace')
 
             if f is not None:
-                f.write(unicode(os.path.basename(d)))
+                f.write(unicode(pkg))
                 f.write(u":\n======================================"
                         "==========================================")
                 f.write(u"\n")
@@ -162,7 +164,7 @@ class ElbeFilesystem(Filesystem):
                 f.write(u"\n\n")
 
             if xml_fname is not None:
-                licence_xml.add_copyright_file(os.path.basename(d), lic_text)
+                licence_xml.add_copyright_file(pkg, lic_text)
 
         if xml_fname is not None:
             licence_xml.write(xml_fname)
diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index 8be6c1dbc..b512de2b5 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -575,11 +575,14 @@ class ElbeProject (object):
         lic_txt_fname = os.path.join(self.builddir, "licence.txt")
         lic_xml_fname = os.path.join(self.builddir, "licence.xml")
 
+        pkglist = self.get_rpcaptcache().get_installed_pkgs()
+        pkgnames = [p.name for p in pkglist]
+
         with io.open(lic_txt_fname,
                      'w+',
                      encoding='utf-8',
                      errors='replace') as f:
-            self.buildenv.rfs.write_licenses(f, lic_xml_fname)
+            self.buildenv.rfs.write_licenses(f, pkgnames, lic_xml_fname)
 
         # Use some handwaving to determine grub version
         #
-- 
2.20.1




More information about the elbe-devel mailing list