Interface handler can suggest names

The interface handler can suggest names for loaded
relations.

This can be used to remove duplicated code.
master
Salvo 'LtWorf' Tomaselli 2015-06-17 16:35:01 +07:00
parent 05e13bfeac
commit 59d712e53f
1 changed files with 20 additions and 0 deletions

@ -21,6 +21,7 @@
import http.client
import urllib.parse
import os.path
from relational.relation import relation
from relational import parser
@ -93,6 +94,25 @@ class user_interface (object):
raise Exception('Invalid name for destination relation')
self.relations[name] = rel
def suggest_name(self, filename):
'''
Returns a possible name for a relation, given
a filename.
If it is impossible to extract a possible name,
returns None
'''
name = os.path.basename(filename).lower()
if len(name) == 0:
return None
if (name.endswith(".csv")): # removes the extension
name = name[:-4]
if not is_valid_relation_name(name):
return None
return name
def execute(self, query, relname='last_'):
'''Executes a query, returns the result and if
relname is not None, adds the result to the