PKʼn:Hsrcinfo/__init__.pyPKʼn:H8csrcinfo/main.pyfrom srcinfo.parse import parse_srcinfo import sys ## # Parse SRCINFO from stdin and pretty-print parsed info # def main(): import pprint import sys srcinfo = sys.stdin.read() (info, errors) = parse_srcinfo(srcinfo) pprint.PrettyPrinter().pprint(info) if errors: print('==> The following errors occured while parsing:', file=sys.stderr) for error in errors: print(error, file=sys.stderr) PKʼn:H#=6Lsrcinfo/utils.py## # Get a specific variable for a package, falling back to the global one if no # package-specific version exists # # Arguments: # variable: Variable to find # package: Package to look up variable for # info: Dict to look up in # def get_variable(variable, package, info): if package and package in info['packages']: package = info['packages'][package] if variable in package: return package[variable] if variable in info: return info[variable] else: return None ## # Return the info for a single package # def get_merged_package(package, srcinfo): if not package in srcinfo['packages']: return None merged = srcinfo.copy() package_info = merged['packages'][package] for key in package_info: merged[key] = package_info[key] merged.pop('packages') return merged ## # Get a list of package names # def get_package_names(info): return [p for p in info['packages'].keys()] PKnFHDjsrcinfo/parse.pyfrom parse import parse arrays = ['pkgname', 'arch', 'license', 'groups', 'options', 'conflicts', 'provides', 'replaces', 'source', 'noextract', 'backup', 'validpgpkeys', 'md5sums', 'sha1sums', 'sha224sums', 'sha256sums', 'sha384sums', 'sha512sums', 'depends', 'makedepends', 'checkdepends', 'optdepends', ] def remove_empty_values(values): return [v for v in values if v.strip()] ## # Check if SRCINFO key is an array # def is_array(key): if key in arrays: return True for array in arrays: if key.startswith(array): return True return False ## # Insert `value` into the list index `key` in list `target` # def list_insert(target, key, value): if key not in target: target[key] = [] # Don't append value if already in the list if value not in target[key]: if value: target[key].append(value) ## # Extract a SRCINFO variable from `string` # def extract_var(string): line = string.lstrip() key = None value = None errors = [] parsed = parse('{} ={}', line) if parsed: (key, value) = parsed key = key.strip() value = value.strip() elif line.startswith('#'): pass else: errors.append('failed to parse line: "{}"'.format(line)) return (key, value, errors) ## # Parse SRCINFO from string # # Returns a tuple of the srcinfo dict and an list of any errors found while # parsing # def parse_srcinfo(source): lines = source.splitlines() srcinfo = {'packages': {}} info = srcinfo errors = [] for index, line in enumerate(lines, start=1): if not line.strip(): continue if line.startswith('pkgname'): pkgname = line.split('pkgname =')[1].strip() info = srcinfo['packages'][pkgname] = {} continue (key, value, err) = extract_var(line) if err: errors.append({ 'line': index, 'error': err }) if not key: continue if is_array(key): list_insert(info, key, value) else: info[key] = value return (srcinfo, errors) PKFHZ'srcinfo-0.0.5.dist-info/DESCRIPTION.rst================ python-srcinfo ================ This is a small library to easily parse ``.SRCINFO`` files in python, using the python parse_ library. .. _parse: https://github.com/r1chardj0n3s/parse Installing ---------- If you're on Arch Linux, you can install this library from the [community] repository. Alternatively, it can be installed from the PyPI using pip `[1]`__. .. __: https://pypi.python.org/pypi/srcinfo PKFHR<55(srcinfo-0.0.5.dist-info/entry_points.txt[console_scripts] parse_srcinfo = srcinfo.main:main PKFH6}}%srcinfo-0.0.5.dist-info/metadata.json{"classifiers": ["Development Status :: 3 - Alpha", "Topic :: System :: Archiving :: Packaging", "License :: OSI Approved :: ISC License (ISCL)"], "extensions": {"python.commands": {"wrap_console": {"parse_srcinfo": "srcinfo.main:main"}}, "python.details": {"contacts": [{"email": "johannes@kyriasis.com", "name": "Johannes L\u00f6thberg", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/kyrias/python-srcinfo"}}, "python.exports": {"console_scripts": {"parse_srcinfo": "srcinfo.main:main"}}}, "extras": [], "generator": "bdist_wheel (0.28.0)", "keywords": [".SRCINFO", "makepkg", "pacman", "AUR"], "license": "ISC", "metadata_version": "2.0", "name": "srcinfo", "run_requires": [{"requires": ["parse"]}], "summary": "A small library to parse .SRCINFO files", "test_requires": [{"requires": ["nose"]}], "version": "0.0.5"}PKFHI[%srcinfo-0.0.5.dist-info/top_level.txtsrcinfo PKFHLO/\\srcinfo-0.0.5.dist-info/WHEELWheel-Version: 1.0 Generator: bdist_wheel (0.28.0) Root-Is-Purelib: true Tag: py3-none-any PKFHҎ}} srcinfo-0.0.5.dist-info/METADATAMetadata-Version: 2.0 Name: srcinfo Version: 0.0.5 Summary: A small library to parse .SRCINFO files Home-page: https://github.com/kyrias/python-srcinfo Author: Johannes Löthberg Author-email: johannes@kyriasis.com License: ISC Keywords: .SRCINFO makepkg pacman AUR Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Topic :: System :: Archiving :: Packaging Classifier: License :: OSI Approved :: ISC License (ISCL) Requires-Dist: parse ================ python-srcinfo ================ This is a small library to easily parse ``.SRCINFO`` files in python, using the python parse_ library. .. _parse: https://github.com/r1chardj0n3s/parse Installing ---------- If you're on Arch Linux, you can install this library from the [community] repository. Alternatively, it can be installed from the PyPI using pip `[1]`__. .. __: https://pypi.python.org/pypi/srcinfo PKFHn$(oosrcinfo-0.0.5.dist-info/RECORDsrcinfo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 srcinfo/main.py,sha256=wU-w5MuCvSYpT7VQHnDQDR3klSZZS-JZiGGWF_uNltQ,443 srcinfo/parse.py,sha256=V7Zqa4XgBGnssbNPxiY3_NpkPco0PF6pyAr3Xka9nkk,2250 srcinfo/utils.py,sha256=yut6_5jsboDBNWEHLE7FlHY88X-5ZWwt9povFFBmQAs,996 srcinfo-0.0.5.dist-info/DESCRIPTION.rst,sha256=_-kzM_ky1ZFjBgIiLo3wWdx9UeCFlhmTBeNAaMN0mBI,431 srcinfo-0.0.5.dist-info/METADATA,sha256=dCsr3KCu1g4377fF_txnpKZ4tLyMrbVhFD6DgBXnJNE,893 srcinfo-0.0.5.dist-info/RECORD,, srcinfo-0.0.5.dist-info/WHEEL,sha256=ZDZZro9Z4IIKbNpfyOW28VHgUeIyjXGR9sWdIPDOwYM,92 srcinfo-0.0.5.dist-info/entry_points.txt,sha256=LBSDRSDNCeqKMFj-iSenHSIMy5ctkVuN01hbeFzK_mI,53 srcinfo-0.0.5.dist-info/metadata.json,sha256=hnQ7TzHTxfAWaCCKwYFVnlaI04L0mpvRFHX2ivzu4_o,893 srcinfo-0.0.5.dist-info/top_level.txt,sha256=lprn9n1S4UVDkfUTvSk1E8ArC56uWEBr9ZWuqQxlel0,8 PKʼn:Hsrcinfo/__init__.pyPKʼn:H8c1srcinfo/main.pyPKʼn:H#=6Lsrcinfo/utils.pyPKnFHDj+srcinfo/parse.pyPKFHZ'#srcinfo-0.0.5.dist-info/DESCRIPTION.rstPKFHR<55(srcinfo-0.0.5.dist-info/entry_points.txtPKFH6}}%srcinfo-0.0.5.dist-info/metadata.jsonPKFHI[%Rsrcinfo-0.0.5.dist-info/top_level.txtPKFHLO/\\srcinfo-0.0.5.dist-info/WHEELPKFHҎ}} 4srcinfo-0.0.5.dist-info/METADATAPKFHn$(oosrcinfo-0.0.5.dist-info/RECORDPK 0