Commits

Michał Górny  committed d7df0f0

Implement smarter update status header output.

  • Participants
  • Parent commits 971f61c

Comments (0)

Files changed (2)

File smartliverebuild/output.py

 	s3reset = cyan
 	errreset = yellow
 
+	def __init__(self):
+		self._cur_header = None
+
 	def monochromize(self):
 		for k in dir(self):
 			if not k.startswith('_'):
 
 	def s1(self, msg):
 		self.out('%s*** %s%s\n' % (self.s1reset, msg, self.reset))
+		self._cur_header = None
 	def s2(self, msg):
 		self.out('%s->%s  %s\n' % (self.s2reset, self.reset, msg))
 	def s3(self, msg):
 		self.out('%s-->%s %s\n' % (self.s3reset, self.reset, msg))
 
+	def pkgs(self, header, msg):
+		if self._cur_header != header:
+			self.s2(header)
+			self._cur_header = header
+		self.s3(msg)
+
 	def err(self, msg):
 		self.out('%s!!!%s %s%s%s\n' % (self.red, self.reset, self.errreset, msg, self.reset))
+		self._cur_header = None
 
 	def out(self, msg):
 		sys.stderr.write(msg)

File smartliverebuild/vcs/__init__.py

 		if len(missingvars) > 0:
 			raise KeyError('Environment does not declare: %s' % missingvars)
 
+		class LazyHeader(object):
+			def __init__(self, vcs):
+				self._s = None
+				self._vcs = vcs
+
+			def __str__(self):
+				if self._s is None:
+					self._s = '[%s] %s' % (self._vcs.cpv, str(self._vcs))
+				return self._s
+
+		self._header = LazyHeader(self)
+
 	@abstractmethod
 	def __str__(self):
 		pass
 
 		cmd = self.updatecmd
 		if self._opts.jobs > 1:
-			out.s2(str(self))
+			out.pkgs(str(self), cmd)
 		else:
-			out.s2('[%s] %s' % (self.cpv, str(self)))
-		out.s3(cmd)
+			out.pkgs(self._header, cmd)
 
 		popenargs['env'] = self.callenv
 		popenargs['shell'] = True
 			raise Exception('update command returned non-zero result')
 
 	def _finishupdate(self, newrev):
-		if self._opts.jobs > 1:
-			out.s2('[%s] %s' % (self.cpv, str(self)))
-
 		oldrev = self.savedrev
 		if self.revcmp(oldrev, newrev):
-			out.s3('at rev %s%s%s (no changes)' % (out.green, oldrev, out.reset))
+			out.pkgs(self._header, 'at rev %s%s%s (no changes)' % \
+					(out.green, oldrev, out.reset))
 			return False
 		else:
-			out.s3('update from %s%s%s to %s%s%s' % (out.green, oldrev, out.reset, out.lime, newrev, out.reset))
+			out.pkgs(self._header, 'update from %s%s%s to %s%s%s' % \
+					(out.green, oldrev, out.reset, out.lime, newrev, out.reset))
 			return True
 
 	def __del__(self):