diff options
author | Jayaram R Pai | 2014-08-21 19:46:18 +0530 |
---|---|---|
committer | Jayaram R Pai | 2014-08-21 19:46:18 +0530 |
commit | 6349505c1b9cb638d562bd06a75a26109b106f0d (patch) | |
tree | aeed4f0c7a3b985ea735ec3c424f8504cea70eac /website/helpers.py | |
parent | 1ced43baf6c586f6af51b13eeb72f24dc5906be2 (diff) | |
download | scilab-on-cloud-6349505c1b9cb638d562bd06a75a26109b106f0d.tar.gz scilab-on-cloud-6349505c1b9cb638d562bd06a75a26109b106f0d.tar.bz2 scilab-on-cloud-6349505c1b9cb638d562bd06a75a26109b106f0d.zip |
added lightbox to display plot
Diffstat (limited to 'website/helpers.py')
-rw-r--r-- | website/helpers.py | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/website/helpers.py b/website/helpers.py index eac7720..016f2fd 100644 --- a/website/helpers.py +++ b/website/helpers.py @@ -5,7 +5,7 @@ import subprocess from soc.settings import PROJECT_DIR -def scilab_run(code, token): +def scilab_run(code, token, example_id): #Check for system commands system_commands = re.compile( 'unix\(.*\)|unix_g\(.*\)|unix_w\(.*\)|unix_x\(.*\)|unix_s\(.*\)' @@ -20,24 +20,14 @@ def scilab_run(code, token): #Finding the plot and appending xs2jpg function p = re.compile(r'.*plot.*\(.*,.*,*\).*\n') + + plot_path = '' if p.search(code): plot_exists = True code = code + '\n' - temp = code - code = '' - start, end, count = 0, 0, 0 current_time = time.time() - plot_path = [] - for (count, match) in enumerate(p.finditer(temp)): - print "count==================",count - plot_path.append( - PROJECT_DIR + '/static/tmp/{0}.jpg'.format(int(current_time) + count) - ) - end = match.end() - code += temp[start:end] - code += 'xs2jpg(gcf(), "{0}");\n'.format(plot_path[-1]) - start = end - code += temp[end:] + plot_path = PROJECT_DIR + '/static/tmp/{0}.jpg'.format(str(current_time)) + code += 'xs2jpg(gcf(), "{0}");\n'.format(plot_path) #Check whether to load scimax / maxima if 'syms' in code or 'Syms' in code: @@ -59,7 +49,6 @@ def scilab_run(code, token): #getting stuck in the prompt in case of error cmd = 'printf "lines(0)\nexec(\'{0}\',2);\nquit();"'.format(file_path) cmd += ' | /home/cheese/scilab-5.4.1/bin/scilab-adv-cli -nw' - print cmd output = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True @@ -67,10 +56,13 @@ def scilab_run(code, token): #os.remove(file_path) output = trim(output) - return output + data = { + 'output': output, + 'plot_path': plot_path.replace(PROJECT_DIR, '') + } + return data def trim(output): #for future use output = re.sub(r'\n \n \n', '\n', output) - #print repr(output) return output |