Silent mode if using scripts

When using a script, the command line mode prints less debug output
and less things in general, to avoid cluttering the output with
unwanted things.
master
Salvo 'LtWorf' Tomaselli 2015-11-06 16:03:58 +07:00
parent 643adf4d0a
commit 87e2c76468
2 changed files with 23 additions and 9 deletions

@ -121,9 +121,10 @@ if __name__ == "__main__":
form.show()
sys.exit(app.exec_())
else:
printver(False)
try:
import relational_readline.linegui
if relational_readline.linegui.TTY:
printver(False)
except:
print (
"Module relational_readline is missing.\nPlease install relational-cli package.",

@ -30,6 +30,15 @@ from xtermcolor import colorize
PROMPT_COLOR = 0xffff00
ERROR_COLOR = 0xff0000
TTY = os.isatty(0) and os.isatty(1)
def printtty(*args, **kwargs):
'''
Prints only if stdout and stdin are a tty
'''
if TTY:
print(*args,**kwargs)
class SimpleCompleter(object):
@ -121,7 +130,7 @@ def load_relation(filename, defname=None):
relations[defname] = relation.relation(filename)
completer.add_completion(defname)
print (colorize("Loaded relation %s" % defname, 0x00ff00))
printtty(colorize("Loaded relation %s" % defname, 0x00ff00))
return defname
except Exception as e:
print (colorize(e, ERROR_COLOR), file=sys.stderr)
@ -287,7 +296,7 @@ def exec_query(command):
pyquery = parser.parse(query)
result = pyquery(relations)
print (colorize("-> query: %s" % pyquery, 0x00ff00))
printtty(colorize("-> query: %s" % pyquery, 0x00ff00))
if printrel:
print ()
@ -301,8 +310,8 @@ def exec_query(command):
def main(files=[]):
print (colorize('> ', PROMPT_COLOR) + "; Type HELP to get the HELP")
print (colorize('> ', PROMPT_COLOR) +
printtty(colorize('> ', PROMPT_COLOR) + "; Type HELP to get the HELP")
printtty(colorize('> ', PROMPT_COLOR) +
"; Completion is activated using the tab (if supported by the terminal)")
for i in files:
@ -316,14 +325,18 @@ def main(files=[]):
while True:
try:
line = input(colorize('> ', PROMPT_COLOR))
line = input(colorize('> ' if TTY else '', PROMPT_COLOR))
if isinstance(line, str) and len(line) > 0:
exec_line(line)
except KeyboardInterrupt:
print ('^C\n')
continue
if TTY:
print ('^C\n')
continue
else:
break
except EOFError:
print ()
printtty()
sys.exit(0)