aboutsummaryrefslogtreecommitdiff
blob: 0cb81e817a3a037fbf5270381c8f21b2635b0ac0 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# R overlay --
# Copyright 2006-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2


class DepEnv ( object ):

	STATUS_UNDONE       = 1
	STATUS_RESOLVED     = 2
	STATUS_UNRESOLVABLE = 4

	def __init__ ( self, dep_str ):
		"""Initializes a dependency environment that represents the dependency
		resolution of one entry in the description data of an R package.

		arguments:
		* dep_str -- dependency string at it appears in the description data.
		"""
		self.ident       = id ( self )
		self.dep_str     = dep_str
		self.dep_str_low = dep_str.lower()
		self.status      = DepEnv.STATUS_UNDONE
		self.resolved_by = None

		# TODO: analyze dep_str:
		#   extract dep name, dep version, useless comments,...

	# --- end of __init__ (...) ---

	def set_resolved ( self, resolved_by, append=False ):
		"""Marks this DepEnv as resolved with resolved_by as corresponding
		portage package.

		arguments:
		* resolved_by -- resolving portage package
		* append -- whether to append resolved_by or not; NOT IMPLEMENTED
		"""
		if self.resolved_by is None:
			self.resolved_by = resolved_by
		elif append:
			# useful?
			raise Exception ( "appending is not supported..." )
		else:
			raise Exception (
				"dependency is already resolved and append is disabled."
			)

		# add RESOLVED status
		self.status |= DepEnv.STATUS_RESOLVED

	# --- end of set_resolved (...) ---

	def set_unresolvable ( self, force=False ):
		"""Marks this DepEnv as unresolvable.

		arguments:
		force -- force unresolvable status even if this DepEnv
		          is already resolved
		"""
		if force or not self.status & DepEnv.STATUS_RESOLVED:
			self.resolved_by = None
			self.status |= DepEnv.STATUS_UNRESOLVABLE
		else:
			raise Exception ("dependency is already marked as resolved." )

	# --- end of set_unresolvable (...) ---

	def zap ( self ):
		"""Resets the status of this DepEnv and clears out all resolving pkgs."""
		self.status      = DepEnv.STATUS_UNDONE
		self.resolved_by = None

	# --- end of zap (...) ---

	def is_resolved ( self ):
		"""Returns True if this DepEnv is resolved, else false."""
		return bool ( self.status & DepEnv.STATUS_RESOLVED )

	# --- end of is_resolved (...) ---

	def get_result ( self ):
		"""Returns the result of this DepEnv as a tuple
		( original dep str, resolving portage package ) where resolving portage
		package may be None.
		"""
		return ( self.dep_str, self.resolved_by )

	# --- end of get_result (...) ---