Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 277619 | Differences between
and this patch

Collapse All | Expand All

(-)news.py (-11 / +19 lines)
Lines 180-186 Link Here
180
	"display if arch: x86" and so forth.
180
	"display if arch: x86" and so forth.
181
181
182
	Creation of a news item involves passing in the path to the particular news item.
182
	Creation of a news item involves passing in the path to the particular news item.
183
184
	"""
183
	"""
185
184
186
	def __init__(self, path, name):
185
	def __init__(self, path, name):
Lines 199-222 Link Here
199
		and a vardb so we can look at installed packages).
198
		and a vardb so we can look at installed packages).
200
		Each restriction will pluck out the items that are required for it to match
199
		Each restriction will pluck out the items that are required for it to match
201
		or raise a ValueError exception if the required object is not present.
200
		or raise a ValueError exception if the required object is not present.
201
202
		Restrictions of the form Display-X are OR'd with like-restrictions; otherwise
203
		restrictions are AND'd.  any_match is the ORing and all_match is the ANDing.
202
		"""
204
		"""
203
205
204
		if not self._parsed:
206
		if not self._parsed:
205
			self.parse()
207
			self.parse()
206
208
207
		if not len(self.restrictions):
209
		if not len(self.restrictions):
208
			return True # no restrictions to match means everyone should see it
210
			return True
209
211
210
		kwargs = \
212
		kwargs = \
211
			{ 'vardb' : vardb,
213
			{ 'vardb' : vardb,
212
				'config' : config,
214
				'config' : config,
213
				'profile' : profile }
215
				'profile' : profile }
214
216
215
		for restriction in self.restrictions:
217
		all_match = True
216
			if restriction.checkRestriction(**kwargs):
218
		for restriction_type, values in self.restrictions.iteritems():
217
				return True
219
			any_match = False
220
			for restriction in values:
221
				if restriction.checkRestriction(**kwargs):
222
					any_match = True
223
			if not any_match:
224
			all_match = False
218
225
219
		return False # No restrictions were met; thus we aren't relevant :(
226
		return all_match
220
227
221
	def isValid(self):
228
	def isValid(self):
222
		if not self._parsed:
229
		if not self._parsed:
Lines 225-235 Link Here
225
232
226
	def parse(self):
233
	def parse(self):
227
		lines = open(self.path).readlines()
234
		lines = open(self.path).readlines()
228
		self.restrictions = []
235
		self.restrictions = {}
229
		invalids = []
236
		invalids = []
230
		for i, line in enumerate(lines):
237
		for i, line in enumerate(lines):
231
			#Optimization to ignore regex matchines on lines that
238
			# Optimization to ignore regex matchines on lines that
232
			#will never match
239
			# will never match
233
			if not line.startswith('D'):
240
			if not line.startswith('D'):
234
				continue
241
				continue
235
			restricts = {  _installedRE : DisplayInstalledRestriction,
242
			restricts = {  _installedRE : DisplayInstalledRestriction,
Lines 238-246 Link Here
238
			for regex, restriction in restricts.iteritems():
245
			for regex, restriction in restricts.iteritems():
239
				match = regex.match(line)
246
				match = regex.match(line)
240
				if match:
247
				if match:
241
					self.restrictions.append(restriction(match.groups()[0].strip()))
248
					restrict = restriction(match.groups()[0].strip())
242
					if not self.restrictions[-1].isValid():
249
					if not restrict.isValid():
243
						invalids.append((i + 1, line.rstrip("\n")))
250
						invalids.append((i + 1, line.rstrip("\n")))
251
					self.restrictions.setdefault(restriction.__class__, []).append(restrict)
244
					continue
252
					continue
245
		if invalids:
253
		if invalids:
246
			self._valid = False
254
			self._valid = False

Return to bug 277619