Add documentation/typing to linegui
This commit is contained in:
parent
54e4d05837
commit
57936db6b9
@ -23,6 +23,7 @@ import logging
|
|||||||
import os.path
|
import os.path
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from relational import relation, parser, rtypes
|
from relational import relation, parser, rtypes
|
||||||
from relational import maintenance
|
from relational import maintenance
|
||||||
@ -46,10 +47,9 @@ class SimpleCompleter:
|
|||||||
|
|
||||||
'''Handles completion'''
|
'''Handles completion'''
|
||||||
|
|
||||||
def __init__(self, options):
|
def __init__(self, options) -> None:
|
||||||
'''Takes a list of valid completion options'''
|
'''Takes a list of valid completion options'''
|
||||||
self.options = sorted(options)
|
self.options = sorted(options)
|
||||||
return
|
|
||||||
|
|
||||||
def add_completion(self, option):
|
def add_completion(self, option):
|
||||||
'''Adds one string to the list of the valid completion options'''
|
'''Adds one string to the list of the valid completion options'''
|
||||||
@ -110,7 +110,14 @@ 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, defname=None):
|
def load_relation(filename: str, defname:Optional[str]=None) -> Optional[str]:
|
||||||
|
'''
|
||||||
|
Loads a relation into the set. Defname is the given name
|
||||||
|
to the relation.
|
||||||
|
|
||||||
|
Returns the name to the relation, or None if it was
|
||||||
|
not loaded.
|
||||||
|
'''
|
||||||
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)
|
"%s is not a file" % filename, ERROR_COLOR), file=sys.stderr)
|
||||||
@ -137,7 +144,7 @@ def load_relation(filename, defname=None):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def survey():
|
def survey() -> None:
|
||||||
'''performs a survey'''
|
'''performs a survey'''
|
||||||
post = {'software': 'Relational algebra (cli)', 'version': version}
|
post = {'software': 'Relational algebra (cli)', 'version': version}
|
||||||
|
|
||||||
@ -151,7 +158,7 @@ def survey():
|
|||||||
print('Yeah, not sending that.')
|
print('Yeah, not sending that.')
|
||||||
|
|
||||||
|
|
||||||
def help(command):
|
def help(command: str) -> None:
|
||||||
'''Prints help on the various functions'''
|
'''Prints help on the various functions'''
|
||||||
p = command.split(' ', 1)
|
p = command.split(' ', 1)
|
||||||
if len(p) == 1:
|
if len(p) == 1:
|
||||||
@ -176,10 +183,15 @@ def help(command):
|
|||||||
'HELP': 'Prints the help on a command',
|
'HELP': 'Prints the help on a command',
|
||||||
'SURVEY': 'Fill and send a survey',
|
'SURVEY': 'Fill and send a survey',
|
||||||
}
|
}
|
||||||
print (cmdhelp.get(cmd, 'Unknown command: %s' % cmd))
|
print(cmdhelp.get(cmd, 'Unknown command: %s' % cmd))
|
||||||
|
|
||||||
|
|
||||||
def exec_line(command):
|
def exec_line(command: str) -> None:
|
||||||
|
'''
|
||||||
|
Executes a line.
|
||||||
|
|
||||||
|
If it's a command, runs it, if it's a query runs it too
|
||||||
|
'''
|
||||||
command = command.strip()
|
command = command.strip()
|
||||||
|
|
||||||
if command.startswith(';'):
|
if command.startswith(';'):
|
||||||
@ -217,7 +229,6 @@ def exec_line(command):
|
|||||||
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))
|
||||||
pass
|
|
||||||
elif command.startswith('SAVE '):
|
elif command.startswith('SAVE '):
|
||||||
pars = command.split(' ')
|
pars = command.split(' ')
|
||||||
if len(pars) != 3:
|
if len(pars) != 3:
|
||||||
@ -238,7 +249,7 @@ def exec_line(command):
|
|||||||
exec_query(command)
|
exec_query(command)
|
||||||
|
|
||||||
|
|
||||||
def replacements(query):
|
def replacements(query: str) -> str:
|
||||||
'''This funcion replaces ascii easy operators with the correct ones'''
|
'''This funcion replaces ascii easy operators with the correct ones'''
|
||||||
rules = (
|
rules = (
|
||||||
('_PRODUCT', parser.PRODUCT),
|
('_PRODUCT', parser.PRODUCT),
|
||||||
@ -260,9 +271,12 @@ def replacements(query):
|
|||||||
return query
|
return query
|
||||||
|
|
||||||
|
|
||||||
def exec_query(command):
|
def exec_query(command: str) -> None:
|
||||||
'''This function executes a query and prints the result on the screen
|
'''
|
||||||
if the command terminates with ";" the result will not be printed
|
Executes a query and prints the result on the screen
|
||||||
|
if the command terminates with ";" the result will not be printed.
|
||||||
|
|
||||||
|
Updates the set of relations.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# If it terminates with ; doesn't print the result
|
# If it terminates with ; doesn't print the result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user