Commit 5645356f authored by Theresa Pollinger's avatar Theresa Pollinger
Browse files

putting and executing exastencils in users home

parent 51ed0bc8
...@@ -19,7 +19,7 @@ class ExaOutput: ...@@ -19,7 +19,7 @@ class ExaOutput:
but only if simdata is given""" but only if simdata is given"""
def __init__(self, simdata=None, username="user", probname=None): def __init__(self, simdata=None, username="user", probname=None):
remove_ensuremaths() remove_ensuremaths()
self.exastencils_path = Path(os.path.dirname(__file__)).joinpath("./exastencils") self.exastencils_path = Path.home().joinpath("./exastencils")
self.username = username self.username = username
...@@ -179,7 +179,7 @@ class ExaOutput: ...@@ -179,7 +179,7 @@ class ExaOutput:
def create_l4(self): def create_l4(self):
l4path = str(self.filespath.with_suffix('.exa4')) l4path = str(self.filespath.with_suffix('.exa4'))
with open(l4path,'w') as l4: with open(l4path, 'w') as l4:
l4.write( l4.write(
"Function Application ( ) : Unit { \n" "Function Application ( ) : Unit { \n"
" startTimer ( 'setup' ) \n" " startTimer ( 'setup' ) \n"
...@@ -227,13 +227,13 @@ class ExaOutput: ...@@ -227,13 +227,13 @@ class ExaOutput:
def create_platform(self): def create_platform(self):
platformpath = str(self.filespath) + '.platform' platformpath = str(self.filespath) + '.platform'
with open(platformpath,'w') as platformfile: with open(platformpath, 'w') as platformfile:
for key in self.platform: for key in self.platform:
platformfile.write(self.format_key(key, self.platform)) platformfile.write(self.format_key(key, self.platform))
def create_knowledge(self): def create_knowledge(self):
knowledgepath = str(self.filespath) + '.knowledge' knowledgepath = str(self.filespath) + '.knowledge'
with open(knowledgepath,'w') as knowledgefile: with open(knowledgepath, 'w') as knowledgefile:
# for key in self.knowledge: # for key in self.knowledge:
# knowledgefile.write(self.format_key(key, self.knowledge)) # knowledgefile.write(self.format_key(key, self.knowledge))
knowledgefile.write( knowledgefile.write(
...@@ -271,7 +271,8 @@ class ExaRunner: ...@@ -271,7 +271,8 @@ class ExaRunner:
@lru_cache() @lru_cache()
def load_data(self, data_name="u"): # TODO more dimensions def load_data(self, data_name="u"): # TODO more dimensions
import pandas as pd import pandas as pd
data_path = self.exaout.exastencils_path.joinpath("generated").joinpath(self.exaout.probname).joinpath(data_name).with_suffix(".dat") data_path = self.exaout.exastencils_path.joinpath("generated").joinpath(self.exaout.probname)\
.joinpath(data_name).with_suffix(".dat")
df = pd.read_csv(data_path, sep=' ', index_col=0) df = pd.read_csv(data_path, sep=' ', index_col=0)
try: try:
df.columns = [data_name] df.columns = [data_name]
......
...@@ -7,8 +7,9 @@ from .interview_kernel import Interview ...@@ -7,8 +7,9 @@ from .interview_kernel import Interview
from jupyter_client.kernelspec import KernelSpecManager from jupyter_client.kernelspec import KernelSpecManager
from IPython.utils.tempdir import TemporaryDirectory from IPython.utils.tempdir import TemporaryDirectory
from shutil import copyfile import shutil
import errno
from pathlib import Path
kernel_json = { kernel_json = {
...@@ -22,7 +23,7 @@ kernel_json = { ...@@ -22,7 +23,7 @@ kernel_json = {
def install_my_kernel_spec(user=True, prefix=None): def install_my_kernel_spec(user=True, prefix=None):
with TemporaryDirectory() as td: with TemporaryDirectory() as td:
os.chmod(td, 0o755) # Starts off as 700, not user readable os.chmod(td, 0o755) # Starts off as 700, not user readable
with open(os.path.join(td, 'kernel.json'), 'w') as f: with open(os.path.join(td, 'kernel.json'), 'w') as f:
json.dump(kernel_json, f, sort_keys=True) json.dump(kernel_json, f, sort_keys=True)
try: try:
...@@ -50,11 +51,23 @@ def install_my_kernel_spec(user=True, prefix=None): ...@@ -50,11 +51,23 @@ def install_my_kernel_spec(user=True, prefix=None):
except Exception: except Exception:
print('could not copy kernel.js, will not see initial message in notebook') print('could not copy kernel.js, will not see initial message in notebook')
#raise
print("Installing Jupyter kernel spec") print("Installing Jupyter kernel spec")
KernelSpecManager().install_kernel_spec(td, 'Interview', user=user, prefix=prefix) KernelSpecManager().install_kernel_spec(td, 'Interview', user=user, prefix=prefix)
# copy exastencils directory to user's home
src = Path(os.path.dirname(__file__)).joinpath("./exastencils")
dest = Path.home().joinpath("./exastencils")
try:
shutil.copytree(src, dest)
except OSError as e:
# If the error was caused because the source wasn't a directory
if e.errno == errno.ENOTDIR:
shutil.copy(src, dest)
else:
print('Directory not copied. Error: %s' % e)
def _is_root(): def _is_root():
try: try:
return os.geteuid() == 0 return os.geteuid() == 0
......
...@@ -90,7 +90,7 @@ Otherwise, you can always answer with \LaTeX-type input. ...@@ -90,7 +90,7 @@ Otherwise, you can always answer with \LaTeX-type input.
def do_execute_direct(self, code, silent=False, allow_stdin=True): def do_execute_direct(self, code, silent=False, allow_stdin=True):
"""This is where the user input enters our code""" """This is where the user input enters our code"""
arg = string_handling.replace_times_to_cdot(LatexNodes2Text().latex_to_text(code)) arg = string_handling.replace_times_to_cdot(LatexNodes2Text().latex_to_text(code)).strip()
if not self.keyword_handling(arg): if not self.keyword_handling(arg):
if not self.prompt_input_handling(arg): if not self.prompt_input_handling(arg):
...@@ -101,12 +101,6 @@ Otherwise, you can always answer with \LaTeX-type input. ...@@ -101,12 +101,6 @@ Otherwise, you can always answer with \LaTeX-type input.
# string output # string output
stream_content = {'name': self.outstream_name, 'text': self.poutstring} stream_content = {'name': self.outstream_name, 'text': self.poutstring}
self.send_response(self.iopub_socket, 'stream', stream_content) self.send_response(self.iopub_socket, 'stream', stream_content)
# data_content = {
# "ename": "InterviewError",
# "evalue": self.poutstring,
# "traceback": [self.poutstring],
# }
# self.send_response(self.iopub_socket, 'error', data_content)
else: else:
# for other mime types, cf. http://ipython.org/ipython-doc/stable/notebook/nbformat.html # for other mime types, cf. http://ipython.org/ipython-doc/stable/notebook/nbformat.html
data_content = {"data": { data_content = {"data": {
......
Supports Markdown
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