-
Notifications
You must be signed in to change notification settings - Fork 5
/
KeplerMagicFunction.py
executable file
·72 lines (61 loc) · 1.79 KB
/
KeplerMagicFunction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'''
If we want only one function with different parameters, we have to use argparse
'''
from __future__ import print_function
import os
import argparse
from IPython.core.magic import (Magics, magics_class, line_magic,
cell_magic, line_cell_magic)
from KeplerMagicLib import Kepler_Magic
@magics_class
class KeplerMagic(Magics):
KeplerPath = ''
WorkFlowPath = ''
TargetFilePath = ''
wk = Kepler_Magic()
@line_magic
def Kepler(self,line):
if self.KeplerPath =='':
if os.path.isfile('kppath.txt'):
fh = open('kppath.txt','r')
self.KeplerPath = fh.readline()
paramHolder = str(line)
if os.path.isfile(self.WorkFlowPath):
if os.path.isfile(self.KeplerPath):
self.wk.runKepler(self.KeplerPath,self.WorkFlowPath,self.TargetFilePath, paramHolder)
else:
return "Please specify Kepler path with KpConf kepler path"
else:
return "Please specify workflwo path with WpConf workflwo path"
@line_magic
def readoutput(self,line):
result = self.wk.readKeplerOutput(self.TargetFilePath+'/'+line)
#It seems it has a problem with removing the output file!!
#self.wk.removeKeplerOutputFile(self.TargetFilePath+'/'+line)
if line.endswith('.png'):
return result
else:
print(result)
@line_magic
def KpConf(self,line):
if line :
try:
fh = open('kppath.txt','w+')
fh.truncate()
fh.write(line)
fh.close()
except IOError as e:
Error = "Cannot creat/open kepler path file"
self.KeplerPath = line
@line_magic
def WpConf(self,line):
if line:
if self.TargetFilePath == '':
self.TargetFilePath = os.path.dirname(os.path.realpath(line))
self.WorkFlowPath = line
@line_magic
def TgConf(self,line):
if line:
self.TargetFilePath = line
ip = get_ipython()
ip.register_magics(KeplerMagic)