Esempio n. 1
0
		def __init__(self, origrepo):
			""" Instantiate the SyncedUnmaskRepo, copying the entries
				from `origrepo' (MaskRepo instance). """
			self.name = origrepo.name
			for e in origrepo:
				ce = copy(e)
				ce._enabled = False
				DiffmaskList.append(self, ce)
Esempio n. 2
0
	def __init__(self, mask, unmask):
		""" Instantiate the SyncedUnmaskFile using a package.mask file
			instance `mask' and UnmaskFile instance `unmask'. """
		DiffmaskList.__init__(self)
		self.path = unmask.path

		for r in mask:
			self.append(r)
		for ur in unmask:
			if ur.name is None:
				for r in self:
					r.extend(ur)
			elif ur.name in self:
				self[ur.name].extend(ur)
Esempio n. 3
0
	def toString(self):
		out = DiffmaskList.toString(self)
		# If the file ends with a blank line, drop it.
		if out.endswith('\n\n'):
			return out[:-1]
		else:
			return out
Esempio n. 4
0
	def __contains__(self, repo):
		if isinstance(repo, self.MaskRepo):
			return DiffmaskList.__contains__(self, repo)
		else:
			for r in self:
				if r.name == repo:
					return True
			return False
Esempio n. 5
0
	def __getitem__(self, name):
		""" Get the repository by the numeric index or name. """
		if isinstance(name, int):
			return DiffmaskList.__getitem__(self, name)
		else:
			for r in self:
				if r.name == name:
					return r
			raise KeyError('No such repo')
Esempio n. 6
0
	def __init__(self, data):
		""" Instiantate a new MaskFile. Parse the contents of string
			list data, and feed the subclasses with it. """
		repo = self.MaskRepo(None)
		DiffmaskList.__init__(self, [repo])
		buf = []
		pbuf = None
		tmprepo = []
		tmprepos = [(None, tmprepo)]
		gotatoms = False

		for l in data:
			if l.startswith('#'):
				newrepo = (l.startswith('## *') and l.endswith('*\n')) # repo name
				newmask = ('<' in l and '>' in l) # a mask header

				if gotatoms:
					tmprepo.append(buf)
					pbuf = buf
					buf = []
					gotatoms = False
				if newrepo:
					pbuf = None
					buf = []
					tmprepo = []
					tmprepos.append((l[4:-2], tmprepo))
					continue
				elif not gotatoms and newmask and pbuf is not None:
					pbuf.extend(buf)
					pbuf = None
					buf = []
			elif l.strip():
				gotatoms = True
			buf.append(l)

		if ''.join(buf).strip():
			tmprepo.append(buf)

		for reponame, entries in tmprepos:
			repo = self.MaskRepo(reponame)
			repo.extend(entries)
			self.append(repo)
Esempio n. 7
0
			def __contains__(self, cpv):
				""" When passed a cpv, check whether at least one
					of the atoms in the mask entry match the given cpv.
					
					When passed a MaskAtom instance, check whether
					the particular Atom is contained within the entry.
					"""
				if isinstance(cpv, self.MaskAtom):
					return DiffmaskList.__contains__(self, cpv)

				atoms = [x.atom for x in self if isinstance(x.atom, Atom)]
				return match_to_list(cpv, atoms)
Esempio n. 8
0
			def __init__(self, data):
				""" Instantiate a new MaskBlock from string list.
					The list is required to contain only the contents
					of a single mask entry. """
				DiffmaskList.__init__(self)
				self.comment = []
				self.after = []

				for l in data:
					if not self:
						if l.startswith('#'): # a comment
							self.comment.append(l)
						elif l.strip(): # the first atom
							self.append(l)
						elif self.comment: # a non-leading whitespace
							self.comment.append(l)
					elif l.startswith('#') or not l.strip():
						self.after.append(l)
					else:
						self.append(l)

				# We require each entry to end with a blank line
				if not self.after or not self.after[-1].endswith('\n'):
					self.after.append('\n')
Esempio n. 9
0
	def append(self, repo):
		if not isinstance(repo, self.SyncedUnmaskRepo):
			repo = self.SyncedUnmaskRepo(repo)
		DiffmaskList.append(self, repo)
Esempio n. 10
0
			def append(self, data):
				""" Append the atom to the entry, taking care
					of conversion into MaskAtom if necessary. """
				if not isinstance(data, self.MaskAtom):
					data = self.MaskAtom(data)
				DiffmaskList.append(self, data)
Esempio n. 11
0
			def toString(self):
				l = [DiffmaskList.toString(self)]
				return ''.join(self.comment + l + self.after)
Esempio n. 12
0
		def __init__(self, name):
			""" Instiantate a new MaskRepo named 'name'. The repository
				will be empty and needs to be fed manually. """
			DiffmaskList.__init__(self)
			self.name = name
Esempio n. 13
0
		def append(self, data):
			""" Append the given block to the repository, taking care
				of casting into MaskBlock if necessary. """
			if not isinstance(data, self.MaskBlock):
				data = self.MaskBlock(data)
			DiffmaskList.append(self, data)