1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-31 12:49:46 +00:00

package_manager: remove strings and migrate to direct arrays

When using subprocess call and check_output, it is better to use arrays
rather than strings when possible to avoid whitespace and quoting
problems.

[ YOCTO #9342 ]

(From OE-Core rev: b12cec9a5ef14ecb02be7feec65508cf5d65c795)

(From OE-Core rev: 60ba1d424636bdd5700ec3ee0acec5c19550b884)

Signed-off-by: Stephano Cetola <stephano.cetola@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Stephano Cetola
2016-12-06 07:30:59 -08:00
committed by Richard Purdie
parent 2d5e8043be
commit 8cdf2a2e36
2 changed files with 121 additions and 125 deletions
+7 -6
View File
@@ -18,23 +18,24 @@ def runstrip(arg):
newmode = origmode | stat.S_IWRITE | stat.S_IREAD newmode = origmode | stat.S_IWRITE | stat.S_IREAD
os.chmod(file, newmode) os.chmod(file, newmode)
extraflags = "" stripcmd = [strip]
# kernel module # kernel module
if elftype & 16: if elftype & 16:
extraflags = "--strip-debug --remove-section=.comment --remove-section=.note --preserve-dates" stripcmd.extend(["--strip-debug", "--remove-section=.comment",
"--remove-section=.note", "--preserve-dates"])
# .so and shared library # .so and shared library
elif ".so" in file and elftype & 8: elif ".so" in file and elftype & 8:
extraflags = "--remove-section=.comment --remove-section=.note --strip-unneeded" stripcmd.extend(["--remove-section=.comment", "--remove-section=.note", "--strip-unneeded"])
# shared or executable: # shared or executable:
elif elftype & 8 or elftype & 4: elif elftype & 8 or elftype & 4:
extraflags = "--remove-section=.comment --remove-section=.note" stripcmd.extend(["--remove-section=.comment", "--remove-section=.note"])
stripcmd = "'%s' %s '%s'" % (strip, extraflags, file) stripcmd.append(file)
bb.debug(1, "runstrip: %s" % stripcmd) bb.debug(1, "runstrip: %s" % stripcmd)
try: try:
output = subprocess.check_output(stripcmd, stderr=subprocess.STDOUT, shell=True) output = subprocess.check_output(stripcmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
bb.error("runstrip: '%s' strip command failed with %s (%s)" % (stripcmd, e.returncode, e.output)) bb.error("runstrip: '%s' strip command failed with %s (%s)" % (stripcmd, e.returncode, e.output))
+114 -119
View File
@@ -358,12 +358,11 @@ class RpmPkgsList(PkgsList):
RpmIndexer(d, rootfs_dir).get_ml_prefix_and_os_list(arch_var, os_var) RpmIndexer(d, rootfs_dir).get_ml_prefix_and_os_list(arch_var, os_var)
# Determine rpm version # Determine rpm version
cmd = "%s --version" % self.rpm_cmd
try: try:
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).decode("utf-8") output = subprocess.check_output([self.rpm_cmd, "--version"], stderr=subprocess.STDOUT).decode("utf-8")
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
bb.fatal("Getting rpm version failed. Command '%s' " bb.fatal("Getting rpm version failed. Command '%s' "
"returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) "returned %d:\n%s" % (self.rpm_cmd, e.returncode, e.output.decode("utf-8")))
''' '''
Translate the RPM/Smart format names to the OE multilib format names Translate the RPM/Smart format names to the OE multilib format names
@@ -412,16 +411,15 @@ class RpmPkgsList(PkgsList):
return output return output
def list_pkgs(self): def list_pkgs(self):
cmd = self.rpm_cmd + ' --root ' + self.rootfs_dir cmd = [self.rpm_cmd, '--root', self.rootfs_dir]
cmd += ' -D "_dbpath /var/lib/rpm" -qa' cmd.extend(['-D', '_dbpath /var/lib/rpm'])
cmd += " --qf '[%{NAME} %{ARCH} %{VERSION} %{PACKAGEORIGIN}\n]'" cmd.extend(['-qa', '--qf', '[%{NAME} %{ARCH} %{VERSION} %{PACKAGEORIGIN}\n]'])
try: try:
# bb.note(cmd) tmp_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip().decode("utf-8")
tmp_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).strip().decode("utf-8")
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
bb.fatal("Cannot get the installed packages list. Command '%s' " bb.fatal("Cannot get the installed packages list. Command '%s' "
"returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
output = dict() output = dict()
deps = dict() deps = dict()
@@ -672,11 +670,11 @@ class RpmPM(PackageManager):
# 2 = --log-level=debug # 2 = --log-level=debug
# 3 = --log-level=debug plus dumps of scriplet content and command invocation # 3 = --log-level=debug plus dumps of scriplet content and command invocation
self.debug_level = int(d.getVar('ROOTFS_RPM_DEBUG', True) or "0") self.debug_level = int(d.getVar('ROOTFS_RPM_DEBUG', True) or "0")
self.smart_opt = "--log-level=%s --data-dir=%s" % \ self.smart_opt = ["--log-level=%s" %
("warning" if self.debug_level == 0 else ("warning" if self.debug_level == 0 else
"info" if self.debug_level == 1 else "info" if self.debug_level == 1 else
"debug", "debug"), "--data-dir=%s" %
os.path.join(target_rootfs, 'var/lib/smart')) os.path.join(target_rootfs, 'var/lib/smart')]
self.scriptlet_wrapper = self.d.expand('${WORKDIR}/scriptlet_wrapper') self.scriptlet_wrapper = self.d.expand('${WORKDIR}/scriptlet_wrapper')
self.solution_manifest = self.d.expand('${T}/saved/%s_solution' % self.solution_manifest = self.d.expand('${T}/saved/%s_solution' %
self.task_name) self.task_name)
@@ -732,18 +730,18 @@ class RpmPM(PackageManager):
for arch in arch_list: for arch in arch_list:
bb.note('Adding Smart channel url%d%s (%s)' % bb.note('Adding Smart channel url%d%s (%s)' %
(uri_iterator, arch, channel_priority)) (uri_iterator, arch, channel_priority))
self._invoke_smart('channel --add url%d-%s type=rpm-md baseurl=%s/%s -y' self._invoke_smart(['channel', '--add', 'url%d-%s' % (uri_iterator, arch),
% (uri_iterator, arch, uri, arch)) 'type=rpm-md', 'baseurl=%s/%s' % (uri, arch), '-y'])
self._invoke_smart('channel --set url%d-%s priority=%d' % self._invoke_smart(['channel', '--set', 'url%d-%s' % (uri_iterator, arch),
(uri_iterator, arch, channel_priority)) 'priority=%d' % channel_priority])
channel_priority -= 5 channel_priority -= 5
else: else:
bb.note('Adding Smart channel url%d (%s)' % bb.note('Adding Smart channel url%d (%s)' %
(uri_iterator, channel_priority)) (uri_iterator, channel_priority))
self._invoke_smart('channel --add url%d type=rpm-md baseurl=%s -y' self._invoke_smart(['channel', '--add', 'url%d' % uri_iterator,
% (uri_iterator, uri)) 'type=rpm-md', 'baseurl=%s' % uri, '-y'])
self._invoke_smart('channel --set url%d priority=%d' % self._invoke_smart(['channel', '--set', 'url%d' % uri_iterator,
(uri_iterator, channel_priority)) 'priority=%d' % channel_priority])
channel_priority -= 5 channel_priority -= 5
uri_iterator += 1 uri_iterator += 1
@@ -774,18 +772,17 @@ class RpmPM(PackageManager):
self._create_configs(platform, platform_extra) self._create_configs(platform, platform_extra)
#takes array args
def _invoke_smart(self, args): def _invoke_smart(self, args):
cmd = "%s %s %s" % (self.smart_cmd, self.smart_opt, args) cmd = [self.smart_cmd] + self.smart_opt + args
# bb.note(cmd) # bb.note(cmd)
try: try:
complementary_pkgs = subprocess.check_output(cmd, complementary_pkgs = subprocess.check_output(cmd,stderr=subprocess.STDOUT).decode("utf-8")
stderr=subprocess.STDOUT,
shell=True).decode("utf-8")
# bb.note(complementary_pkgs) # bb.note(complementary_pkgs)
return complementary_pkgs return complementary_pkgs
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
bb.fatal("Could not invoke smart. Command " bb.fatal("Could not invoke smart. Command "
"'%s' returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) "'%s' returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
def _search_pkg_name_in_feeds(self, pkg, feed_archs): def _search_pkg_name_in_feeds(self, pkg, feed_archs):
for arch in feed_archs: for arch in feed_archs:
@@ -800,19 +797,23 @@ class RpmPM(PackageManager):
# Search provides if not found by pkgname. # Search provides if not found by pkgname.
bb.note('Not found %s by name, searching provides ...' % pkg) bb.note('Not found %s by name, searching provides ...' % pkg)
cmd = "%s %s query --provides %s --show-format='$name-$version'" % \ cmd = [self.smart_cmd] + self.smart_opt + ["query", "--provides", pkg,
(self.smart_cmd, self.smart_opt, pkg) "--show-format=$name-$version"]
cmd += " | sed -ne 's/ *Provides://p'" bb.note('cmd: %s' % ' '.join(cmd))
bb.note('cmd: %s' % cmd) ps = subprocess.Popen(cmd, stdout=subprocess.PIPE)
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).decode("utf-8") try:
# Found a provider output = subprocess.check_output(["sed", "-ne", "s/ *Provides://p"],
if output: stdin=ps.stdout, stderr=subprocess.STDOUT).decode("utf-8")
bb.note('Found providers for %s: %s' % (pkg, output)) # Found a provider
for p in output.split(): if output:
for arch in feed_archs: bb.note('Found providers for %s: %s' % (pkg, output))
arch = arch.replace('-', '_') for p in output.split():
if p.rstrip().endswith('@' + arch): for arch in feed_archs:
return p arch = arch.replace('-', '_')
if p.rstrip().endswith('@' + arch):
return p
except subprocess.CalledProcessError as e:
bb.error("Failed running smart query on package %s." % pkg)
return "" return ""
@@ -949,30 +950,32 @@ class RpmPM(PackageManager):
open(db_config_dir, 'w+').write(DB_CONFIG_CONTENT) open(db_config_dir, 'w+').write(DB_CONFIG_CONTENT)
# Create database so that smart doesn't complain (lazy init) # Create database so that smart doesn't complain (lazy init)
opt = "-qa" cmd = [self.rpm_cmd, '--root', self.target_rootfs, '--dbpath', '/var/lib/rpm', '-qa']
cmd = "%s --root %s --dbpath /var/lib/rpm %s > /dev/null" % (
self.rpm_cmd, self.target_rootfs, opt)
try: try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
bb.fatal("Create rpm database failed. Command '%s' " bb.fatal("Create rpm database failed. Command '%s' "
"returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
# Import GPG key to RPM database of the target system # Import GPG key to RPM database of the target system
if self.d.getVar('RPM_SIGN_PACKAGES', True) == '1': if self.d.getVar('RPM_SIGN_PACKAGES', True) == '1':
pubkey_path = self.d.getVar('RPM_GPG_PUBKEY', True) pubkey_path = self.d.getVar('RPM_GPG_PUBKEY', True)
cmd = "%s --root %s --dbpath /var/lib/rpm --import %s > /dev/null" % ( cmd = [self.rpm_cmd, '--root', self.target_rootfs, '--dbpath', '/var/lib/rpm', '--import', pubkey_path]
self.rpm_cmd, self.target_rootfs, pubkey_path) try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
bb.fatal("Import GPG key failed. Command '%s' "
"returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
# Configure smart # Configure smart
bb.note("configuring Smart settings") bb.note("configuring Smart settings")
bb.utils.remove(os.path.join(self.target_rootfs, 'var/lib/smart'), bb.utils.remove(os.path.join(self.target_rootfs, 'var/lib/smart'),
True) True)
self._invoke_smart('config --set rpm-root=%s' % self.target_rootfs) self._invoke_smart(['config', '--set', 'rpm-root=%s' % self.target_rootfs])
self._invoke_smart('config --set rpm-dbpath=/var/lib/rpm') self._invoke_smart(['config', '--set', 'rpm-dbpath=/var/lib/rpm'])
self._invoke_smart('config --set rpm-extra-macros._var=%s' % self._invoke_smart(['config', '--set', 'rpm-extra-macros._var=%s' %
self.d.getVar('localstatedir', True)) self.d.getVar('localstatedir', True)])
cmd = "config --set rpm-extra-macros._tmppath=/%s/tmp" % (self.install_dir_name) cmd = ["config", "--set", "rpm-extra-macros._tmppath=/%s/tmp" % self.install_dir_name]
prefer_color = self.d.getVar('RPM_PREFER_ELF_ARCH', True) prefer_color = self.d.getVar('RPM_PREFER_ELF_ARCH', True)
if prefer_color: if prefer_color:
@@ -986,32 +989,32 @@ class RpmPM(PackageManager):
['mips64', 'mips64el']: ['mips64', 'mips64el']:
bb.fatal("RPM_PREFER_ELF_ARCH = \"4\" is for mips64 or mips64el " bb.fatal("RPM_PREFER_ELF_ARCH = \"4\" is for mips64 or mips64el "
"only.") "only.")
self._invoke_smart('config --set rpm-extra-macros._prefer_color=%s' self._invoke_smart(['config', '--set', 'rpm-extra-macros._prefer_color=%s'
% prefer_color) % prefer_color])
self._invoke_smart(cmd) self._invoke_smart(cmd)
self._invoke_smart('config --set rpm-ignoresize=1') self._invoke_smart(['config', '--set', 'rpm-ignoresize=1'])
# Write common configuration for host and target usage # Write common configuration for host and target usage
self._invoke_smart('config --set rpm-nolinktos=1') self._invoke_smart(['config', '--set', 'rpm-nolinktos=1'])
self._invoke_smart('config --set rpm-noparentdirs=1') self._invoke_smart(['config', '--set', 'rpm-noparentdirs=1'])
check_signature = self.d.getVar('RPM_CHECK_SIGNATURES', True) check_signature = self.d.getVar('RPM_CHECK_SIGNATURES', True)
if check_signature and check_signature.strip() == "0": if check_signature and check_signature.strip() == "0":
self._invoke_smart('config --set rpm-check-signatures=false') self._invoke_smart(['config', '--set rpm-check-signatures=false'])
for i in self.d.getVar('BAD_RECOMMENDATIONS', True).split(): for i in self.d.getVar('BAD_RECOMMENDATIONS', True).split():
self._invoke_smart('flag --set ignore-recommends %s' % i) self._invoke_smart(['flag', '--set', 'ignore-recommends', i])
# Do the following configurations here, to avoid them being # Do the following configurations here, to avoid them being
# saved for field upgrade # saved for field upgrade
if self.d.getVar('NO_RECOMMENDATIONS', True).strip() == "1": if self.d.getVar('NO_RECOMMENDATIONS', True).strip() == "1":
self._invoke_smart('config --set ignore-all-recommends=1') self._invoke_smart(['config', '--set', 'ignore-all-recommends=1'])
pkg_exclude = self.d.getVar('PACKAGE_EXCLUDE', True) or "" pkg_exclude = self.d.getVar('PACKAGE_EXCLUDE', True) or ""
for i in pkg_exclude.split(): for i in pkg_exclude.split():
self._invoke_smart('flag --set exclude-packages %s' % i) self._invoke_smart(['flag', '--set', 'exclude-packages', i])
# Optional debugging # Optional debugging
# self._invoke_smart('config --set rpm-log-level=debug') # self._invoke_smart(['config', '--set', 'rpm-log-level=debug'])
# cmd = 'config --set rpm-log-file=/tmp/smart-debug-logfile' # cmd = ['config', '--set', 'rpm-log-file=/tmp/smart-debug-logfile']
# self._invoke_smart(cmd) # self._invoke_smart(cmd)
ch_already_added = [] ch_already_added = []
for canonical_arch in platform_extra: for canonical_arch in platform_extra:
@@ -1030,16 +1033,16 @@ class RpmPM(PackageManager):
if not arch in ch_already_added: if not arch in ch_already_added:
bb.note('Adding Smart channel %s (%s)' % bb.note('Adding Smart channel %s (%s)' %
(arch, channel_priority)) (arch, channel_priority))
self._invoke_smart('channel --add %s type=rpm-md baseurl=%s -y' self._invoke_smart(['channel', '--add', arch, 'type=rpm-md',
% (arch, arch_channel)) 'baseurl=%s' % arch_channel, '-y'])
self._invoke_smart('channel --set %s priority=%d' % self._invoke_smart(['channel', '--set', arch, 'priority=%d' %
(arch, channel_priority)) channel_priority])
channel_priority -= 5 channel_priority -= 5
ch_already_added.append(arch) ch_already_added.append(arch)
bb.note('adding Smart RPM DB channel') bb.note('adding Smart RPM DB channel')
self._invoke_smart('channel --add rpmsys type=rpm-sys -y') self._invoke_smart(['channel', '--add', 'rpmsys', 'type=rpm-sys', '-y'])
# Construct install scriptlet wrapper. # Construct install scriptlet wrapper.
# Scripts need to be ordered when executed, this ensures numeric order. # Scripts need to be ordered when executed, this ensures numeric order.
@@ -1102,15 +1105,15 @@ class RpmPM(PackageManager):
bb.note("configuring RPM cross-install scriptlet_wrapper") bb.note("configuring RPM cross-install scriptlet_wrapper")
os.chmod(self.scriptlet_wrapper, 0o755) os.chmod(self.scriptlet_wrapper, 0o755)
cmd = 'config --set rpm-extra-macros._cross_scriptlet_wrapper=%s' % \ cmd = ['config', '--set', 'rpm-extra-macros._cross_scriptlet_wrapper=%s' %
self.scriptlet_wrapper self.scriptlet_wrapper]
self._invoke_smart(cmd) self._invoke_smart(cmd)
# Debug to show smart config info # Debug to show smart config info
# bb.note(self._invoke_smart('config --show')) # bb.note(self._invoke_smart(['config', '--show']))
def update(self): def update(self):
self._invoke_smart('update rpmsys') self._invoke_smart(['update', 'rpmsys'])
def get_rdepends_recursively(self, pkgs): def get_rdepends_recursively(self, pkgs):
# pkgs will be changed during the loop, so use [:] to make a copy. # pkgs will be changed during the loop, so use [:] to make a copy.
@@ -1207,20 +1210,19 @@ class RpmPM(PackageManager):
return return
if not attempt_only: if not attempt_only:
bb.note('to be installed: %s' % ' '.join(pkgs)) bb.note('to be installed: %s' % ' '.join(pkgs))
cmd = "%s %s install -y %s" % \ cmd = [self.smart_cmd] + self.smart_opt + ["install", "-y"] + pkgs
(self.smart_cmd, self.smart_opt, ' '.join(pkgs)) bb.note(' '.join(cmd))
bb.note(cmd)
else: else:
bb.note('installing attempt only packages...') bb.note('installing attempt only packages...')
bb.note('Attempting %s' % ' '.join(pkgs)) bb.note('Attempting %s' % ' '.join(pkgs))
cmd = "%s %s install --attempt -y %s" % \ cmd = [self.smart_cmd] + self.smart_opt + ["install", "--attempt",
(self.smart_cmd, self.smart_opt, ' '.join(pkgs)) "-y"] + pkgs
try: try:
output = subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT).decode("utf-8") output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8")
bb.note(output) bb.note(output)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
bb.fatal("Unable to install packages. Command '%s' " bb.fatal("Unable to install packages. Command '%s' "
"returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
''' '''
Remove pkgs with smart, the pkg name is smart/rpm format Remove pkgs with smart, the pkg name is smart/rpm format
@@ -1229,24 +1231,19 @@ class RpmPM(PackageManager):
bb.note('to be removed: ' + ' '.join(pkgs)) bb.note('to be removed: ' + ' '.join(pkgs))
if not with_dependencies: if not with_dependencies:
cmd = "%s -e --nodeps " % self.rpm_cmd cmd = [self.rpm_cmd] + ["-e", "--nodeps", "--root=%s" %
cmd += "--root=%s " % self.target_rootfs self.target_rootfs, "--dbpath=/var/lib/rpm",
cmd += "--dbpath=/var/lib/rpm " "--define='_cross_scriptlet_wrapper %s'" %
cmd += "--define='_cross_scriptlet_wrapper %s' " % \ self.scriptlet_wrapper,
self.scriptlet_wrapper "--define='_tmppath /%s/tmp'" % self.install_dir_name] + pkgs
cmd += "--define='_tmppath /%s/tmp' %s" % (self.install_dir_name, ' '.join(pkgs))
else: else:
# for pkg in pkgs: # for pkg in pkgs:
# bb.note('Debug: What required: %s' % pkg) # bb.note('Debug: What required: %s' % pkg)
# bb.note(self._invoke_smart('query %s --show-requiredby' % pkg)) # bb.note(self._invoke_smart(['query', pkg, '--show-requiredby']))
cmd = [self.smart_cmd] + self.smart_opt + ["remove", "-y"] + pkgs
cmd = "%s %s remove -y %s" % (self.smart_cmd,
self.smart_opt,
' '.join(pkgs))
try: try:
bb.note(cmd) bb.note(' '.join(cmd))
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).decode("utf-8") output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8")
bb.note(output) bb.note(output)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
bb.note("Unable to remove packages. Command '%s' " bb.note("Unable to remove packages. Command '%s' "
@@ -1254,7 +1251,7 @@ class RpmPM(PackageManager):
def upgrade(self): def upgrade(self):
bb.note('smart upgrade') bb.note('smart upgrade')
self._invoke_smart('upgrade') self._invoke_smart(['upgrade'])
def write_index(self): def write_index(self):
result = self.indexer.write_index() result = self.indexer.write_index()
@@ -1307,25 +1304,24 @@ class RpmPM(PackageManager):
pkgs = self._pkg_translate_oe_to_smart(pkgs, False) pkgs = self._pkg_translate_oe_to_smart(pkgs, False)
install_pkgs = list() install_pkgs = list()
cmd = "%s %s install -y --dump %s 2>%s" % \ cmd = [self.smart_cmd] + self.smart_opt + ['install', '-y', '--dump'] + pkgs
(self.smart_cmd,
self.smart_opt,
' '.join(pkgs),
self.solution_manifest)
try: try:
# Disable rpmsys channel for the fake install # Disable rpmsys channel for the fake install
self._invoke_smart('channel --disable rpmsys') self._invoke_smart(['channel', '--disable', 'rpmsys'])
subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) output = subprocess.check_output(cmd,stderr=subprocess.STDOUT).decode('utf-8')
f = open(self.solution_manifest, 'w')
f.write(output)
f.close()
with open(self.solution_manifest, 'r') as manifest: with open(self.solution_manifest, 'r') as manifest:
for pkg in manifest.read().split('\n'): for pkg in manifest.read().split('\n'):
if '@' in pkg: if '@' in pkg:
install_pkgs.append(pkg) install_pkgs.append(pkg.strip())
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
bb.note("Unable to dump install packages. Command '%s' " bb.note("Unable to dump install packages. Command '%s' "
"returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8")))
# Recovery rpmsys channel # Recovery rpmsys channel
self._invoke_smart('channel --enable rpmsys') self._invoke_smart(['channel', '--enable', 'rpmsys'])
return install_pkgs return install_pkgs
''' '''
@@ -1355,17 +1351,16 @@ class RpmPM(PackageManager):
def dump_all_available_pkgs(self): def dump_all_available_pkgs(self):
available_manifest = self.d.expand('${T}/saved/available_pkgs.txt') available_manifest = self.d.expand('${T}/saved/available_pkgs.txt')
available_pkgs = list() available_pkgs = list()
cmd = "%s %s query --output %s" % \ cmd = [self.smart_cmd] + self.smart_opt + ['query', '--output', available_manifest]
(self.smart_cmd, self.smart_opt, available_manifest)
try: try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) subprocess.check_output(cmd, stderr=subprocess.STDOUT)
with open(available_manifest, 'r') as manifest: with open(available_manifest, 'r') as manifest:
for pkg in manifest.read().split('\n'): for pkg in manifest.read().split('\n'):
if '@' in pkg: if '@' in pkg:
available_pkgs.append(pkg.strip()) available_pkgs.append(pkg.strip())
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
bb.note("Unable to list all available packages. Command '%s' " bb.note("Unable to list all available packages. Command '%s' "
"returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
self.fullpkglist = available_pkgs self.fullpkglist = available_pkgs
@@ -1404,11 +1399,11 @@ class RpmPM(PackageManager):
bb.utils.remove(os.path.join(self.target_rootfs, 'var/lib/smart'), bb.utils.remove(os.path.join(self.target_rootfs, 'var/lib/smart'),
True) True)
self._invoke_smart('config --set rpm-nolinktos=1') self._invoke_smart(['config', '--set', 'rpm-nolinktos=1'])
self._invoke_smart('config --set rpm-noparentdirs=1') self._invoke_smart(['config', '--set', 'rpm-noparentdirs=1'])
for i in self.d.getVar('BAD_RECOMMENDATIONS', True).split(): for i in self.d.getVar('BAD_RECOMMENDATIONS', True).split():
self._invoke_smart('flag --set ignore-recommends %s' % i) self._invoke_smart(['flag', '--set', 'ignore-recommends', i])
self._invoke_smart('channel --add rpmsys type=rpm-sys -y') self._invoke_smart(['channel', '--add', 'rpmsys', 'type=rpm-sys', '-y'])
''' '''
The rpm db lock files were produced after invoking rpm to query on The rpm db lock files were produced after invoking rpm to query on
@@ -1425,12 +1420,12 @@ class RpmPM(PackageManager):
Returns a dictionary with the package info. Returns a dictionary with the package info.
""" """
def package_info(self, pkg): def package_info(self, pkg):
cmd = "%s %s info --urls %s" % (self.smart_cmd, self.smart_opt, pkg) cmd = [self.smart_cmd] + self.smart_opt + ['info', '--urls', pkg]
try: try:
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).decode("utf-8") output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8")
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
bb.fatal("Unable to list available packages. Command '%s' " bb.fatal("Unable to list available packages. Command '%s' "
"returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
# Set default values to avoid UnboundLocalError # Set default values to avoid UnboundLocalError
arch = "" arch = ""
@@ -1550,18 +1545,18 @@ class OpkgDpkgPM(PackageManager):
os.chdir(tmp_dir) os.chdir(tmp_dir)
try: try:
cmd = "%s x %s" % (ar_cmd, pkg_path) cmd = [ar_cmd, 'x', pkg_path]
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
cmd = "%s xf data.tar.*" % tar_cmd cmd = [tar_cmd, 'xf', 'data.tar.*']
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
bb.utils.remove(tmp_dir, recurse=True) bb.utils.remove(tmp_dir, recurse=True)
bb.fatal("Unable to extract %s package. Command '%s' " bb.fatal("Unable to extract %s package. Command '%s' "
"returned %d:\n%s" % (pkg_path, cmd, e.returncode, e.output.decode("utf-8"))) "returned %d:\n%s" % (pkg_path, ' '.join(cmd), e.returncode, e.output.decode("utf-8")))
except OSError as e: except OSError as e:
bb.utils.remove(tmp_dir, recurse=True) bb.utils.remove(tmp_dir, recurse=True)
bb.fatal("Unable to extract %s package. Command '%s' " bb.fatal("Unable to extract %s package. Command '%s' "
"returned %d:\n%s at %s" % (pkg_path, cmd, e.errno, e.strerror, e.filename)) "returned %d:\n%s at %s" % (pkg_path, ' '.join(cmd), e.errno, e.strerror, e.filename))
bb.note("Extracted %s to %s" % (pkg_path, tmp_dir)) bb.note("Extracted %s to %s" % (pkg_path, tmp_dir))
bb.utils.remove(os.path.join(tmp_dir, "debian-binary")) bb.utils.remove(os.path.join(tmp_dir, "debian-binary"))