Clean PkgsList return data implementation.
v2 cover Clean PkgsList return data implementation.
From: Mariano Lopez <[email protected]>
Currently the when calling the list() from the classes that inherit from PKgsList, it must pass the format required and it will return a formated string listing all the packages installed. Retruning such string is not the best data structure to manipulate in the callers.
This series of patches change PkgsList to return a dictionary and the callers will format the output as required.
Changes in V2:
- Fix the last break line in the image manifest
- Fix issue not showing the last pkg when using deb or ipk
[YOCTO #7427]
The following changes since commit 96a34e7f847ad34deac520b78809e7dd82dbc59e:
conf/distro/poky-tiny: correctly disable python in opkg-utils (2016-01-12 15:35:27 +0000)
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib mariano/bug7427v2
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=mariano/bug7427v2
Mariano Lopez (4):
lib/oe/package_manager: Add list_pkgs() to PkgsList class lib/oe/utils: Add function format_pkg_list() lib/oe/rootfs: Use list_pkgs() instead of list() lib/oe/package_manager.py: Remove list() from PkgsList class
meta/classes/buildhistory.bbclass | 11 +- meta/classes/license.bbclass | 8 +- meta/classes/populate_sdk_base.bbclass | 8 +- meta/classes/rootfs-postcommands.bbclass | 4 +- meta/lib/oe/package_manager.py | 193 ++++++++++++++----------------- meta/lib/oe/rootfs.py | 8 +- meta/lib/oe/sdk.py | 8 +- meta/lib/oe/utils.py | 22 ++++ 8 files changed, 137 insertions(+), 125 deletions(-)
Signature · 1 line
1.8.4.5
PATCH v2 1/4 lib/oe/package_manager: Add list_pkgs() to PkgsList class
From: Mariano Lopez <[email protected]>
Currently the class PkgList returns a formated string of the installed packages. It would be more clean to pass a standard data structure to the callers instead to format the output inside PkgsList class.
This patch adds list_pkgs() method to PkgsList class to get the all the information for installed packages and return a dictionary with the info.
[YOCTO #7427]
--- meta/lib/oe/package_manager.py | 128 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+)
meta/lib/oe/package_manager.py +128 -0
@@ -296,6 +296,53 @@ class PkgsList(object): def list(self, format=None): pass + @abstractmethod + def list_pkgs(self): + pass + + def opkg_query(self, cmd_output): + verregex = re.compile(' \([=<>]* [^ )]*\)') + output = dict() + filename = "" + dep = [] + for line in cmd_output.splitlines(): + line = line.rstrip() + if ':' in line: + if line.startswith("Package: "): + pkg = line.split(": ")[1] + elif line.startswith("Architecture: "): + arch = line.split(": ")[1] + elif line.startswith("Version: "): + ver = line.split(": ")[1] + elif line.startswith("File: "): + filename = line.split(": ")[1] + elif line.startswith("Depends: "): + depends = verregex.sub('', line.split(": ")[1]) + for depend in depends.split(", "): + dep.append(depend) + elif line.startswith("Recommends: "): + recommends = verregex.sub('', line.split(": ")[1]) + for recommend in recommends.split(", "): + dep.append("%s [REC]" % recommend) + else: + # IPK doesn't include the filename + if not filename: + filename = "%s_%s_%s.ipk" % (pkg, ver, arch) + if pkg: + output[pkg] = {"arch":arch, "ver":ver, + "filename":filename, "deps": dep } + pkg = "" + filename = "" + dep = [] + + if pkg: + if not filename: + filename = "%s_%s_%s.ipk" % (pkg, ver, arch) + output[pkg] = {"arch":arch, "ver":ver, + "filename":filename, "deps": dep } + + return output + class RpmPkgsList(PkgsList): def __init__(self, d, rootfs_dir, arch_var=None, os_var=None):
@@ -412,6 +459,59 @@ class RpmPkgsList(PkgsList): return '\n'.join(output) + def list_pkgs(self): + cmd = self.rpm_cmd + ' --root ' + self.rootfs_dir + cmd += ' -D "_dbpath /var/lib/rpm" -qa' + if self.rpm_version == 4: + cmd += " --qf '[%{NAME} %{ARCH} %{VERSION}\n]'" + else: + cmd += " --qf '[%{NAME} %{ARCH} %{VERSION} %{PACKAGEORIGIN}\n]'" + + try: + # bb.note(cmd) + tmp_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).strip() + except subprocess.CalledProcessError as e: + bb.fatal("Cannot get the installed packages list. Command '%s' " + "returned %d:\n%s" % (cmd, e.returncode, e.output)) + + output = dict() + deps = dict() + if self.rpm_version == 4: + bb.warn("Dependency listings are not supported with rpm 4 since rpmresolve does not work") + dependencies = "" + else: + dependencies = self._list_pkg_deps() + + # Populate deps dictionary for better manipulation + for line in dependencies.splitlines(): + pkg, dep = line.split("|") + if not pkg in deps: + deps[pkg] = list() + if not dep in deps[pkg]: + deps[pkg].append(dep) + + for line in tmp_output.split('\n'): + if len(line.strip()) == 0: + continue + pkg = line.split()[0] + arch = line.split()[1] + ver = line.split()[2] + dep = deps.get(pkg, []) + + # Skip GPG keys + if pkg == 'gpg-pubkey': + continue + if self.rpm_version == 4: + pkgorigin = "unknown" + else: + pkgorigin = line.split()[3] + new_pkg, new_arch = self._pkg_translate_smart_to_oe(pkg, arch) + + output[new_pkg] = {"arch":new_arch, "ver":ver, + "filename":pkgorigin, "deps":dep} + + return output + class OpkgPkgsList(PkgsList): def __init__(self, d, rootfs_dir, config_file):
@@ -466,6 +566,19 @@ class OpkgPkgsList(PkgsList): return '\n'.join(output) + def list_pkgs(self, format=None): + cmd = "%s %s status" % (self.opkg_cmd, self.opkg_args) + + try: + # bb.note(cmd) + cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).strip() + + except subprocess.CalledProcessError as e: + bb.fatal("Cannot get the installed packages list. Command '%s' " + "returned %d:\n%s" % (cmd, e.returncode, e.output)) + + return self.opkg_query(cmd_output) + class DpkgPkgsList(PkgsList): def list(self, format=None):
@@ -523,6 +636,21 @@ class DpkgPkgsList(PkgsList): return output + def list_pkgs(self): + cmd = [bb.utils.which(os.getenv('PATH'), "dpkg-query"), + "--admindir=%s/var/lib/dpkg" % self.rootfs_dir, + "-W"] + + cmd.append("-f=Package: ${Package}\nArchitecture: ${PackageArch}\nVersion: ${Version}\nFile: ${Package}_${Version}_${Architecture}.deb\nDepends: ${Depends}\nRecommends: ${Recommends}\n\n") + + try: + cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip() + except subprocess.CalledProcessError as e: + bb.fatal("Cannot get the installed packages list. Command '%s' " + "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output)) + + return self.opkg_query(cmd_output) + class PackageManager(object): """
Signature · 1 line
1.8.4.5
PATCH v2 2/4 lib/oe/utils: Add function format_pkg_list()
In reply to [email protected]From: Mariano Lopez <[email protected]>
The class PkgsList returns a dictionary with all the installed packages, because the data structure is a dictionary there is needed to format the data in order to write to a file.
The function format_pkg_list returns a formated sting with all packages installed. The output will depend on the requested format when calling the function.
[YOCTO #7427]
--- meta/lib/oe/utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
meta/lib/oe/utils.py +22 -0
@@ -208,6 +208,28 @@ def squashspaces(string): import re return re.sub("\s+", " ", string).strip() +def format_pkg_list(pkg_dict, ret_format=None): + output = [] + + if ret_format == "arch": + for pkg in sorted(pkg_dict): + output.append("%s %s" % (pkg, pkg_dict[pkg]["arch"])) + elif ret_format == "file": + for pkg in sorted(pkg_dict): + output.append("%s %s %s" % (pkg, pkg_dict[pkg]["filename"], pkg_dict[pkg]["arch"])) + elif ret_format == "ver": + for pkg in sorted(pkg_dict): + output.append("%s %s %s" % (pkg, pkg_dict[pkg]["arch"], pkg_dict[pkg]["ver"])) + elif ret_format == "deps": + for pkg in sorted(pkg_dict): + for dep in pkg_dict[pkg]["deps"]: + output.append("%s|%s" % (pkg, dep)) + else: + for pkg in sorted(pkg_dict): + output.append(pkg) + + return '\n'.join(output) + # # Python 2.7 doesn't have threaded pools (just multiprocessing) # so implement a version here
Signature · 1 line
1.8.4.5
PATCH v2 3/4 lib/oe/rootfs: Use list_pkgs() instead of list()
In reply to [email protected]From: Mariano Lopez <[email protected]>
This patch changes the use list_pkgs() instead of list() from class RpmPkgsList. The change is in two functions, image_list_installed_packages from rootfs.py and sdk_list_installed_packages from sdk.py.
With this change the functions calling the functions listed above, must format the output as they required. The formatting can be done using format_pkg_list() from oe.utils.
The classes calling the afected functions are changed too with this patch, to keep the same functionality using the new data structure.
[YOCTO #7427]
--- meta/classes/buildhistory.bbclass | 11 +++++++---- meta/classes/license.bbclass | 8 ++++++-- meta/classes/populate_sdk_base.bbclass | 8 ++++++-- meta/classes/rootfs-postcommands.bbclass | 4 +++- meta/lib/oe/package_manager.py | 18 ++++++++++-------- meta/lib/oe/rootfs.py | 8 ++++---- meta/lib/oe/sdk.py | 8 ++++---- 7 files changed, 40 insertions(+), 25 deletions(-)
meta/classes/buildhistory.bbclass +7 -4
@@ -337,18 +337,21 @@ def write_pkghistory(pkginfo, d): def buildhistory_list_installed(d, rootfs_type="image"): from oe.rootfs import image_list_installed_packages from oe.sdk import sdk_list_installed_packages + from oe.utils import format_pkg_list process_list = [('file', 'bh_installed_pkgs.txt'),\ ('deps', 'bh_installed_pkgs_deps.txt')] + if rootfs_type == "image": + pkgs = image_list_installed_packages(d) + else: + pkgs = sdk_list_installed_packages(d, rootfs_type == "sdk_target") + for output_type, output_file in process_list: output_file_full = os.path.join(d.getVar('WORKDIR', True), output_file) with open(output_file_full, 'w') as output: - if rootfs_type == "image": - output.write(image_list_installed_packages(d, output_type)) - else: - output.write(sdk_list_installed_packages(d, rootfs_type == "sdk_target", output_type)) + output.write(format_pkg_list(pkgs, output_type)) python buildhistory_list_installed_image() { buildhistory_list_installed(d)
meta/classes/license.bbclass +6 -2
@@ -21,8 +21,12 @@ python write_package_manifest() { license_image_dir = d.expand('${LICENSE_DIRECTORY}/${IMAGE_NAME}') bb.utils.mkdirhier(license_image_dir) from oe.rootfs import image_list_installed_packages + from oe.utils import format_pkg_list + + pkgs = image_list_installed_packages(d) + output = format_pkg_list(pkgs) open(os.path.join(license_image_dir, 'package.manifest'), - 'w+').write(image_list_installed_packages(d)) + 'w+').write(output) } python write_deploy_manifest() {
@@ -38,7 +42,7 @@ python license_create_manifest() { return 0 pkg_dic = {} - for pkg in image_list_installed_packages(d).splitlines(): + for pkg in sorted(image_list_installed_packages(d)): pkg_info = os.path.join(d.getVar('PKGDATA_DIR', True), 'runtime-reverse', pkg) pkg_name = os.path.basename(os.readlink(pkg_info))
meta/classes/populate_sdk_base.bbclass +6 -2
@@ -62,20 +62,24 @@ SDK_TARGET_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.target.manifest" SDK_HOST_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.host.manifest" python write_target_sdk_manifest () { from oe.sdk import sdk_list_installed_packages + from oe.utils import format_pkg_list sdkmanifestdir = os.path.dirname(d.getVar("SDK_TARGET_MANIFEST", True)) + pkgs = sdk_list_installed_packages(d, True) if not os.path.exists(sdkmanifestdir): bb.utils.mkdirhier(sdkmanifestdir) with open(d.getVar('SDK_TARGET_MANIFEST', True), 'w') as output: - output.write(sdk_list_installed_packages(d, True, 'ver')) + output.write(format_pkg_list(pkgs, 'ver')) } python write_host_sdk_manifest () { from oe.sdk import sdk_list_installed_packages + from oe.utils import format_pkg_list sdkmanifestdir = os.path.dirname(d.getVar("SDK_HOST_MANIFEST", True)) + pkgs = sdk_list_installed_packages(d, False) if not os.path.exists(sdkmanifestdir): bb.utils.mkdirhier(sdkmanifestdir) with open(d.getVar('SDK_HOST_MANIFEST', True), 'w') as output: - output.write(sdk_list_installed_packages(d, False, 'ver')) + output.write(format_pkg_list(pkgs, 'ver')) } POPULATE_SDK_POST_TARGET_COMMAND_append = " write_target_sdk_manifest ; "
meta/classes/rootfs-postcommands.bbclass +3 -1
@@ -207,13 +207,15 @@ insert_feed_uris () { python write_image_manifest () { from oe.rootfs import image_list_installed_packages + from oe.utils import format_pkg_list deploy_dir = d.getVar('DEPLOY_DIR_IMAGE', True) link_name = d.getVar('IMAGE_LINK_NAME', True) manifest_name = d.getVar('IMAGE_MANIFEST', True) + pkgs = image_list_installed_packages(d) with open(manifest_name, 'w+') as image_manifest: - image_manifest.write(image_list_installed_packages(d, 'ver')) + image_manifest.write(format_pkg_list(pkgs, "ver")) image_manifest.write("\n") if manifest_name is not None and os.path.exists(manifest_name):
meta/lib/oe/package_manager.py +10 -8
@@ -701,7 +701,7 @@ class PackageManager(object): pass @abstractmethod - def list_installed(self, format=None): + def list_installed(self): pass @abstractmethod
@@ -721,7 +721,9 @@ class PackageManager(object): installed_pkgs_file = os.path.join(self.d.getVar('WORKDIR', True), "installed_pkgs.txt") with open(installed_pkgs_file, "w+") as installed_pkgs: - installed_pkgs.write(self.list_installed("arch")) + pkgs = self.list_installed() + output = oe.utils.format_pkg_list(pkgs, "arch") + installed_pkgs.write(output) if globs is None: globs = self.d.getVar('IMAGE_INSTALL_COMPLEMENTARY', True)
@@ -1425,8 +1427,8 @@ class RpmPM(PackageManager): self.image_rpmlib, symlinks=True) - def list_installed(self, format=None): - return self.pkgs_list.list(format) + def list_installed(self): + return self.pkgs_list.list_pkgs() ''' If incremental install, we need to determine what we've got,
@@ -1790,8 +1792,8 @@ class OpkgPM(PackageManager): # create the directory back, it's needed by PM lock bb.utils.mkdirhier(self.opkg_dir) - def list_installed(self, format=None): - return OpkgPkgsList(self.d, self.target_rootfs, self.config_file).list(format) + def list_installed(self): + return OpkgPkgsList(self.d, self.target_rootfs, self.config_file).list_pkgs() def handle_bad_recommendations(self): bad_recommendations = self.d.getVar("BAD_RECOMMENDATIONS", True) or ""
@@ -2179,8 +2181,8 @@ class DpkgPM(PackageManager): bb.fatal("Cannot fix broken dependencies. Command '%s' " "returned %d:\n%s" % (cmd, e.returncode, e.output)) - def list_installed(self, format=None): - return DpkgPkgsList(self.d, self.target_rootfs).list() + def list_installed(self): + return DpkgPkgsList(self.d, self.target_rootfs).list_pkgs() def generate_index_files(d):
meta/lib/oe/rootfs.py +4 -4
@@ -976,17 +976,17 @@ def create_rootfs(d, manifest_dir=None): os.environ.update(env_bkp) -def image_list_installed_packages(d, format=None, rootfs_dir=None): +def image_list_installed_packages(d, rootfs_dir=None): if not rootfs_dir: rootfs_dir = d.getVar('IMAGE_ROOTFS', True) img_type = d.getVar('IMAGE_PKGTYPE', True) if img_type == "rpm": - return RpmPkgsList(d, rootfs_dir).list(format) + return RpmPkgsList(d, rootfs_dir).list_pkgs() elif img_type == "ipk": - return OpkgPkgsList(d, rootfs_dir, d.getVar("IPKGCONF_TARGET", True)).list(format) + return OpkgPkgsList(d, rootfs_dir, d.getVar("IPKGCONF_TARGET", True)).list_pkgs() elif img_type == "deb": - return DpkgPkgsList(d, rootfs_dir).list(format) + return DpkgPkgsList(d, rootfs_dir).list_pkgs() if __name__ == "__main__": """
meta/lib/oe/sdk.py +4 -4
@@ -345,7 +345,7 @@ class DpkgSdk(Sdk): -def sdk_list_installed_packages(d, target, format=None, rootfs_dir=None): +def sdk_list_installed_packages(d, target, rootfs_dir=None): if rootfs_dir is None: sdk_output = d.getVar('SDK_OUTPUT', True) target_path = d.getVar('SDKTARGETSYSROOT', True).strip('/')
@@ -356,12 +356,12 @@ def sdk_list_installed_packages(d, target, format=None, rootfs_dir=None): if img_type == "rpm": arch_var = ["SDK_PACKAGE_ARCHS", None][target is True] os_var = ["SDK_OS", None][target is True] - return RpmPkgsList(d, rootfs_dir, arch_var, os_var).list(format) + return RpmPkgsList(d, rootfs_dir, arch_var, os_var).list_pkgs() elif img_type == "ipk": conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True] - return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var, True)).list(format) + return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var, True)).list_pkgs() elif img_type == "deb": - return DpkgPkgsList(d, rootfs_dir).list(format) + return DpkgPkgsList(d, rootfs_dir).list_pkgs() def populate_sdk(d, manifest_dir=None): env_bkp = os.environ.copy()
Signature · 1 line
1.8.4.5
PATCH v2 4/4 lib/oe/package_manager.py: Remove list() from PkgsList class
In reply to [email protected]From: Mariano Lopez <[email protected]>
Now that the method list() is not used anymore, remove it.
[YOCTO #7427]
--- meta/lib/oe/package_manager.py | 153 ----------------------------------------- 1 file changed, 153 deletions(-)
meta/lib/oe/package_manager.py +0 -153
@@ -293,10 +293,6 @@ class PkgsList(object): self.rootfs_dir = rootfs_dir @abstractmethod - def list(self, format=None): - pass - - @abstractmethod def list_pkgs(self): pass
@@ -409,56 +405,6 @@ class RpmPkgsList(PkgsList): return output - def list(self, format=None): - if format == "deps": - if self.rpm_version == 4: - bb.fatal("'deps' format dependency listings are not supported with rpm 4 since rpmresolve does not work") - return self._list_pkg_deps() - - cmd = self.rpm_cmd + ' --root ' + self.rootfs_dir - cmd += ' -D "_dbpath /var/lib/rpm" -qa' - if self.rpm_version == 4: - cmd += " --qf '[%{NAME} %{ARCH} %{VERSION}\n]'" - else: - cmd += " --qf '[%{NAME} %{ARCH} %{VERSION} %{PACKAGEORIGIN}\n]'" - - try: - # bb.note(cmd) - tmp_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).strip() - - except subprocess.CalledProcessError as e: - bb.fatal("Cannot get the installed packages list. Command '%s' " - "returned %d:\n%s" % (cmd, e.returncode, e.output)) - - output = list() - for line in tmp_output.split('\n'): - if len(line.strip()) == 0: - continue - pkg = line.split()[0] - arch = line.split()[1] - ver = line.split()[2] - # Skip GPG keys - if pkg == 'gpg-pubkey': - continue - if self.rpm_version == 4: - pkgorigin = "unknown" - else: - pkgorigin = line.split()[3] - new_pkg, new_arch = self._pkg_translate_smart_to_oe(pkg, arch) - - if format == "arch": - output.append('%s %s' % (new_pkg, new_arch)) - elif format == "file": - output.append('%s %s %s' % (new_pkg, pkgorigin, new_arch)) - elif format == "ver": - output.append('%s %s %s' % (new_pkg, new_arch, ver)) - else: - output.append('%s' % (new_pkg)) - - output.sort() - - return '\n'.join(output) - def list_pkgs(self): cmd = self.rpm_cmd + ' --root ' + self.rootfs_dir cmd += ' -D "_dbpath /var/lib/rpm" -qa'
@@ -521,51 +467,6 @@ class OpkgPkgsList(PkgsList): self.opkg_args = "-f %s -o %s " % (config_file, rootfs_dir) self.opkg_args += self.d.getVar("OPKG_ARGS", True) - def list(self, format=None): - opkg_query_cmd = bb.utils.which(os.getenv('PATH'), "opkg-query-helper.py") - - if format == "arch": - cmd = "%s %s status | %s -a" % \ - (self.opkg_cmd, self.opkg_args, opkg_query_cmd) - elif format == "file": - cmd = "%s %s status | %s -f" % \ - (self.opkg_cmd, self.opkg_args, opkg_query_cmd) - elif format == "ver": - cmd = "%s %s status | %s -v" % \ - (self.opkg_cmd, self.opkg_args, opkg_query_cmd) - elif format == "deps": - cmd = "%s %s status | %s" % \ - (self.opkg_cmd, self.opkg_args, opkg_query_cmd) - else: - cmd = "%s %s list_installed | cut -d' ' -f1" % \ - (self.opkg_cmd, self.opkg_args) - - try: - # bb.note(cmd) - tmp_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).strip() - - except subprocess.CalledProcessError as e: - bb.fatal("Cannot get the installed packages list. Command '%s' " - "returned %d:\n%s" % (cmd, e.returncode, e.output)) - - output = list() - for line in tmp_output.split('\n'): - if len(line.strip()) == 0: - continue - if format == "file": - pkg, pkg_file, pkg_arch = line.split() - full_path = os.path.join(self.rootfs_dir, pkg_arch, pkg_file) - if os.path.exists(full_path): - output.append('%s %s %s' % (pkg, full_path, pkg_arch)) - else: - output.append('%s %s %s' % (pkg, pkg_file, pkg_arch)) - else: - output.append(line) - - output.sort() - - return '\n'.join(output) - def list_pkgs(self, format=None): cmd = "%s %s status" % (self.opkg_cmd, self.opkg_args)
@@ -581,60 +482,6 @@ class OpkgPkgsList(PkgsList): class DpkgPkgsList(PkgsList): - def list(self, format=None): - cmd = [bb.utils.which(os.getenv('PATH'), "dpkg-query"), - "--admindir=%s/var/lib/dpkg" % self.rootfs_dir, - "-W"] - - if format == "arch": - cmd.append("-f=${Package} ${PackageArch}\n") - elif format == "file": - cmd.append("-f=${Package} ${Package}_${Version}_${Architecture}.deb ${PackageArch}\n") - elif format == "ver": - cmd.append("-f=${Package} ${PackageArch} ${Version}\n") - elif format == "deps": - cmd.append("-f=Package: ${Package}\nDepends: ${Depends}\nRecommends: ${Recommends}\n\n") - else: - cmd.append("-f=${Package}\n") - - try: - output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip() - except subprocess.CalledProcessError as e: - bb.fatal("Cannot get the installed packages list. Command '%s' " - "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output)) - - if format == "file": - tmp_output = "" - for line in tuple(output.split('\n')): - if not line.strip(): - continue - pkg, pkg_file, pkg_arch = line.split() - full_path = os.path.join(self.rootfs_dir, pkg_arch, pkg_file) - if os.path.exists(full_path): - tmp_output += "%s %s %s\n" % (pkg, full_path, pkg_arch) - else: - tmp_output += "%s %s %s\n" % (pkg, pkg_file, pkg_arch) - - output = tmp_output - elif format == "deps": - opkg_query_cmd = bb.utils.which(os.getenv('PATH'), "opkg-query-helper.py") - file_out = tempfile.NamedTemporaryFile() - file_out.write(output) - file_out.flush() - - try: - output = subprocess.check_output("cat %s | %s" % - (file_out.name, opkg_query_cmd), - stderr=subprocess.STDOUT, - shell=True) - except subprocess.CalledProcessError as e: - file_out.close() - bb.fatal("Cannot compute packages dependencies. Command '%s' " - "returned %d:\n%s" % (e.cmd, e.returncode, e.output)) - - file_out.close() - - return output def list_pkgs(self): cmd = [bb.utils.which(os.getenv('PATH'), "dpkg-query"),
Signature · 1 line
1.8.4.5