aboutsummaryrefslogtreecommitdiff
blob: 13c478fbe4ef9b1efe7a84b56959eeb1414e99fc (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
# Copyright: 2005 Gentoo Foundation
# Author(s): Brian Harring (ferringb@gentoo.org)
# License: GPL2
# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/restrictions/restriction.py,v 1.9 2005/08/16 00:21:49 ferringb Exp $

import re, logging

class base(object):
	"""base restriction matching object; overrides setattr to provide the usual write once trickery
	all derivatives *must* be __slot__ based"""

	__slots__ = ["negate"]
	package_matching = False
	
	def __init__(self, negate=False):
		self.negate = negate

#	def __setattr__(self, name, value):
#		import traceback;traceback.print_stack()
#		object.__setattr__(self, name, value)
#		try:	getattr(self, name)
#			
#		except AttributeError:
#			object.__setattr__(self, name, value)
#		else:	raise AttributeError

	def match(self, *arg, **kwargs):
		raise NotImplementedError

	force_False = force_True = match
	def cmatch(self, pkg, *val):
		m=self.match(value)
		if m ^ self.negate:
			return True
		elif pkg == None or attr == None:
			return False
		elif self.negate:
			return pkg.request_disable(attr, value)
		return pkg.request_enable(attr, value)

	def intersect(self, other):
		return None

	def __len__(self):
		return 1

class AlwaysBoolMatch(base):
	__slots__ = base.__slots__
	def match(self, *a, **kw):		return self.negate
	def __str__(self):	return "always '%s'" % self.negate
	def cmatch(self, *a, **kw):		return self.negate

AlwaysFalse = AlwaysBoolMatch(False)
AlwaysTrue  = AlwaysBoolMatch(True)