diff options
author | Hongxu Jia <hongxu.jia@windriver.com> | 2014-02-21 14:12:52 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-02-21 16:14:15 +0000 |
commit | af9e8e9132954aa1013ae22355054c9dea4524b3 (patch) | |
tree | e4605d9e0c596db7543418d2d245cd1e4cbbedb6 | |
parent | f4de8399ba6ddc38656cc1fb08098e7c4588151f (diff) | |
download | poky-af9e8e9132954aa1013ae22355054c9dea4524b3.tar.gz |
package_manager.py: support ipk incremental image generation
Add the following three functions to OpkgPM class:
- The 'dummy_install' is used to dummy install pkgs, and returns the log
of output;
- The 'backup_packaging_data' is used to back up the current opkg
database;
- The 'recover_packaging_data' is used to recover the opkg database
which backed up by the previous image creation;
Tweak 'remove' function in OpkgPM class, which the options for remove
with dependencies was incorrect.
Tweak 'handle_bad_recommendations' function in OpkgPM class:
- Fix none value check;
- Add the existance check of opkg status file;
[YOCTO #1894]
(From OE-Core rev: 5df18065e267a7e55a990ac3728414bb6e28a723)
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/lib/oe/package_manager.py | 81 |
1 files changed, 75 insertions, 6 deletions
diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py index 84d87319a9..b430ee3a62 100644 --- a/meta/lib/oe/package_manager.py +++ b/meta/lib/oe/package_manager.py | |||
@@ -934,12 +934,13 @@ class RpmPM(PackageManager): | |||
934 | 934 | ||
935 | 935 | ||
936 | class OpkgPM(PackageManager): | 936 | class OpkgPM(PackageManager): |
937 | def __init__(self, d, target_rootfs, config_file, archs): | 937 | def __init__(self, d, target_rootfs, config_file, archs, task_name='target'): |
938 | super(OpkgPM, self).__init__(d) | 938 | super(OpkgPM, self).__init__(d) |
939 | 939 | ||
940 | self.target_rootfs = target_rootfs | 940 | self.target_rootfs = target_rootfs |
941 | self.config_file = config_file | 941 | self.config_file = config_file |
942 | self.pkg_archs = archs | 942 | self.pkg_archs = archs |
943 | self.task_name = task_name | ||
943 | 944 | ||
944 | self.deploy_dir = self.d.getVar("DEPLOY_DIR_IPK", True) | 945 | self.deploy_dir = self.d.getVar("DEPLOY_DIR_IPK", True) |
945 | self.deploy_lock_file = os.path.join(self.deploy_dir, "deploy.lock") | 946 | self.deploy_lock_file = os.path.join(self.deploy_dir, "deploy.lock") |
@@ -956,6 +957,10 @@ class OpkgPM(PackageManager): | |||
956 | 957 | ||
957 | bb.utils.mkdirhier(self.opkg_dir) | 958 | bb.utils.mkdirhier(self.opkg_dir) |
958 | 959 | ||
960 | self.saved_opkg_dir = self.d.expand('${T}/saved/%s' % self.task_name) | ||
961 | if not os.path.exists(self.d.expand('${T}/saved')): | ||
962 | bb.utils.mkdirhier(self.d.expand('${T}/saved')) | ||
963 | |||
959 | if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS', True) or "") != "1": | 964 | if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS', True) or "") != "1": |
960 | self._create_config() | 965 | self._create_config() |
961 | else: | 966 | else: |
@@ -1075,7 +1080,9 @@ class OpkgPM(PackageManager): | |||
1075 | 1080 | ||
1076 | try: | 1081 | try: |
1077 | bb.note("Installing the following packages: %s" % ' '.join(pkgs)) | 1082 | bb.note("Installing the following packages: %s" % ' '.join(pkgs)) |
1078 | subprocess.check_output(cmd.split()) | 1083 | bb.note(cmd) |
1084 | output = subprocess.check_output(cmd.split()) | ||
1085 | bb.note(output) | ||
1079 | except subprocess.CalledProcessError as e: | 1086 | except subprocess.CalledProcessError as e: |
1080 | (bb.fatal, bb.note)[attempt_only]("Unable to install packages. " | 1087 | (bb.fatal, bb.note)[attempt_only]("Unable to install packages. " |
1081 | "Command '%s' returned %d:\n%s" % | 1088 | "Command '%s' returned %d:\n%s" % |
@@ -1083,14 +1090,16 @@ class OpkgPM(PackageManager): | |||
1083 | 1090 | ||
1084 | def remove(self, pkgs, with_dependencies=True): | 1091 | def remove(self, pkgs, with_dependencies=True): |
1085 | if with_dependencies: | 1092 | if with_dependencies: |
1086 | cmd = "%s %s remove %s" % \ | 1093 | cmd = "%s %s --force-depends --force-remove --force-removal-of-dependent-packages remove %s" % \ |
1087 | (self.opkg_cmd, self.opkg_args, ' '.join(pkgs)) | 1094 | (self.opkg_cmd, self.opkg_args, ' '.join(pkgs)) |
1088 | else: | 1095 | else: |
1089 | cmd = "%s %s --force-depends remove %s" % \ | 1096 | cmd = "%s %s --force-depends remove %s" % \ |
1090 | (self.opkg_cmd, self.opkg_args, ' '.join(pkgs)) | 1097 | (self.opkg_cmd, self.opkg_args, ' '.join(pkgs)) |
1091 | 1098 | ||
1092 | try: | 1099 | try: |
1093 | subprocess.check_output(cmd.split()) | 1100 | bb.note(cmd) |
1101 | output = subprocess.check_output(cmd.split()) | ||
1102 | bb.note(output) | ||
1094 | except subprocess.CalledProcessError as e: | 1103 | except subprocess.CalledProcessError as e: |
1095 | bb.fatal("Unable to remove packages. Command '%s' " | 1104 | bb.fatal("Unable to remove packages. Command '%s' " |
1096 | "returned %d:\n%s" % (e.cmd, e.returncode, e.output)) | 1105 | "returned %d:\n%s" % (e.cmd, e.returncode, e.output)) |
@@ -1147,12 +1156,17 @@ class OpkgPM(PackageManager): | |||
1147 | return output | 1156 | return output |
1148 | 1157 | ||
1149 | def handle_bad_recommendations(self): | 1158 | def handle_bad_recommendations(self): |
1150 | bad_recommendations = self.d.getVar("BAD_RECOMMENDATIONS", True) | 1159 | bad_recommendations = self.d.getVar("BAD_RECOMMENDATIONS", True) or "" |
1151 | if bad_recommendations is None: | 1160 | if bad_recommendations.strip() == "": |
1152 | return | 1161 | return |
1153 | 1162 | ||
1154 | status_file = os.path.join(self.opkg_dir, "status") | 1163 | status_file = os.path.join(self.opkg_dir, "status") |
1155 | 1164 | ||
1165 | # If status file existed, it means the bad recommendations has already | ||
1166 | # been handled | ||
1167 | if os.path.exists(status_file): | ||
1168 | return | ||
1169 | |||
1156 | cmd = "%s %s info " % (self.opkg_cmd, self.opkg_args) | 1170 | cmd = "%s %s info " % (self.opkg_cmd, self.opkg_args) |
1157 | 1171 | ||
1158 | with open(status_file, "w+") as status: | 1172 | with open(status_file, "w+") as status: |
@@ -1176,6 +1190,61 @@ class OpkgPM(PackageManager): | |||
1176 | else: | 1190 | else: |
1177 | status.write(line + "\n") | 1191 | status.write(line + "\n") |
1178 | 1192 | ||
1193 | ''' | ||
1194 | The following function dummy installs pkgs and returns the log of output. | ||
1195 | ''' | ||
1196 | def dummy_install(self, pkgs): | ||
1197 | if len(pkgs) == 0: | ||
1198 | return | ||
1199 | |||
1200 | # Create an temp dir as opkg root for dummy installation | ||
1201 | temp_rootfs = self.d.expand('${T}/opkg') | ||
1202 | temp_opkg_dir = os.path.join(temp_rootfs, 'var/lib/opkg') | ||
1203 | bb.utils.mkdirhier(temp_opkg_dir) | ||
1204 | |||
1205 | opkg_args = "-f %s -o %s " % (self.config_file, temp_rootfs) | ||
1206 | opkg_args += self.d.getVar("OPKG_ARGS", True) | ||
1207 | |||
1208 | cmd = "%s %s update" % (self.opkg_cmd, opkg_args) | ||
1209 | try: | ||
1210 | subprocess.check_output(cmd, shell=True) | ||
1211 | except subprocess.CalledProcessError as e: | ||
1212 | bb.fatal("Unable to update. Command '%s' " | ||
1213 | "returned %d:\n%s" % (cmd, e.returncode, e.output)) | ||
1214 | |||
1215 | # Dummy installation | ||
1216 | cmd = "%s %s --noaction install %s " % (self.opkg_cmd, | ||
1217 | opkg_args, | ||
1218 | ' '.join(pkgs)) | ||
1219 | try: | ||
1220 | output = subprocess.check_output(cmd, shell=True) | ||
1221 | except subprocess.CalledProcessError as e: | ||
1222 | bb.fatal("Unable to dummy install packages. Command '%s' " | ||
1223 | "returned %d:\n%s" % (cmd, e.returncode, e.output)) | ||
1224 | |||
1225 | bb.utils.remove(temp_rootfs, True) | ||
1226 | |||
1227 | return output | ||
1228 | |||
1229 | def backup_packaging_data(self): | ||
1230 | # Save the opkglib for increment ipk image generation | ||
1231 | if os.path.exists(self.saved_opkg_dir): | ||
1232 | bb.utils.remove(self.saved_opkg_dir, True) | ||
1233 | shutil.copytree(self.opkg_dir, | ||
1234 | self.saved_opkg_dir, | ||
1235 | symlinks=True) | ||
1236 | |||
1237 | def recover_packaging_data(self): | ||
1238 | # Move the opkglib back | ||
1239 | if os.path.exists(self.saved_opkg_dir): | ||
1240 | if os.path.exists(self.opkg_dir): | ||
1241 | bb.utils.remove(self.opkg_dir, True) | ||
1242 | |||
1243 | bb.note('Recover packaging data') | ||
1244 | shutil.copytree(self.saved_opkg_dir, | ||
1245 | self.opkg_dir, | ||
1246 | symlinks=True) | ||
1247 | |||
1179 | 1248 | ||
1180 | class DpkgPM(PackageManager): | 1249 | class DpkgPM(PackageManager): |
1181 | def __init__(self, d, target_rootfs, archs, base_archs, apt_conf_dir=None): | 1250 | def __init__(self, d, target_rootfs, archs, base_archs, apt_conf_dir=None): |