summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorLaurentiu Palcu <laurentiu.palcu@intel.com>2014-01-30 21:40:24 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-02-11 11:53:43 +0000
commit365b77909d8b58b8827474f6b1c68067a21ed27f (patch)
tree2504287b768a91fd17c23e5235c9da941f84b8fb /meta/lib
parentb76f240df03e15282aa9f6ed62ed121fb1657d8a (diff)
downloadpoky-365b77909d8b58b8827474f6b1c68067a21ed27f.tar.gz
lib/oe/package_manager.py: OpkgPM/DpkgPM fixes
This commit: * adds missing mark_packages() function for OpkgPM. This is needed to * manually change the packages installation status in the status file; * fix OpkgPM remove_packaging_data() issue; * fix OpkgPM handle_bad_recommendations() issue; * improve OpkgPM/DpkgPM mark_packages() regex pattern; * fix DpkgPM list_installed() problem; * fix DpkgPM _create_configs() problem: status file should not be truncated if it already exists/ (From OE-Core rev: d50a40100763dcbfabec2c147fdfcb46aa909329) Signed-off-by: Laurentiu Palcu <laurentiu.palcu@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oe/package_manager.py54
1 files changed, 42 insertions, 12 deletions
diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py
index 2e5aa82568..91f5f70d83 100644
--- a/meta/lib/oe/package_manager.py
+++ b/meta/lib/oe/package_manager.py
@@ -807,6 +807,34 @@ class OpkgPM(PackageManager):
807 807
808 self._create_config() 808 self._create_config()
809 809
810 """
811 This function will change a package's status in /var/lib/opkg/status file.
812 If 'packages' is None then the new_status will be applied to all
813 packages
814 """
815 def mark_packages(self, status_tag, packages=None):
816 status_file = os.path.join(self.opkg_dir, "status")
817
818 with open(status_file, "r") as sf:
819 with open(status_file + ".tmp", "w+") as tmp_sf:
820 if packages is None:
821 tmp_sf.write(re.sub(r"Package: (.*?)\n((?:[^\n]+\n)*?)Status: (.*)(?:unpacked|installed)",
822 r"Package: \1\n\2Status: \3%s" % status_tag,
823 sf.read()))
824 else:
825 if type(packages).__name__ != "list":
826 raise TypeError("'packages' should be a list object")
827
828 status = sf.read()
829 for pkg in packages:
830 status = re.sub(r"Package: %s\n((?:[^\n]+\n)*?)Status: (.*)(?:unpacked|installed)" % pkg,
831 r"Package: %s\n\1Status: \2%s" % (pkg, status_tag),
832 status)
833
834 tmp_sf.write(status)
835
836 os.rename(status_file + ".tmp", status_file)
837
810 def _create_config(self): 838 def _create_config(self):
811 with open(self.config_file, "w+") as config_file: 839 with open(self.config_file, "w+") as config_file:
812 priority = 1 840 priority = 1
@@ -922,7 +950,7 @@ class OpkgPM(PackageManager):
922 open(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), "w").close() 950 open(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), "w").close()
923 951
924 def remove_packaging_data(self): 952 def remove_packaging_data(self):
925 bb.utils.remove(self.opkg_dir) 953 bb.utils.remove(self.opkg_dir, True)
926 # create the directory back, it's needed by PM lock 954 # create the directory back, it's needed by PM lock
927 bb.utils.mkdirhier(self.opkg_dir) 955 bb.utils.mkdirhier(self.opkg_dir)
928 956
@@ -968,17 +996,17 @@ class OpkgPM(PackageManager):
968 996
969 status_file = os.path.join(self.opkg_dir, "status") 997 status_file = os.path.join(self.opkg_dir, "status")
970 998
971 cmd = [self.opkg_cmd, self.opkg_args, "info"] 999 cmd = "%s %s info " % (self.opkg_cmd, self.opkg_args)
972 1000
973 with open(status_file, "w+") as status: 1001 with open(status_file, "w+") as status:
974 for pkg in bad_recommendations.split(): 1002 for pkg in bad_recommendations.split():
975 pkg_info = cmd + [pkg] 1003 pkg_info = cmd + pkg
976 1004
977 try: 1005 try:
978 output = subprocess.check_output(pkg_info).strip() 1006 output = subprocess.check_output(pkg_info.split()).strip()
979 except subprocess.CalledProcessError as e: 1007 except subprocess.CalledProcessError as e:
980 bb.fatal("Cannot get package info. Command %s " 1008 bb.fatal("Cannot get package info. Command %s "
981 "returned %d" % (' '.join(pkg_info), e.returncode)) 1009 "returned %d" % (pkg_info, e.returncode))
982 1010
983 if output == "": 1011 if output == "":
984 bb.note("Requested ignored recommendation $i is " 1012 bb.note("Requested ignored recommendation $i is "
@@ -1021,8 +1049,8 @@ class DpkgPM(PackageManager):
1021 with open(status_file, "r") as sf: 1049 with open(status_file, "r") as sf:
1022 with open(status_file + ".tmp", "w+") as tmp_sf: 1050 with open(status_file + ".tmp", "w+") as tmp_sf:
1023 if packages is None: 1051 if packages is None:
1024 tmp_sf.write(re.sub(r"Package: (.*)\nStatus: (.*)(unpacked|installed)", 1052 tmp_sf.write(re.sub(r"Package: (.*?)\n((?:[^\n]+\n)*?)Status: (.*)(?:unpacked|installed)",
1025 r"Package: \1\nStatus: \2%s" % status_tag, 1053 r"Package: \1\n\2Status: \3%s" % status_tag,
1026 sf.read())) 1054 sf.read()))
1027 else: 1055 else:
1028 if type(packages).__name__ != "list": 1056 if type(packages).__name__ != "list":
@@ -1030,8 +1058,8 @@ class DpkgPM(PackageManager):
1030 1058
1031 status = sf.read() 1059 status = sf.read()
1032 for pkg in packages: 1060 for pkg in packages:
1033 status = re.sub(r"Package: %s\nStatus: (.*)(unpacked|installed)" % pkg, 1061 status = re.sub(r"Package: %s\n((?:[^\n]+\n)*?)Status: (.*)(?:unpacked|installed)" % pkg,
1034 r"Package: %s\nStatus: \1%s" % (pkg, status_tag), 1062 r"Package: %s\n\1Status: \2%s" % (pkg, status_tag),
1035 status) 1063 status)
1036 1064
1037 tmp_sf.write(status) 1065 tmp_sf.write(status)
@@ -1244,8 +1272,10 @@ class DpkgPM(PackageManager):
1244 1272
1245 bb.utils.mkdirhier(os.path.join(target_dpkg_dir, "updates")) 1273 bb.utils.mkdirhier(os.path.join(target_dpkg_dir, "updates"))
1246 1274
1247 open(os.path.join(target_dpkg_dir, "status"), "w+").close() 1275 if not os.path.exists(os.path.join(target_dpkg_dir, "status")):
1248 open(os.path.join(target_dpkg_dir, "available"), "w+").close() 1276 open(os.path.join(target_dpkg_dir, "status"), "w+").close()
1277 if not os.path.exists(os.path.join(target_dpkg_dir, "available")):
1278 open(os.path.join(target_dpkg_dir, "available"), "w+").close()
1249 1279
1250 def remove_packaging_data(self): 1280 def remove_packaging_data(self):
1251 bb.utils.remove(os.path.join(self.target_rootfs, 1281 bb.utils.remove(os.path.join(self.target_rootfs,
@@ -1275,7 +1305,7 @@ class DpkgPM(PackageManager):
1275 elif format == "ver": 1305 elif format == "ver":
1276 cmd.append("-f=${Package} ${PackageArch} ${Version}\n") 1306 cmd.append("-f=${Package} ${PackageArch} ${Version}\n")
1277 else: 1307 else:
1278 cmd.append("-f=${Package}") 1308 cmd.append("-f=${Package}\n")
1279 1309
1280 try: 1310 try:
1281 output = subprocess.check_output(cmd).strip() 1311 output = subprocess.check_output(cmd).strip()