[server] Do not use progress bar when stdout is not a TTY
Closes #5460552.
--- a/server/schemaserial.py Tue May 05 15:49:41 2015 +0200
+++ b/server/schemaserial.py Fri Jun 12 09:18:02 2015 +0200
@@ -21,8 +21,9 @@
import os
import json
+import sys
-from logilab.common.shellutils import ProgressBar
+from logilab.common.shellutils import ProgressBar, DummyProgressBar
from yams import (BadSchemaDefinition, schema as schemamod, buildobjs as ybo,
schema2sql as y2sql)
@@ -350,7 +351,10 @@
pb_size = (len(eschemas + schema.relations())
+ len(CONSTRAINTS)
+ len([x for x in eschemas if x.specializes()]))
- pb = ProgressBar(pb_size, title=_title)
+ if sys.stdout.isatty():
+ pb = ProgressBar(pb_size, title=_title)
+ else:
+ pb = DummyProgressBar()
groupmap = group_mapping(cnx, interactive=False)
# serialize all entity types, assuring CWEType is serialized first for proper
# is / is_instance_of insertion
--- a/server/sqlutils.py Tue May 05 15:49:41 2015 +0200
+++ b/server/sqlutils.py Fri Jun 12 09:18:02 2015 +0200
@@ -28,7 +28,7 @@
from logging import getLogger
from logilab import database as db, common as lgc
-from logilab.common.shellutils import ProgressBar
+from logilab.common.shellutils import ProgressBar, DummyProgressBar
from logilab.common.deprecation import deprecated
from logilab.common.logging_ext import set_log_methods
from logilab.database.sqlgen import SQLGenerator
@@ -72,7 +72,10 @@
sqlstmts_as_string = True
sqlstmts = sqlstmts.split(delimiter)
if withpb:
- pb = ProgressBar(len(sqlstmts), title=pbtitle)
+ if sys.stdout.isatty():
+ pb = ProgressBar(len(sqlstmts), title=pbtitle)
+ else:
+ pb = DummyProgressBar()
failed = []
for sql in sqlstmts:
sql = sql.strip()