X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwlaunchpad%2Fplugins%2Frwlaunchpadtasklet%2Frift%2Fpackage%2Fpackage.py;h=0b5c49948467d093cce67a50d6ab5137c5222a25;hb=HEAD;hp=b4162811f8f9be646e9e11ca345e86c3a9f56002;hpb=5a327cd48a7bfea78c3d11ec4143f72d103a8afc;p=osm%2FSO.git diff --git a/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/package/package.py b/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/package/package.py index b4162811..0b5c4994 100644 --- a/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/package/package.py +++ b/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/package/package.py @@ -431,10 +431,21 @@ class DescriptorPackage(object): Raises: NotADirectoryError - dest_root_dir is not a directory """ + def find_prefix(): + """ Find comon prefix of all files in package. This prefix will be + used to collapse directory structure during extraction to eliminate + empty nested folders. + """ + common_dir = set() + for f in self.files: + common_dir.add(os.path.dirname(f)) + prefix = os.path.commonprefix(list(common_dir)) + return prefix if prefix else None + if not os.path.isdir(dest_root_dir): raise NotADirectoryError(dest_root_dir) - self.extract_dir(None, dest_root_dir, extract_images) + self.extract_dir(find_prefix(), dest_root_dir, extract_images) def open(self, rel_path): """ Open a file contained in the package in read-only, binary mode. @@ -613,7 +624,7 @@ class PackageChecksumValidator(object): archive_checksums = checksums.ArchiveChecksums.from_file_desc(checksum_hdl) except (FileNotFoundError, PackageError) as e: self._log.warning("Could not open package checksum file. Not validating checksums.") - return validated_file_checksums + return self.validated_file_checksums for pkg_file in package.files: if pkg_file == checksum_file: @@ -635,7 +646,7 @@ class PackageChecksumValidator(object): raise PackageValidationError(msg) from e if archive_checksums[pkg_file_no_prefix] != file_checksum: - msg = "{} checksum ({}) did match expected checksum ({})".format( + msg = "{} checksum ({}) did not match expected checksum ({})".format( pkg_file, file_checksum, archive_checksums[pkg_file_no_prefix] ) self._log.error(msg)