aboutsummaryrefslogtreecommitdiff
blob: 3f3757209f5945d499ea30ad98ee9c8cdc8e5e4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Copyright 2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

from __future__ import unicode_literals

from portage.exception import InvalidData
from portage.localization import _
from portage.dep.soname.SonameAtom import SonameAtom

_error_empty_category = _("Multilib category empty: %s")
_error_missing_category = _("Multilib category missing: %s")
_error_duplicate_category = _("Multilib category occurs"
	" more than once: %s")

def parse_soname_deps(s):
	"""
	Parse a REQUIRES or PROVIDES dependency string, and raise
	InvalidData if necessary.

	@param s: REQUIRES or PROVIDES string
	@type s: str
	@rtype: iter
	@return: An iterator of SonameAtom instances
	"""

	categories = set()
	category = None
	previous_soname = None
	for soname in s.split():
		if soname.endswith(":"):
			if category is not None and previous_soname is None:
					raise InvalidData(_error_empty_category % category)

			category = soname[:-1]
			previous_soname = None
			if category in categories:
				raise InvalidData(_error_duplicate_category % category)
			categories.add(category)

		elif category is None:
			raise InvalidData(_error_missing_category % soname)
		else:
			previous_soname = soname
			yield SonameAtom(category, soname)

	if category is not None and previous_soname is None:
		raise InvalidData(_error_empty_category % category)