Fix cli for the double format
This commit is contained in:
parent
a110f3f2c5
commit
ae2e838df2
@ -1,5 +1,5 @@
|
|||||||
# Relational
|
# Relational
|
||||||
# Copyright (C) 2008-2017 Salvo "LtWorf" Tomaselli
|
# Copyright (C) 2008-2020 Salvo "LtWorf" Tomaselli
|
||||||
#
|
#
|
||||||
# Relation is free software: you can redistribute it and/or modify
|
# Relation is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -106,8 +106,7 @@ class SimpleCompleter:
|
|||||||
repr(text), state, repr(response))
|
repr(text), state, repr(response))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
ui = maintenance.UserInterface()
|
||||||
relations = {}
|
|
||||||
completer = SimpleCompleter(
|
completer = SimpleCompleter(
|
||||||
['SURVEY', 'LIST', 'LOAD ', 'UNLOAD ', 'HELP ', 'QUIT', 'SAVE ', '_PRODUCT ', '_UNION ', '_INTERSECTION ',
|
['SURVEY', 'LIST', 'LOAD ', 'UNLOAD ', 'HELP ', 'QUIT', 'SAVE ', '_PRODUCT ', '_UNION ', '_INTERSECTION ',
|
||||||
'_DIFFERENCE ', '_JOIN ', '_LJOIN ', '_RJOIN ', '_FJOIN ', '_PROJECTION ', '_RENAME_TO ', '_SELECTION ', '_RENAME ', '_DIVISION '])
|
'_DIFFERENCE ', '_JOIN ', '_LJOIN ', '_RJOIN ', '_FJOIN ', '_PROJECTION ', '_RENAME_TO ', '_SELECTION ', '_RENAME ', '_DIVISION '])
|
||||||
@ -137,7 +136,7 @@ def load_relation(filename: str, defname: Optional[str]) -> Optional[str]:
|
|||||||
"%s is not a valid relation name" % defname, ERROR_COLOR), file=sys.stderr)
|
"%s is not a valid relation name" % defname, ERROR_COLOR), file=sys.stderr)
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
relations[defname] = relation.Relation.load(filename)
|
ui.load(filename, defname)
|
||||||
|
|
||||||
completer.add_completion(defname)
|
completer.add_completion(defname)
|
||||||
printtty(colorize("Loaded relation %s" % defname, COLOR_GREEN))
|
printtty(colorize("Loaded relation %s" % defname, COLOR_GREEN))
|
||||||
@ -204,7 +203,7 @@ def exec_line(command: str) -> None:
|
|||||||
elif command.startswith('HELP'):
|
elif command.startswith('HELP'):
|
||||||
help(command)
|
help(command)
|
||||||
elif command == 'LIST': # Lists all the loaded relations
|
elif command == 'LIST': # Lists all the loaded relations
|
||||||
for i in relations:
|
for i in ui.relations:
|
||||||
if not i.startswith('_'):
|
if not i.startswith('_'):
|
||||||
print(i)
|
print(i)
|
||||||
elif command == 'SURVEY':
|
elif command == 'SURVEY':
|
||||||
@ -225,9 +224,10 @@ def exec_line(command: str) -> None:
|
|||||||
pars = command.split(' ')
|
pars = command.split(' ')
|
||||||
if len(pars) < 2:
|
if len(pars) < 2:
|
||||||
print(colorize("Missing parameter", ERROR_COLOR))
|
print(colorize("Missing parameter", ERROR_COLOR))
|
||||||
return
|
elif len(pars) > 2:
|
||||||
if pars[1] in relations:
|
print(colorize("Too many parameter", ERROR_COLOR))
|
||||||
del relations[pars[1]]
|
if pars[1] in ui.relations:
|
||||||
|
ui.unload(pars[1])
|
||||||
completer.remove_completion(pars[1])
|
completer.remove_completion(pars[1])
|
||||||
else:
|
else:
|
||||||
print(colorize("No such relation %s" % pars[1], ERROR_COLOR))
|
print(colorize("No such relation %s" % pars[1], ERROR_COLOR))
|
||||||
@ -240,11 +240,8 @@ def exec_line(command: str) -> None:
|
|||||||
filename = pars[1]
|
filename = pars[1]
|
||||||
defname = pars[2]
|
defname = pars[2]
|
||||||
|
|
||||||
if defname not in relations:
|
|
||||||
print(colorize("No such relation %s" % defname, ERROR_COLOR))
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
relations[defname].save(filename)
|
ui.store(filename, defname)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(colorize(e, ERROR_COLOR))
|
print(colorize(e, ERROR_COLOR))
|
||||||
else:
|
else:
|
||||||
@ -298,7 +295,7 @@ def exec_query(command: str) -> None:
|
|||||||
# Execute query
|
# Execute query
|
||||||
try:
|
try:
|
||||||
pyquery = parser.parse(query)
|
pyquery = parser.parse(query)
|
||||||
result = pyquery(relations)
|
result = pyquery(ui.relations)
|
||||||
|
|
||||||
printtty(colorize("-> query: %s" % pyquery, COLOR_GREEN))
|
printtty(colorize("-> query: %s" % pyquery, COLOR_GREEN))
|
||||||
|
|
||||||
@ -306,7 +303,7 @@ def exec_query(command: str) -> None:
|
|||||||
print()
|
print()
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
relations[relname] = result
|
ui.relations[relname] = result
|
||||||
|
|
||||||
completer.add_completion(relname)
|
completer.add_completion(relname)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user