[3.10.9 migration] don't display progress bar if stdout is not a tty stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 08 Mar 2011 16:00:25 +0100
branchstable
changeset 7050 3f2857704444
parent 7043 686010f3a83e
child 7051 34d8b36480a9
[3.10.9 migration] don't display progress bar if stdout is not a tty
misc/migration/3.10.9_Any.py
--- a/misc/migration/3.10.9_Any.py	Mon Mar 07 17:19:00 2011 +0100
+++ b/misc/migration/3.10.9_Any.py	Tue Mar 08 16:00:25 2011 +0100
@@ -1,4 +1,5 @@
 from __future__ import with_statement
+import sys
 
 # fix some corrupted entities noticed on several instances
 rql('DELETE CWConstraint X WHERE NOT E constrained_by X')
@@ -9,13 +10,17 @@
     from logilab.common.shellutils import ProgressBar
     from cubicweb.server.session import hooks_control
     rset = rql('Any X, XC WHERE X cwuri XC, X cwuri ~= "%/eid/%"')
-    pb = ProgressBar(nbops=rset.rowcount, size=70)
+    if sys.stdout.isatty():
+        pb = ProgressBar(nbops=rset.rowcount, size=70)
+    else:
+        pb = None
     with hooks_control(session, session.HOOKS_DENY_ALL, 'integrity'):
         for i,  e in enumerate(rset.entities()):
             e.set_attributes(cwuri=e.cwuri.replace('/eid', ''))
             if i % 100: # commit every 100 entities to limit memory consumption
                 commit(ask_confirm=False)
-            pb.update()
+            if pb is not None:
+                pb.update()
     commit(ask_confirm=False)
 
 try: