Yield lists of (name, value) pairs, one list for each package found in an installed Alpine packages database file at `location` (typically found at '/lib/apk/db/installed' in an Alpine installation.) Note: APKINDEX index files are also in the same format. See: http://uk.alpinel
(location)
| 192 | |
| 193 | |
| 194 | def get_alpine_installed_db_fields(location): |
| 195 | """ |
| 196 | Yield lists of (name, value) pairs, one list for each package found in an |
| 197 | installed Alpine packages database file at `location` (typically found at |
| 198 | '/lib/apk/db/installed' in an Alpine installation.) |
| 199 | |
| 200 | Note: APKINDEX index files are also in the same format. |
| 201 | See: http://uk.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz |
| 202 | """ |
| 203 | if not path.exists(location): |
| 204 | return |
| 205 | |
| 206 | with open(location, 'rb') as f: |
| 207 | installed = as_unicode(f.read()) |
| 208 | |
| 209 | if installed: |
| 210 | # each installed package paragraph is separated by LFLF |
| 211 | packages = (p for p in re.split('\n\n', installed) if p) |
| 212 | for pkg in packages: |
| 213 | try: |
| 214 | fields = email.message_from_string(pkg) |
| 215 | except UnicodeEncodeError: |
| 216 | fields = email.message_from_string(pkg.encode('utf-8')) |
| 217 | yield [(n.strip(), v.strip(),) for n, v in fields.items()] |
| 218 | |
| 219 | |
| 220 | # these variables need to be resolved or else this is a parsing error |
no test coverage detected