Commit b886ca20 authored by Alan Mitchell's avatar Alan Mitchell
Browse files

Fixed bugs in periodic script feature.

parent 2cea3533
......@@ -631,6 +631,9 @@ class PeriodicScript(models.Model):
# Results of the script saved and passed to the next invocation of the script.
script_results = models.TextField('Script results in YAML form', blank=True)
def __unicode__(self):
return '%s -- %s' % (self.script_file_name, self.script_parameters.replace('\n', ', '))
def choice_text(val, choices):
"""Returns the display text associated with the choice value 'val'
......
......@@ -2,5 +2,5 @@
Script to collect sensor readings from an OkoFEN pellet boiler.
'''
def run():
pass
def run(**kwargs):
return {'parameters': str(kwargs)}
......@@ -90,7 +90,12 @@ class RunScript(threading.Thread):
# last run of the script. Both of the those sets of parameters are in YAML
# form.
params = yaml.load(self.script.script_parameters)
params.update(yaml.load(self.script.script_results))
last_script_results = yaml.load(self.script.script_results)
if type(last_script_results) != dict:
# There may not have been any script results, or the YAML translation
# did not produce a dictionary.
last_script_results = {}
params.update(last_script_results)
# import the periodic script module, but first strip off any extension that
# the user may have appended
......@@ -99,7 +104,7 @@ class RunScript(threading.Thread):
# The script is coded in the 'run' function, so run it with the input parameters
# and record the execution time.
start = time.time()
script_results = script_mod.run(params)
script_results = script_mod.run(**params)
exec_time = time.time() - start
results['script_execution_time'] = round(exec_time, 2)
......@@ -133,6 +138,6 @@ class RunScript(threading.Thread):
# Store the results back into the model script object so they are
# viewable in the Admin interface and are available for the next call.
self.script.script_results = yaml.dump(results)
self.script.script_results.save()
self.script.save()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment