MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / get_alpine_installed_db_fields

Function get_alpine_installed_db_fields

src/packagedcode/alpine.py:194–217  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

192
193
194def 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

Callers 1

Calls 5

as_unicodeFunction · 0.90
existsMethod · 0.45
readMethod · 0.45
splitMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected