Add repo_management package

Add the basic defaults module, providing data that translates keywords
found in the 'desc' and 'files' files of a binary repository database to
those used in JSON files, representing the same data.

Add the convert module, and introduce the simple private method
(reimplementing a subset of the features from db2json)
`_files_data_to_dict()`, which translates the contents of a `files` file
to a typed dict.
parent 190fff47
import io
from typing import Dict, List
from repo_management import defaults
def _files_data_to_dict(data: io.StringIO) -> Dict[str, List[str]]:
"""Read the contents of a 'files' file (represented as an instance of
io.StringIO) into a dict
Closes the io.StringIO upon error or before returning the dict
data: io.StringIO
A buffered I/O that represents a 'files' file
If the 'files' file is missing its %FILES% header
Dict[str, List[str]]
A dict representing the list of files
output: Dict[str, List[str]] = {defaults.FILES_JSON["%FILES%"]: []}
line_counter = 0
for line in data:
line = line.strip()
if line_counter == 0 and line not in defaults.FILES_JSON.keys():
raise RuntimeError(f"The 'files' data misses its header: '{line}' was provided.")
if line_counter > 0 and line not in defaults.FILES_JSON.keys():
# TODO: assertions about whether the line actually represents a
# valid path
output[defaults.FILES_JSON["%FILES%"]] += [line]
line_counter += 1
return output
# mapping of sections of pkgbase desc file <-> JSON key
"%BASE%": "base",
"%VERSION%": "version",
"%MAKEDEPENDS%": "makedepends",
"%CHECKDEPENDS%": "checkdepends",
"%FILENAME%": "filename",
"%NAME%": "name",
"%DESC%": "desc",
"%GROUPS%": "groups",
"%CSIZE%": "csize",
"%ISIZE%": "isize",
"%MD5SUM%": "md5sum",
"%SHA256SUM%": "sha256sum",
"%PGPSIG%": "pgpsig",
"%URL%": "url",
"%LICENSE%": "licenses",
"%ARCH%": "arch",
"%BUILDDATE%": "builddate",
"%PACKAGER%": "packager",
"%REPLACES%": "replaces",
"%CONFLICTS%": "conflicts",
"%PROVIDES%": "provides",
"%DEPENDS%": "depends",
"%OPTDEPENDS%": "optdepends",
"%BACKUP%": "backup",
FILES_JSON = {"%FILES%": "files"}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment