Load JOY_HOME/definitions.txt

You still can't edit other text files from within the UI, but at least
now you have a place to persist your own definitions over restarts.

I thought about having a [definitions] section in the config INI file,
but for some reason I prefer a separate definitions.txt file.  I dunno.
Might change it in future.
This commit is contained in:
Simon Forman
2018-07-22 11:50:34 -07:00
parent 17b9fba65e
commit 4ed8422258
2 changed files with 9 additions and 2 deletions
+7
View File
@@ -380,6 +380,13 @@ class DefinitionWrapper(object):
_log.info('Adding definition %s := %s', F.name, expression_to_string(F.body))
dictionary[F.name] = F
@classmethod
def load_definitions(class_, filename, dictionary):
with open(filename) as f:
lines = [line for line in f if '==' in line]
for line in lines:
class_.add_def(line, dictionary)
def _text_to_defs(text):
return (line.strip() for line in text.splitlines() if '==' in line)