[PATCH] Re: smart on cron

Arnaldo Carvalho de Melo acme at mandriva.com
Sat Oct 8 18:40:12 PDT 2005


Em Sat, Oct 08, 2005 at 04:50:10PM -0300, Martín Marqués escreveu:
> El Sáb 08 Oct 2005 16:23, Gustavo Niemeyer escribió:
> > Hello,
> > 
> > Yes, that's something that should be fixed. The textual progress bar
> > should check if the output is a terminal or not and act accordingly.
> > 
> > Can you please open an issue at tracker.labix.org? That's the best
> > way to ensure that it'll be taken care of.
> 
> Done.

Hi Martin,

	I cooked up a patch, can you try it? I tested it using ``smart
update > /tmp/output'', works for me :-)

	Ah, patch was done & tested using smart 0.36, but I checked and
interfaces/text/progress.py hasn't changed, so it should work.

	Please report here if it works,

Thanks,

- Arnaldo

--- /usr/lib/python2.4/site-packages/smart/interfaces/text/progress.py.orig	2005-10-08 19:02:44.000000000 -0300
+++ /usr/lib/python2.4/site-packages/smart/interfaces/text/progress.py	2005-10-08 22:33:40.000000000 -0300
@@ -60,7 +60,8 @@ class TextProgress(Progress):
         if self.getHasSub():
             if topic != self._lasttopic:
                 self._lasttopic = topic
-                out.write(" "*(self._screenwidth-1)+"\r")
+                if out.isatty():
+                    out.write(" "*(self._screenwidth-1)+"\r")
                 if self._addline:
                     print
                 else:
@@ -87,20 +88,23 @@ class TextProgress(Progress):
             if self._fetchermode:
                 if topic not in self._seentopics:
                     self._seentopics[topic] = True
-                    out.write(" "*(self._screenwidth-1)+"\r")
+                    if out.isatty():
+                        out.write(" "*(self._screenwidth-1)+"\r")
                     print "->", self._shorturl.get(topic)
                 topic = posixpath.basename(topic)
         else:
             current = percent
-        n = data.get("item-number")
-        if n:
-            if len(topic) > self._topicwidth-6:
-                topic = topic[:self._topicwidth-8]+".."
-            out.write(self._topicmaskn % (n, topic))
-        else:
-            if len(topic) > self._topicwidth-1:
-                topic = topic[:self._topicwidth-3]+".."
-            out.write(self._topicmask % topic)
+
+        if out.isatty() or not percent:
+            n = data.get("item-number")
+            if n:
+                if len(topic) > self._topicwidth-6:
+                    topic = topic[:self._topicwidth-8]+".."
+                out.write(self._topicmaskn % (n, topic))
+            else:
+                if len(topic) > self._topicwidth-1:
+                    topic = topic[:self._topicwidth-3]+".."
+                out.write(self._topicmask % topic)
 
         if not done:
             speed = data.get("speed")
@@ -115,11 +119,12 @@ class TextProgress(Progress):
 
         hashwidth = self._hashwidth-len(suffix)
 
-        hashes = int(hashwidth*current/100)
-        out.write("#"*hashes)
-        out.write(" "*(hashwidth-hashes+1))
+        if out.isatty() or current == 100:
+            hashes = int(hashwidth*current/100)
+            out.write("#"*hashes)
+            out.write(" "*(hashwidth-hashes+1))
+            out.write(suffix)
 
-        out.write(suffix)
         out.flush()
 
 def test():



More information about the Smart mailing list