- Can easily insert operators

- Gracefully terminates
- Doesn't list hidden python stuff


git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@229 014f5005-505e-4b48-8d0a-63407b615a7c
master
LtWorf 2010-06-21 14:12:43 +07:00
parent f3dbab3993
commit 5de25127c9
1 changed files with 27 additions and 4 deletions

@ -70,7 +70,7 @@ class SimpleCompleter(object):
relations={} relations={}
completer=SimpleCompleter(['LIST','LOAD ','UNLOAD ','HELP','QUIT','SAVE ']) completer=SimpleCompleter(['LIST','LOAD ','UNLOAD ','HELP','QUIT','SAVE ','_PRODUCT ','_UNION ','_INTERSECTION ','_DIFFERENCE ','_JOIN ','_LJOIN ','_RJOIN ','_FJOIN ','_PROJECTION ','_RENAME_TO ','_SELECTION ','_RENAME '])
def load_relation(filename,defname=None): def load_relation(filename,defname=None):
@ -100,6 +100,7 @@ def exec_line(command):
pass pass
elif command=='LIST': #Lists all the loaded relations elif command=='LIST': #Lists all the loaded relations
for i in relations: for i in relations:
if not i.startswith('_'):
print i print i
elif command.startswith('LOAD '): #Loads a relation elif command.startswith('LOAD '): #Loads a relation
pars=command.split(' ') pars=command.split(' ')
@ -121,7 +122,23 @@ def exec_line(command):
else: else:
exec_query( command) exec_query( command)
def replacements(query):
query=query.replace( '_PRODUCT' , '*')
query=query.replace( '_UNION' , '')
query=query.replace( '_INTERSECTION' , '')
query=query.replace( '_DIFFERENCE' , '-')
query=query.replace( '_JOIN' , 'ᐅᐊ')
query=query.replace( '_LJOIN' , 'ᐅLEFTᐊ')
query=query.replace( '_RJOIN' , 'ᐅRIGHTᐊ')
query=query.replace( '_FJOIN' , 'ᐅFULLᐊ')
query=query.replace( '_PROJECTION' , 'π')
query=query.replace( '_RENAME_TO' , '')
query=query.replace( '_SELECTION' , 'σ')
query=query.replace( '_RENAME' , 'ρ')
return query
def exec_query(command): def exec_query(command):
'''This function executes a query and prints the result on the screen'''
#Finds the name in where to save the query #Finds the name in where to save the query
@ -143,6 +160,8 @@ def exec_query(command):
relname='last_' relname='last_'
query=command query=command
#Performs replacements for weird operators
query=replacements(query)
#Execute query #Execute query
try: try:
@ -165,8 +184,12 @@ def main(files=[]):
readline.parse_and_bind('set editing-mode vi') readline.parse_and_bind('set editing-mode vi')
while True: while True:
try:
line = raw_input('> ') line = raw_input('> ')
exec_line(line) exec_line(line)
except:
print
sys.exit(0)