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.
This commit is contained in:
parent
643adf4d0a
commit
87e2c76468
@ -121,9 +121,10 @@ if __name__ == "__main__":
|
|||||||
form.show()
|
form.show()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
else:
|
else:
|
||||||
printver(False)
|
|
||||||
try:
|
try:
|
||||||
import relational_readline.linegui
|
import relational_readline.linegui
|
||||||
|
if relational_readline.linegui.TTY:
|
||||||
|
printver(False)
|
||||||
except:
|
except:
|
||||||
print (
|
print (
|
||||||
"Module relational_readline is missing.\nPlease install relational-cli package.",
|
"Module relational_readline is missing.\nPlease install relational-cli package.",
|
||||||
|
@ -30,6 +30,15 @@ from xtermcolor import colorize
|
|||||||
PROMPT_COLOR = 0xffff00
|
PROMPT_COLOR = 0xffff00
|
||||||
ERROR_COLOR = 0xff0000
|
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):
|
class SimpleCompleter(object):
|
||||||
|
|
||||||
@ -121,7 +130,7 @@ def load_relation(filename, defname=None):
|
|||||||
relations[defname] = relation.relation(filename)
|
relations[defname] = relation.relation(filename)
|
||||||
|
|
||||||
completer.add_completion(defname)
|
completer.add_completion(defname)
|
||||||
print (colorize("Loaded relation %s" % defname, 0x00ff00))
|
printtty(colorize("Loaded relation %s" % defname, 0x00ff00))
|
||||||
return defname
|
return defname
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print (colorize(e, ERROR_COLOR), file=sys.stderr)
|
print (colorize(e, ERROR_COLOR), file=sys.stderr)
|
||||||
@ -287,7 +296,7 @@ def exec_query(command):
|
|||||||
pyquery = parser.parse(query)
|
pyquery = parser.parse(query)
|
||||||
result = pyquery(relations)
|
result = pyquery(relations)
|
||||||
|
|
||||||
print (colorize("-> query: %s" % pyquery, 0x00ff00))
|
printtty(colorize("-> query: %s" % pyquery, 0x00ff00))
|
||||||
|
|
||||||
if printrel:
|
if printrel:
|
||||||
print ()
|
print ()
|
||||||
@ -301,8 +310,8 @@ def exec_query(command):
|
|||||||
|
|
||||||
|
|
||||||
def main(files=[]):
|
def main(files=[]):
|
||||||
print (colorize('> ', PROMPT_COLOR) + "; Type HELP to get the HELP")
|
printtty(colorize('> ', PROMPT_COLOR) + "; Type HELP to get the HELP")
|
||||||
print (colorize('> ', PROMPT_COLOR) +
|
printtty(colorize('> ', PROMPT_COLOR) +
|
||||||
"; Completion is activated using the tab (if supported by the terminal)")
|
"; Completion is activated using the tab (if supported by the terminal)")
|
||||||
|
|
||||||
for i in files:
|
for i in files:
|
||||||
@ -316,14 +325,18 @@ def main(files=[]):
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
line = input(colorize('> ', PROMPT_COLOR))
|
|
||||||
|
line = input(colorize('> ' if TTY else '', PROMPT_COLOR))
|
||||||
if isinstance(line, str) and len(line) > 0:
|
if isinstance(line, str) and len(line) > 0:
|
||||||
exec_line(line)
|
exec_line(line)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
if TTY:
|
||||||
print ('^C\n')
|
print ('^C\n')
|
||||||
continue
|
continue
|
||||||
|
else:
|
||||||
|
break
|
||||||
except EOFError:
|
except EOFError:
|
||||||
print ()
|
printtty()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user