summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/package_manager.py
diff options
context:
space:
mode:
authorStephano Cetola <stephano.cetola@linux.intel.com>2016-12-06 07:30:59 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-12-08 10:31:30 +0000
commitd8fbaebc482f0e8556077006b8fac43db8927793 (patch)
tree781537a2885b0fe0bf5933797a13a42e6aa86838 /meta/lib/oe/package_manager.py
parent56b4aa820c3e8a7755ca5e41866d1015f025ad46 (diff)
downloadpoky-d8fbaebc482f0e8556077006b8fac43db8927793.tar.gz
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) 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>
Diffstat (limited to 'meta/lib/oe/package_manager.py')
-rw-r--r--meta/lib/oe/package_manager.py233
1 files changed, 114 insertions, 119 deletions
diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py
index 7ba2e4d332..e5e3c3b679 100644
--- a/meta/lib/oe/package_manager.py
+++ b/meta/lib/oe/package_manager.py
@@ -358,12 +358,11 @@ class RpmPkgsList(PkgsList):
358 RpmIndexer(d, rootfs_dir).get_ml_prefix_and_os_list(arch_var, os_var) 358 RpmIndexer(d, rootfs_dir).get_ml_prefix_and_os_list(arch_var, os_var)
359 359
360 # Determine rpm version 360 # Determine rpm version
361 cmd = "%s --version" % self.rpm_cmd
362 try: 361 try:
363 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).decode("utf-8") 362 output = subprocess.check_output([self.rpm_cmd, "--version"], stderr=subprocess.STDOUT).decode("utf-8")
364 except subprocess.CalledProcessError as e: 363 except subprocess.CalledProcessError as e:
365 bb.fatal("Getting rpm version failed. Command '%s' " 364 bb.fatal("Getting rpm version failed. Command '%s' "
366 "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) 365 "returned %d:\n%s" % (self.rpm_cmd, e.returncode, e.output.decode("utf-8")))
367 366
368 ''' 367 '''
369 Translate the RPM/Smart format names to the OE multilib format names 368 Translate the RPM/Smart format names to the OE multilib format names
@@ -412,16 +411,15 @@ class RpmPkgsList(PkgsList):
412 return output 411 return output
413 412
414 def list_pkgs(self): 413 def list_pkgs(self):
415 cmd = self.rpm_cmd + ' --root ' + self.rootfs_dir 414 cmd = [self.rpm_cmd, '--root', self.rootfs_dir]
416 cmd += ' -D "_dbpath /var/lib/rpm" -qa' 415 cmd.extend(['-D', '_dbpath /var/lib/rpm'])
417 cmd += " --qf '[%{NAME} %{ARCH} %{VERSION} %{PACKAGEORIGIN}\n]'" 416 cmd.extend(['-qa', '--qf', '[%{NAME} %{ARCH} %{VERSION} %{PACKAGEORIGIN}\n]'])
418 417
419 try: 418 try:
420 # bb.note(cmd) 419 tmp_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip().decode("utf-8")
421 tmp_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).strip().decode("utf-8")
422 except subprocess.CalledProcessError as e: 420 except subprocess.CalledProcessError as e:
423 bb.fatal("Cannot get the installed packages list. Command '%s' " 421 bb.fatal("Cannot get the installed packages list. Command '%s' "
424 "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) 422 "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
425 423
426 output = dict() 424 output = dict()
427 deps = dict() 425 deps = dict()
@@ -672,11 +670,11 @@ class RpmPM(PackageManager):
672 # 2 = --log-level=debug 670 # 2 = --log-level=debug
673 # 3 = --log-level=debug plus dumps of scriplet content and command invocation 671 # 3 = --log-level=debug plus dumps of scriplet content and command invocation
674 self.debug_level = int(d.getVar('ROOTFS_RPM_DEBUG', True) or "0") 672 self.debug_level = int(d.getVar('ROOTFS_RPM_DEBUG', True) or "0")
675 self.smart_opt = "--log-level=%s --data-dir=%s" % \ 673 self.smart_opt = ["--log-level=%s" %
676 ("warning" if self.debug_level == 0 else 674 ("warning" if self.debug_level == 0 else
677 "info" if self.debug_level == 1 else 675 "info" if self.debug_level == 1 else
678 "debug", 676 "debug"), "--data-dir=%s" %
679 os.path.join(target_rootfs, 'var/lib/smart')) 677 os.path.join(target_rootfs, 'var/lib/smart')]
680 self.scriptlet_wrapper = self.d.expand('${WORKDIR}/scriptlet_wrapper') 678 self.scriptlet_wrapper = self.d.expand('${WORKDIR}/scriptlet_wrapper')
681 self.solution_manifest = self.d.expand('${T}/saved/%s_solution' % 679 self.solution_manifest = self.d.expand('${T}/saved/%s_solution' %
682 self.task_name) 680 self.task_name)
@@ -732,18 +730,18 @@ class RpmPM(PackageManager):
732 for arch in arch_list: 730 for arch in arch_list:
733 bb.note('Adding Smart channel url%d%s (%s)' % 731 bb.note('Adding Smart channel url%d%s (%s)' %
734 (uri_iterator, arch, channel_priority)) 732 (uri_iterator, arch, channel_priority))
735 self._invoke_smart('channel --add url%d-%s type=rpm-md baseurl=%s/%s -y' 733 self._invoke_smart(['channel', '--add', 'url%d-%s' % (uri_iterator, arch),
736 % (uri_iterator, arch, uri, arch)) 734 'type=rpm-md', 'baseurl=%s/%s' % (uri, arch), '-y'])
737 self._invoke_smart('channel --set url%d-%s priority=%d' % 735 self._invoke_smart(['channel', '--set', 'url%d-%s' % (uri_iterator, arch),
738 (uri_iterator, arch, channel_priority)) 736 'priority=%d' % channel_priority])
739 channel_priority -= 5 737 channel_priority -= 5
740 else: 738 else:
741 bb.note('Adding Smart channel url%d (%s)' % 739 bb.note('Adding Smart channel url%d (%s)' %
742 (uri_iterator, channel_priority)) 740 (uri_iterator, channel_priority))
743 self._invoke_smart('channel --add url%d type=rpm-md baseurl=%s -y' 741 self._invoke_smart(['channel', '--add', 'url%d' % uri_iterator,
744 % (uri_iterator, uri)) 742 'type=rpm-md', 'baseurl=%s' % uri, '-y'])
745 self._invoke_smart('channel --set url%d priority=%d' % 743 self._invoke_smart(['channel', '--set', 'url%d' % uri_iterator,
746 (uri_iterator, channel_priority)) 744 'priority=%d' % channel_priority])
747 channel_priority -= 5 745 channel_priority -= 5
748 746
749 uri_iterator += 1 747 uri_iterator += 1
@@ -774,18 +772,17 @@ class RpmPM(PackageManager):
774 772
775 self._create_configs(platform, platform_extra) 773 self._create_configs(platform, platform_extra)
776 774
775 #takes array args
777 def _invoke_smart(self, args): 776 def _invoke_smart(self, args):
778 cmd = "%s %s %s" % (self.smart_cmd, self.smart_opt, args) 777 cmd = [self.smart_cmd] + self.smart_opt + args
779 # bb.note(cmd) 778 # bb.note(cmd)
780 try: 779 try:
781 complementary_pkgs = subprocess.check_output(cmd, 780 complementary_pkgs = subprocess.check_output(cmd,stderr=subprocess.STDOUT).decode("utf-8")
782 stderr=subprocess.STDOUT,
783 shell=True).decode("utf-8")
784 # bb.note(complementary_pkgs) 781 # bb.note(complementary_pkgs)
785 return complementary_pkgs 782 return complementary_pkgs
786 except subprocess.CalledProcessError as e: 783 except subprocess.CalledProcessError as e:
787 bb.fatal("Could not invoke smart. Command " 784 bb.fatal("Could not invoke smart. Command "
788 "'%s' returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) 785 "'%s' returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
789 786
790 def _search_pkg_name_in_feeds(self, pkg, feed_archs): 787 def _search_pkg_name_in_feeds(self, pkg, feed_archs):
791 for arch in feed_archs: 788 for arch in feed_archs:
@@ -800,19 +797,23 @@ class RpmPM(PackageManager):
800 797
801 # Search provides if not found by pkgname. 798 # Search provides if not found by pkgname.
802 bb.note('Not found %s by name, searching provides ...' % pkg) 799 bb.note('Not found %s by name, searching provides ...' % pkg)
803 cmd = "%s %s query --provides %s --show-format='$name-$version'" % \ 800 cmd = [self.smart_cmd] + self.smart_opt + ["query", "--provides", pkg,
804 (self.smart_cmd, self.smart_opt, pkg) 801 "--show-format=$name-$version"]
805 cmd += " | sed -ne 's/ *Provides://p'" 802 bb.note('cmd: %s' % ' '.join(cmd))
806 bb.note('cmd: %s' % cmd) 803 ps = subprocess.Popen(cmd, stdout=subprocess.PIPE)
807 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).decode("utf-8") 804 try:
808 # Found a provider 805 output = subprocess.check_output(["sed", "-ne", "s/ *Provides://p"],
809 if output: 806 stdin=ps.stdout, stderr=subprocess.STDOUT).decode("utf-8")
810 bb.note('Found providers for %s: %s' % (pkg, output)) 807 # Found a provider
811 for p in output.split(): 808 if output:
812 for arch in feed_archs: 809 bb.note('Found providers for %s: %s' % (pkg, output))
813 arch = arch.replace('-', '_') 810 for p in output.split():
814 if p.rstrip().endswith('@' + arch): 811 for arch in feed_archs:
815 return p 812 arch = arch.replace('-', '_')
813 if p.rstrip().endswith('@' + arch):
814 return p
815 except subprocess.CalledProcessError as e:
816 bb.error("Failed running smart query on package %s." % pkg)
816 817
817 return "" 818 return ""
818 819
@@ -949,30 +950,32 @@ class RpmPM(PackageManager):
949 open(db_config_dir, 'w+').write(DB_CONFIG_CONTENT) 950 open(db_config_dir, 'w+').write(DB_CONFIG_CONTENT)
950 951
951 # Create database so that smart doesn't complain (lazy init) 952 # Create database so that smart doesn't complain (lazy init)
952 opt = "-qa" 953 cmd = [self.rpm_cmd, '--root', self.target_rootfs, '--dbpath', '/var/lib/rpm', '-qa']
953 cmd = "%s --root %s --dbpath /var/lib/rpm %s > /dev/null" % (
954 self.rpm_cmd, self.target_rootfs, opt)
955 try: 954 try:
956 subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) 955 subprocess.check_output(cmd, stderr=subprocess.STDOUT)
957 except subprocess.CalledProcessError as e: 956 except subprocess.CalledProcessError as e:
958 bb.fatal("Create rpm database failed. Command '%s' " 957 bb.fatal("Create rpm database failed. Command '%s' "
959 "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) 958 "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
960 # Import GPG key to RPM database of the target system 959 # Import GPG key to RPM database of the target system
961 if self.d.getVar('RPM_SIGN_PACKAGES', True) == '1': 960 if self.d.getVar('RPM_SIGN_PACKAGES', True) == '1':
962 pubkey_path = self.d.getVar('RPM_GPG_PUBKEY', True) 961 pubkey_path = self.d.getVar('RPM_GPG_PUBKEY', True)
963 cmd = "%s --root %s --dbpath /var/lib/rpm --import %s > /dev/null" % ( 962 cmd = [self.rpm_cmd, '--root', self.target_rootfs, '--dbpath', '/var/lib/rpm', '--import', pubkey_path]
964 self.rpm_cmd, self.target_rootfs, pubkey_path) 963 try:
965 subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) 964 subprocess.check_output(cmd, stderr=subprocess.STDOUT)
965 except subprocess.CalledProcessError as e:
966 bb.fatal("Import GPG key failed. Command '%s' "
967 "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
968
966 969
967 # Configure smart 970 # Configure smart
968 bb.note("configuring Smart settings") 971 bb.note("configuring Smart settings")
969 bb.utils.remove(os.path.join(self.target_rootfs, 'var/lib/smart'), 972 bb.utils.remove(os.path.join(self.target_rootfs, 'var/lib/smart'),
970 True) 973 True)
971 self._invoke_smart('config --set rpm-root=%s' % self.target_rootfs) 974 self._invoke_smart(['config', '--set', 'rpm-root=%s' % self.target_rootfs])
972 self._invoke_smart('config --set rpm-dbpath=/var/lib/rpm') 975 self._invoke_smart(['config', '--set', 'rpm-dbpath=/var/lib/rpm'])
973 self._invoke_smart('config --set rpm-extra-macros._var=%s' % 976 self._invoke_smart(['config', '--set', 'rpm-extra-macros._var=%s' %
974 self.d.getVar('localstatedir', True)) 977 self.d.getVar('localstatedir', True)])
975 cmd = "config --set rpm-extra-macros._tmppath=/%s/tmp" % (self.install_dir_name) 978 cmd = ["config", "--set", "rpm-extra-macros._tmppath=/%s/tmp" % self.install_dir_name]
976 979
977 prefer_color = self.d.getVar('RPM_PREFER_ELF_ARCH', True) 980 prefer_color = self.d.getVar('RPM_PREFER_ELF_ARCH', True)
978 if prefer_color: 981 if prefer_color:
@@ -986,32 +989,32 @@ class RpmPM(PackageManager):
986 ['mips64', 'mips64el']: 989 ['mips64', 'mips64el']:
987 bb.fatal("RPM_PREFER_ELF_ARCH = \"4\" is for mips64 or mips64el " 990 bb.fatal("RPM_PREFER_ELF_ARCH = \"4\" is for mips64 or mips64el "
988 "only.") 991 "only.")
989 self._invoke_smart('config --set rpm-extra-macros._prefer_color=%s' 992 self._invoke_smart(['config', '--set', 'rpm-extra-macros._prefer_color=%s'
990 % prefer_color) 993 % prefer_color])
991 994
992 self._invoke_smart(cmd) 995 self._invoke_smart(cmd)
993 self._invoke_smart('config --set rpm-ignoresize=1') 996 self._invoke_smart(['config', '--set', 'rpm-ignoresize=1'])
994 997
995 # Write common configuration for host and target usage 998 # Write common configuration for host and target usage
996 self._invoke_smart('config --set rpm-nolinktos=1') 999 self._invoke_smart(['config', '--set', 'rpm-nolinktos=1'])
997 self._invoke_smart('config --set rpm-noparentdirs=1') 1000 self._invoke_smart(['config', '--set', 'rpm-noparentdirs=1'])
998 check_signature = self.d.getVar('RPM_CHECK_SIGNATURES', True) 1001 check_signature = self.d.getVar('RPM_CHECK_SIGNATURES', True)
999 if check_signature and check_signature.strip() == "0": 1002 if check_signature and check_signature.strip() == "0":
1000 self._invoke_smart('config --set rpm-check-signatures=false') 1003 self._invoke_smart(['config', '--set rpm-check-signatures=false'])
1001 for i in self.d.getVar('BAD_RECOMMENDATIONS', True).split(): 1004 for i in self.d.getVar('BAD_RECOMMENDATIONS', True).split():
1002 self._invoke_smart('flag --set ignore-recommends %s' % i) 1005 self._invoke_smart(['flag', '--set', 'ignore-recommends', i])
1003 1006
1004 # Do the following configurations here, to avoid them being 1007 # Do the following configurations here, to avoid them being
1005 # saved for field upgrade 1008 # saved for field upgrade
1006 if self.d.getVar('NO_RECOMMENDATIONS', True).strip() == "1": 1009 if self.d.getVar('NO_RECOMMENDATIONS', True).strip() == "1":
1007 self._invoke_smart('config --set ignore-all-recommends=1') 1010 self._invoke_smart(['config', '--set', 'ignore-all-recommends=1'])
1008 pkg_exclude = self.d.getVar('PACKAGE_EXCLUDE', True) or "" 1011 pkg_exclude = self.d.getVar('PACKAGE_EXCLUDE', True) or ""
1009 for i in pkg_exclude.split(): 1012 for i in pkg_exclude.split():
1010 self._invoke_smart('flag --set exclude-packages %s' % i) 1013 self._invoke_smart(['flag', '--set', 'exclude-packages', i])
1011 1014
1012 # Optional debugging 1015 # Optional debugging
1013 # self._invoke_smart('config --set rpm-log-level=debug') 1016 # self._invoke_smart(['config', '--set', 'rpm-log-level=debug'])
1014 # cmd = 'config --set rpm-log-file=/tmp/smart-debug-logfile' 1017 # cmd = ['config', '--set', 'rpm-log-file=/tmp/smart-debug-logfile']
1015 # self._invoke_smart(cmd) 1018 # self._invoke_smart(cmd)
1016 ch_already_added = [] 1019 ch_already_added = []
1017 for canonical_arch in platform_extra: 1020 for canonical_arch in platform_extra:
@@ -1030,16 +1033,16 @@ class RpmPM(PackageManager):
1030 if not arch in ch_already_added: 1033 if not arch in ch_already_added:
1031 bb.note('Adding Smart channel %s (%s)' % 1034 bb.note('Adding Smart channel %s (%s)' %
1032 (arch, channel_priority)) 1035 (arch, channel_priority))
1033 self._invoke_smart('channel --add %s type=rpm-md baseurl=%s -y' 1036 self._invoke_smart(['channel', '--add', arch, 'type=rpm-md',
1034 % (arch, arch_channel)) 1037 'baseurl=%s' % arch_channel, '-y'])
1035 self._invoke_smart('channel --set %s priority=%d' % 1038 self._invoke_smart(['channel', '--set', arch, 'priority=%d' %
1036 (arch, channel_priority)) 1039 channel_priority])
1037 channel_priority -= 5 1040 channel_priority -= 5
1038 1041
1039 ch_already_added.append(arch) 1042 ch_already_added.append(arch)
1040 1043
1041 bb.note('adding Smart RPM DB channel') 1044 bb.note('adding Smart RPM DB channel')
1042 self._invoke_smart('channel --add rpmsys type=rpm-sys -y') 1045 self._invoke_smart(['channel', '--add', 'rpmsys', 'type=rpm-sys', '-y'])
1043 1046
1044 # Construct install scriptlet wrapper. 1047 # Construct install scriptlet wrapper.
1045 # Scripts need to be ordered when executed, this ensures numeric order. 1048 # Scripts need to be ordered when executed, this ensures numeric order.
@@ -1102,15 +1105,15 @@ class RpmPM(PackageManager):
1102 1105
1103 bb.note("configuring RPM cross-install scriptlet_wrapper") 1106 bb.note("configuring RPM cross-install scriptlet_wrapper")
1104 os.chmod(self.scriptlet_wrapper, 0o755) 1107 os.chmod(self.scriptlet_wrapper, 0o755)
1105 cmd = 'config --set rpm-extra-macros._cross_scriptlet_wrapper=%s' % \ 1108 cmd = ['config', '--set', 'rpm-extra-macros._cross_scriptlet_wrapper=%s' %
1106 self.scriptlet_wrapper 1109 self.scriptlet_wrapper]
1107 self._invoke_smart(cmd) 1110 self._invoke_smart(cmd)
1108 1111
1109 # Debug to show smart config info 1112 # Debug to show smart config info
1110 # bb.note(self._invoke_smart('config --show')) 1113 # bb.note(self._invoke_smart(['config', '--show']))
1111 1114
1112 def update(self): 1115 def update(self):
1113 self._invoke_smart('update rpmsys') 1116 self._invoke_smart(['update', 'rpmsys'])
1114 1117
1115 def get_rdepends_recursively(self, pkgs): 1118 def get_rdepends_recursively(self, pkgs):
1116 # pkgs will be changed during the loop, so use [:] to make a copy. 1119 # pkgs will be changed during the loop, so use [:] to make a copy.
@@ -1207,20 +1210,19 @@ class RpmPM(PackageManager):
1207 return 1210 return
1208 if not attempt_only: 1211 if not attempt_only:
1209 bb.note('to be installed: %s' % ' '.join(pkgs)) 1212 bb.note('to be installed: %s' % ' '.join(pkgs))
1210 cmd = "%s %s install -y %s" % \ 1213 cmd = [self.smart_cmd] + self.smart_opt + ["install", "-y"] + pkgs
1211 (self.smart_cmd, self.smart_opt, ' '.join(pkgs)) 1214 bb.note(' '.join(cmd))
1212 bb.note(cmd)
1213 else: 1215 else:
1214 bb.note('installing attempt only packages...') 1216 bb.note('installing attempt only packages...')
1215 bb.note('Attempting %s' % ' '.join(pkgs)) 1217 bb.note('Attempting %s' % ' '.join(pkgs))
1216 cmd = "%s %s install --attempt -y %s" % \ 1218 cmd = [self.smart_cmd] + self.smart_opt + ["install", "--attempt",
1217 (self.smart_cmd, self.smart_opt, ' '.join(pkgs)) 1219 "-y"] + pkgs
1218 try: 1220 try:
1219 output = subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT).decode("utf-8") 1221 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8")
1220 bb.note(output) 1222 bb.note(output)
1221 except subprocess.CalledProcessError as e: 1223 except subprocess.CalledProcessError as e:
1222 bb.fatal("Unable to install packages. Command '%s' " 1224 bb.fatal("Unable to install packages. Command '%s' "
1223 "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) 1225 "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
1224 1226
1225 ''' 1227 '''
1226 Remove pkgs with smart, the pkg name is smart/rpm format 1228 Remove pkgs with smart, the pkg name is smart/rpm format
@@ -1229,24 +1231,19 @@ class RpmPM(PackageManager):
1229 bb.note('to be removed: ' + ' '.join(pkgs)) 1231 bb.note('to be removed: ' + ' '.join(pkgs))
1230 1232
1231 if not with_dependencies: 1233 if not with_dependencies:
1232 cmd = "%s -e --nodeps " % self.rpm_cmd 1234 cmd = [self.rpm_cmd] + ["-e", "--nodeps", "--root=%s" %
1233 cmd += "--root=%s " % self.target_rootfs 1235 self.target_rootfs, "--dbpath=/var/lib/rpm",
1234 cmd += "--dbpath=/var/lib/rpm " 1236 "--define='_cross_scriptlet_wrapper %s'" %
1235 cmd += "--define='_cross_scriptlet_wrapper %s' " % \ 1237 self.scriptlet_wrapper,
1236 self.scriptlet_wrapper 1238 "--define='_tmppath /%s/tmp'" % self.install_dir_name] + pkgs
1237 cmd += "--define='_tmppath /%s/tmp' %s" % (self.install_dir_name, ' '.join(pkgs))
1238 else: 1239 else:
1239 # for pkg in pkgs: 1240 # for pkg in pkgs:
1240 # bb.note('Debug: What required: %s' % pkg) 1241 # bb.note('Debug: What required: %s' % pkg)
1241 # bb.note(self._invoke_smart('query %s --show-requiredby' % pkg)) 1242 # bb.note(self._invoke_smart(['query', pkg, '--show-requiredby']))
1242 1243 cmd = [self.smart_cmd] + self.smart_opt + ["remove", "-y"] + pkgs
1243 cmd = "%s %s remove -y %s" % (self.smart_cmd,
1244 self.smart_opt,
1245 ' '.join(pkgs))
1246
1247 try: 1244 try:
1248 bb.note(cmd) 1245 bb.note(' '.join(cmd))
1249 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).decode("utf-8") 1246 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8")
1250 bb.note(output) 1247 bb.note(output)
1251 except subprocess.CalledProcessError as e: 1248 except subprocess.CalledProcessError as e:
1252 bb.note("Unable to remove packages. Command '%s' " 1249 bb.note("Unable to remove packages. Command '%s' "
@@ -1254,7 +1251,7 @@ class RpmPM(PackageManager):
1254 1251
1255 def upgrade(self): 1252 def upgrade(self):
1256 bb.note('smart upgrade') 1253 bb.note('smart upgrade')
1257 self._invoke_smart('upgrade') 1254 self._invoke_smart(['upgrade'])
1258 1255
1259 def write_index(self): 1256 def write_index(self):
1260 result = self.indexer.write_index() 1257 result = self.indexer.write_index()
@@ -1307,25 +1304,24 @@ class RpmPM(PackageManager):
1307 pkgs = self._pkg_translate_oe_to_smart(pkgs, False) 1304 pkgs = self._pkg_translate_oe_to_smart(pkgs, False)
1308 install_pkgs = list() 1305 install_pkgs = list()
1309 1306
1310 cmd = "%s %s install -y --dump %s 2>%s" % \ 1307 cmd = [self.smart_cmd] + self.smart_opt + ['install', '-y', '--dump'] + pkgs
1311 (self.smart_cmd,
1312 self.smart_opt,
1313 ' '.join(pkgs),
1314 self.solution_manifest)
1315 try: 1308 try:
1316 # Disable rpmsys channel for the fake install 1309 # Disable rpmsys channel for the fake install
1317 self._invoke_smart('channel --disable rpmsys') 1310 self._invoke_smart(['channel', '--disable', 'rpmsys'])
1318 1311
1319 subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) 1312 output = subprocess.check_output(cmd,stderr=subprocess.STDOUT).decode('utf-8')
1313 f = open(self.solution_manifest, 'w')
1314 f.write(output)
1315 f.close()
1320 with open(self.solution_manifest, 'r') as manifest: 1316 with open(self.solution_manifest, 'r') as manifest:
1321 for pkg in manifest.read().split('\n'): 1317 for pkg in manifest.read().split('\n'):
1322 if '@' in pkg: 1318 if '@' in pkg:
1323 install_pkgs.append(pkg) 1319 install_pkgs.append(pkg.strip())
1324 except subprocess.CalledProcessError as e: 1320 except subprocess.CalledProcessError as e:
1325 bb.note("Unable to dump install packages. Command '%s' " 1321 bb.note("Unable to dump install packages. Command '%s' "
1326 "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) 1322 "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8")))
1327 # Recovery rpmsys channel 1323 # Recovery rpmsys channel
1328 self._invoke_smart('channel --enable rpmsys') 1324 self._invoke_smart(['channel', '--enable', 'rpmsys'])
1329 return install_pkgs 1325 return install_pkgs
1330 1326
1331 ''' 1327 '''
@@ -1355,17 +1351,16 @@ class RpmPM(PackageManager):
1355 def dump_all_available_pkgs(self): 1351 def dump_all_available_pkgs(self):
1356 available_manifest = self.d.expand('${T}/saved/available_pkgs.txt') 1352 available_manifest = self.d.expand('${T}/saved/available_pkgs.txt')
1357 available_pkgs = list() 1353 available_pkgs = list()
1358 cmd = "%s %s query --output %s" % \ 1354 cmd = [self.smart_cmd] + self.smart_opt + ['query', '--output', available_manifest]
1359 (self.smart_cmd, self.smart_opt, available_manifest)
1360 try: 1355 try:
1361 subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) 1356 subprocess.check_output(cmd, stderr=subprocess.STDOUT)
1362 with open(available_manifest, 'r') as manifest: 1357 with open(available_manifest, 'r') as manifest:
1363 for pkg in manifest.read().split('\n'): 1358 for pkg in manifest.read().split('\n'):
1364 if '@' in pkg: 1359 if '@' in pkg:
1365 available_pkgs.append(pkg.strip()) 1360 available_pkgs.append(pkg.strip())
1366 except subprocess.CalledProcessError as e: 1361 except subprocess.CalledProcessError as e:
1367 bb.note("Unable to list all available packages. Command '%s' " 1362 bb.note("Unable to list all available packages. Command '%s' "
1368 "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) 1363 "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
1369 1364
1370 self.fullpkglist = available_pkgs 1365 self.fullpkglist = available_pkgs
1371 1366
@@ -1404,11 +1399,11 @@ class RpmPM(PackageManager):
1404 bb.utils.remove(os.path.join(self.target_rootfs, 'var/lib/smart'), 1399 bb.utils.remove(os.path.join(self.target_rootfs, 'var/lib/smart'),
1405 True) 1400 True)
1406 1401
1407 self._invoke_smart('config --set rpm-nolinktos=1') 1402 self._invoke_smart(['config', '--set', 'rpm-nolinktos=1'])
1408 self._invoke_smart('config --set rpm-noparentdirs=1') 1403 self._invoke_smart(['config', '--set', 'rpm-noparentdirs=1'])
1409 for i in self.d.getVar('BAD_RECOMMENDATIONS', True).split(): 1404 for i in self.d.getVar('BAD_RECOMMENDATIONS', True).split():
1410 self._invoke_smart('flag --set ignore-recommends %s' % i) 1405 self._invoke_smart(['flag', '--set', 'ignore-recommends', i])
1411 self._invoke_smart('channel --add rpmsys type=rpm-sys -y') 1406 self._invoke_smart(['channel', '--add', 'rpmsys', 'type=rpm-sys', '-y'])
1412 1407
1413 ''' 1408 '''
1414 The rpm db lock files were produced after invoking rpm to query on 1409 The rpm db lock files were produced after invoking rpm to query on
@@ -1425,12 +1420,12 @@ class RpmPM(PackageManager):
1425 Returns a dictionary with the package info. 1420 Returns a dictionary with the package info.
1426 """ 1421 """
1427 def package_info(self, pkg): 1422 def package_info(self, pkg):
1428 cmd = "%s %s info --urls %s" % (self.smart_cmd, self.smart_opt, pkg) 1423 cmd = [self.smart_cmd] + self.smart_opt + ['info', '--urls', pkg]
1429 try: 1424 try:
1430 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).decode("utf-8") 1425 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8")
1431 except subprocess.CalledProcessError as e: 1426 except subprocess.CalledProcessError as e:
1432 bb.fatal("Unable to list available packages. Command '%s' " 1427 bb.fatal("Unable to list available packages. Command '%s' "
1433 "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) 1428 "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
1434 1429
1435 # Set default values to avoid UnboundLocalError 1430 # Set default values to avoid UnboundLocalError
1436 arch = "" 1431 arch = ""
@@ -1550,18 +1545,18 @@ class OpkgDpkgPM(PackageManager):
1550 os.chdir(tmp_dir) 1545 os.chdir(tmp_dir)
1551 1546
1552 try: 1547 try:
1553 cmd = "%s x %s" % (ar_cmd, pkg_path) 1548 cmd = [ar_cmd, 'x', pkg_path]
1554 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) 1549 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
1555 cmd = "%s xf data.tar.*" % tar_cmd 1550 cmd = [tar_cmd, 'xf', 'data.tar.*']
1556 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) 1551 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
1557 except subprocess.CalledProcessError as e: 1552 except subprocess.CalledProcessError as e:
1558 bb.utils.remove(tmp_dir, recurse=True) 1553 bb.utils.remove(tmp_dir, recurse=True)
1559 bb.fatal("Unable to extract %s package. Command '%s' " 1554 bb.fatal("Unable to extract %s package. Command '%s' "
1560 "returned %d:\n%s" % (pkg_path, cmd, e.returncode, e.output.decode("utf-8"))) 1555 "returned %d:\n%s" % (pkg_path, ' '.join(cmd), e.returncode, e.output.decode("utf-8")))
1561 except OSError as e: 1556 except OSError as e:
1562 bb.utils.remove(tmp_dir, recurse=True) 1557 bb.utils.remove(tmp_dir, recurse=True)
1563 bb.fatal("Unable to extract %s package. Command '%s' " 1558 bb.fatal("Unable to extract %s package. Command '%s' "
1564 "returned %d:\n%s at %s" % (pkg_path, cmd, e.errno, e.strerror, e.filename)) 1559 "returned %d:\n%s at %s" % (pkg_path, ' '.join(cmd), e.errno, e.strerror, e.filename))
1565 1560
1566 bb.note("Extracted %s to %s" % (pkg_path, tmp_dir)) 1561 bb.note("Extracted %s to %s" % (pkg_path, tmp_dir))
1567 bb.utils.remove(os.path.join(tmp_dir, "debian-binary")) 1562 bb.utils.remove(os.path.join(tmp_dir, "debian-binary"))