[elbe-devel] [PATCH v2 1/5] elbeproject: Add gen_licenses method
Olivier Dion
dion at linutronix.de
Sun Mar 15 22:12:11 CET 2020
The method check for the existance of the copyright file for each
packages of a RFS. If a copyright file is missing, it's copied from
the buildenv. If the file is also missing from the buildenv, then an
error is emitted.
Signed-off-by: Olivier Dion <dion at linutronix.de>
---
elbepack/elbeproject.py | 42 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index b64a5fcb..765dd956 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -923,3 +923,45 @@ class ElbeProject (object):
except SystemError as e:
logging.exception("Commiting changes failed")
raise AptCacheCommitError(str(e))
+
+ def gen_licenses(self, rfs, env, pkg_list):
+
+ lic_txt_fname = os.path.join(self.builddir,
+ "licence-%s.txt" % rfs)
+ lic_xml_fname = os.path.join(self.builddir,
+ "licence-%s.xml" % rfs)
+ pkg_list.sort()
+
+ if env is not self.buildenv:
+
+ DOC = "/usr/share/doc"
+
+ do("rm -rf '%s'" % env.rfs.fname(DOC))
+
+ if not env.rfs.exists(DOC):
+ logging.warning("%s doesn't exists in RFS %s, "
+ "but is need for licenses generation",
+ DOC, rfs)
+ env.rfs.mkdir_p(DOC)
+
+ for pkg in pkg_list:
+
+ pkg_doc = os.path.join(DOC, pkg, "copyright")
+
+ if env.rfs.exists(pkg_doc):
+ continue
+
+ env.rfs.mkdir_p(os.path.join(DOC, pkg))
+
+ # Try to copy from buildenv or fail
+ try:
+ do("cp '%s' '%s'" % (self.buildenv.rfs.fname(pkg_doc),
+ env.rfs.fname(pkg_doc)))
+ except CommandError as e:
+ logging.error("Missing copyright file for package '%s' in RFS '%s'. "
+ "The copyright file can not be found in the buildenv" %
+ (pkg, rfs))
+
+ with io.open(lic_txt_fname, 'w+',
+ encoding='utf-8', errors='replace') as f:
+ env.rfs.write_licenses(f, pkg_list, lic_xml_fname)
--
2.25.1
More information about the elbe-devel
mailing list