From 59d712e53f680f962196d2b7771703efe583687e Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Wed, 17 Jun 2015 16:35:01 +0200 Subject: [PATCH] Interface handler can suggest names The interface handler can suggest names for loaded relations. This can be used to remove duplicated code. --- relational/maintenance.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/relational/maintenance.py b/relational/maintenance.py index 1f79c44..c7845a8 100644 --- a/relational/maintenance.py +++ b/relational/maintenance.py @@ -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