-
Notifications
You must be signed in to change notification settings - Fork 6
/
run.py
89 lines (81 loc) · 3.62 KB
/
run.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import tools
import subprocess as sp
import sys
import logging
import os
logging.basicConfig(level=logging.DEBUG)
l = logging.getLogger(__name__)
system = tools.GECKO_VM()
def matlab_command(gem):
cmd = """
cd {}geckomat
if endsWith('{}','.xml')
model = importModel('{}');
elseif endsWith('{}','.mat')
model = load('{}');
else
error('Model file format is not compatible with GECKO')
end
model = model{};
modelname = '{}';
[ecModel, ecModel_batch] = enhanceGEM(model,'COBRA', modelname, '{}');
cd ../models
save([modelname '/' modelname '.mat']','ecModel');
save([modelname '/' modelname '_batch.mat'], 'ecModel_batch');
quit;
""".format(system.install_dir('GECKO'), system.model_file_location(gem), system.model_file_location(gem), system.model_file_location(gem), system.model_file_location(gem), system.mat_model(gem), gem, system.version(gem))
l.info(cmd)
output = sp.check_output(['/usr/local/bin/matlab', '-nodisplay -nosplash -nodesktop -batch', '"{}"'.format(cmd)])
return output.decode('utf-8')
def setup_and_run_GECKO(gem):
system.git_clone('GECKO', system.config['GECKO']['branch'])
l.info('Merge `scripts` folder if it exists')
cmd = """
fileNames = dir('{}');
for i = 1:length(fileNames)
fileName = fileNames(i).name;
if ~strncmp(fileName, '.', 1)
fullName = ['{}/' fileName];
GECKO_path = dir(['{}**/' fileName]);
GECKO_path = GECKO_path.folder;
copyfile(fullName, GECKO_path)
end
end
quit;
""".format(system.scripts(gem), system.scripts(gem), system.install_dir('GECKO'))
l.info(cmd)
output = sp.check_output(['/usr/local/bin/matlab', '-nodisplay -nosplash -nodesktop -batch', '"{}"'.format(cmd)])
l.info(output.decode('utf-8'))
system.cleanup('GECKO', 'models/' + gem)
sp.check_output(['mkdir', system.install_dir('GECKO') + 'models/' + gem])
system.git_checkout(gem)
l.info('Running MATLAB command')
matlab_output = matlab_command(gem)
l.info(matlab_output)
l.info('Copying resulting model files from the GECKO output folder into the current repository')
sp.check_output(['cp', '-Rf', system.install_dir('GECKO') + 'models/' + gem + '/.', system.RUNNER_WORKSPACE + gem + '/model/'])
system.git_add_and_pr(gem, matlab_output)
system.cleanup('GECKO')
if __name__ == "__main__":
system.PIPELINE_BASE_BRANCH = sys.argv[1]
l.info('Pipeline started on branch {}'.format(system.PIPELINE_BASE_BRANCH))
l.info('Checking all dependencies listed in config.ini of type not `gem`.')
system.check_dependencies()
# Run GECKO wherever needed
for gem in system.gems():
system.cleanup(gem)
new_version = system.download(gem)
old_version = system.version(gem)
if system.HAS_CHANGES or git_version != old_version:
if system.HAS_CHANGES:
l.warning('System config has changed, have to run GECKO on {} {}'.format(gem, new_version))
else:
l.warning('{} changed from {} to {}'.format(gem, old_version, new_version))
l.info('Going to run GECKO on {}, saving config file before running'.format(gem))
system.version(gem, new_version)
system.save_config()
setup_and_run_GECKO(gem)
l.info('Reverting changes on config file made for {}, proceeding to next gem'.format(gem))
system.version(gem, old_version)
system.save_config()
system.cleanup(gem)