commit
7a43071faf
2
Makefile
2
Makefile
@ -17,7 +17,7 @@ relational_gui/resources.py:
|
|||||||
|
|
||||||
.PHONY: mypy
|
.PHONY: mypy
|
||||||
mypy:
|
mypy:
|
||||||
mypy relational
|
mypy relational relational_readline
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test:
|
test:
|
||||||
|
@ -134,7 +134,7 @@ class Relation(NamedTuple):
|
|||||||
try:
|
try:
|
||||||
c_expr = compile(expr, 'selection', 'eval')
|
c_expr = compile(expr, 'selection', 'eval')
|
||||||
except:
|
except:
|
||||||
raise Exception('Failed to compile expression: %s' % expr)
|
raise Exception(f'Failed to compile expression: {expr}')
|
||||||
|
|
||||||
content = []
|
content = []
|
||||||
for i in self.content:
|
for i in self.content:
|
||||||
@ -147,8 +147,7 @@ class Relation(NamedTuple):
|
|||||||
if eval(c_expr, attributes):
|
if eval(c_expr, attributes):
|
||||||
content.append(i)
|
content.append(i)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(
|
raise Exception(f'Failed to evaluate {expr}\n{e}')
|
||||||
"Failed to evaluate %s\n%s" % (expr, e.__str__()))
|
|
||||||
return Relation(header, frozenset(content))
|
return Relation(header, frozenset(content))
|
||||||
|
|
||||||
def product(self, other: 'Relation') -> 'Relation':
|
def product(self, other: 'Relation') -> 'Relation':
|
||||||
@ -403,7 +402,7 @@ class Header(tuple):
|
|||||||
|
|
||||||
for i in self:
|
for i in self:
|
||||||
if not is_valid_relation_name(i):
|
if not is_valid_relation_name(i):
|
||||||
raise Exception('"%s" is not a valid attribute name' % i)
|
raise Exception(f'"{i}" is not a valid attribute name')
|
||||||
|
|
||||||
if len(self) != len(set(self)):
|
if len(self) != len(set(self)):
|
||||||
raise Exception('Attribute names must be unique')
|
raise Exception('Attribute names must be unique')
|
||||||
@ -419,12 +418,12 @@ class Header(tuple):
|
|||||||
attrs = list(self)
|
attrs = list(self)
|
||||||
for old, new in params.items():
|
for old, new in params.items():
|
||||||
if not is_valid_relation_name(new):
|
if not is_valid_relation_name(new):
|
||||||
raise Exception('%s is not a valid attribute name' % new)
|
raise Exception(f'{new} is not a valid attribute name')
|
||||||
try:
|
try:
|
||||||
id_ = attrs.index(old)
|
id_ = attrs.index(old)
|
||||||
attrs[id_] = new
|
attrs[id_] = new
|
||||||
except:
|
except:
|
||||||
raise Exception('Field not found: %s' % old)
|
raise Exception(f'Field not found: {old}')
|
||||||
return Header(attrs)
|
return Header(attrs)
|
||||||
|
|
||||||
def sharedAttributes(self, other: 'Header') -> int:
|
def sharedAttributes(self, other: 'Header') -> int:
|
||||||
|
@ -27,7 +27,7 @@ from typing import Optional
|
|||||||
|
|
||||||
from relational import relation, parser, rtypes
|
from relational import relation, parser, rtypes
|
||||||
from relational import maintenance
|
from relational import maintenance
|
||||||
from xtermcolor import colorize
|
from xtermcolor import colorize # type: ignore
|
||||||
|
|
||||||
PROMPT_COLOR = 0xffff00
|
PROMPT_COLOR = 0xffff00
|
||||||
ERROR_COLOR = 0xff0000
|
ERROR_COLOR = 0xff0000
|
||||||
@ -113,7 +113,7 @@ completer = SimpleCompleter(
|
|||||||
'_DIFFERENCE ', '_JOIN ', '_LJOIN ', '_RJOIN ', '_FJOIN ', '_PROJECTION ', '_RENAME_TO ', '_SELECTION ', '_RENAME ', '_DIVISION '])
|
'_DIFFERENCE ', '_JOIN ', '_LJOIN ', '_RJOIN ', '_FJOIN ', '_PROJECTION ', '_RENAME_TO ', '_SELECTION ', '_RENAME ', '_DIVISION '])
|
||||||
|
|
||||||
|
|
||||||
def load_relation(filename: str, defname:Optional[str]=None) -> Optional[str]:
|
def load_relation(filename: str, defname: Optional[str]) -> Optional[str]:
|
||||||
'''
|
'''
|
||||||
Loads a relation into the set. Defname is the given name
|
Loads a relation into the set. Defname is the given name
|
||||||
to the relation.
|
to the relation.
|
||||||
@ -123,7 +123,7 @@ def load_relation(filename: str, defname:Optional[str]=None) -> Optional[str]:
|
|||||||
'''
|
'''
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
print(colorize(
|
print(colorize(
|
||||||
"%s is not a file" % filename, ERROR_COLOR), file=sys.stderr)
|
f'{filename} is not a file', ERROR_COLOR), file=sys.stderr)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if defname is None:
|
if defname is None:
|
||||||
@ -137,7 +137,7 @@ def load_relation(filename: str, defname:Optional[str]=None) -> 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(filename)
|
relations[defname] = relation.Relation.load(filename)
|
||||||
|
|
||||||
completer.add_completion(defname)
|
completer.add_completion(defname)
|
||||||
printtty(colorize("Loaded relation %s" % defname, COLOR_GREEN))
|
printtty(colorize("Loaded relation %s" % defname, COLOR_GREEN))
|
||||||
@ -216,10 +216,9 @@ def exec_line(command: str) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
filename = pars[1]
|
filename = pars[1]
|
||||||
|
defname = None
|
||||||
if len(pars) > 2:
|
if len(pars) > 2:
|
||||||
defname = pars[2]
|
defname = pars[2]
|
||||||
else:
|
|
||||||
defname = None
|
|
||||||
load_relation(filename, defname)
|
load_relation(filename, defname)
|
||||||
|
|
||||||
elif command.startswith('UNLOAD '):
|
elif command.startswith('UNLOAD '):
|
||||||
@ -320,7 +319,7 @@ def main(files=[]):
|
|||||||
"; 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:
|
||||||
load_relation(i)
|
load_relation(i, None)
|
||||||
|
|
||||||
readline.set_completer(completer.complete)
|
readline.set_completer(completer.complete)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user