Commits

Michał Górny committed 61bd8a0

Support Token.flags[].modified properties.

Comments (0)

Files changed (1)

lib/flaggie/makeconf.py

 class MakeConfVariable(PackageFileSet.PackageFile.PackageEntry):
 	class MakeConfFlag(PackageFileSet.PackageFile.PackageEntry.PackageFlag):
 		def __init__(self, s, lta = []):
+			PackageFileSet.PackageFile.PackageEntry.PackageFlag.__init__( \
+				self, s + ''.join([x.toString() for x in lta]))
+
 			self._origs = s
 			self._partialflags = lta
-			s += ''.join([x.toString() for x in lta])
-			PackageFileSet.PackageFile.PackageEntry.PackageFlag.__init__(self, s)
+
+		@property
+		def modified(self):
+			return self._origs is None
+
+		@modified.setter
+		def modified(self, val):
+			if val:
+				self._origs = None
+				for pf in self._partialflags:
+					pf.modified = True
+			else:
+				raise NotImplementedError('Disable modified for MakeConfFlag is not supported.')
 
 		def toString(self):
-			return self._origs
+			if not self.modified:
+				return self._origs
+			else:
+				return PackageFileSet.PackageFile.PackageEntry.PackageFlag.toString(self)
 
 	class Whitespace(object):
 		def __init__(self, s):
 		def toString(self):
 			return self.s
 
+		@property
+		def modified(self):
+			return False
+
 	class PartialFlag(Whitespace):
-		pass
+		@property
+		def modified(self):
+			return not self.s
+
+		@modified.setter
+		def modified(self, val):
+			if val:
+				self.s = ''
+			else:
+				raise NotImplementedError('Disabling modified for PartialFlag is not supported.')
 
 	def __init__(self, key, tokens):
 		def flattentokens(l, parentvar):
 
 			@property
 			def modified(self):
-				return self._modified
+				if self._modified:
+					return True
+				elif hasattr(self, 'flags'):
+					for f in self.flags:
+						if f.modified:
+							return True
+				return False
 
 			@modified.setter
 			def modified(self, val):