-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.gradle
More file actions
166 lines (141 loc) · 5.54 KB
/
build.gradle
File metadata and controls
166 lines (141 loc) · 5.54 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
class PrintExec extends Exec {
PrintExec() {
ignoreExitValue true
workingDir '.'
setStandardOutput(new ByteArrayOutputStream())
setErrorOutput(new ByteArrayOutputStream())
doLast {
println commandLine.join(" ")
try {
execResult.assertNormalExitValue()
} catch (Exception e) {
println e.getMessage()
println standardOutput.toString()
println errorOutput.toString()
throw e
}
}
}
protected void exec() {
try {
super.exec()
} catch (Exception e) {
println 'Problem running program, error messages follow'
println '---'
Throwable t = e
while (t != null) {
println t.getMessage()
t = t.getCause();
}
println '---'
throw e
}
}
}
def checkProperties() {
for ( prop in ['PIMP_RSCRIPT_PATH'] ) {
if ( project.ext.props[prop] == null ) {
throw new Exception('Property ' + prop + ' is not set in the configuration file')
}
}
}
task setupProjectProperties {
Properties props = new Properties()
props.load(new FileInputStream('django_projects/pimp/.env'))
project.ext.props = props
checkProperties()
project.ext.props['PATH'] = 'venv/bin' + ':' + "$System.env.PATH"
}
/*
task setPythonVersion(type: PrintExec, dependsOn: setupProjectProperties) {
commandLine project.ext.props.Python, 'getPythonVersion.py'
doLast {
project.ext.PythonVersion = standardOutput.toString()
}
}
task setJavaVersion(type: PrintExec, dependsOn: setupProjectProperties) {
commandLine project.ext.props.Java, '-cp', '.', 'GetJavaVersion'
doLast {
project.ext.JavaVersion = standardOutput.toString()
}
}
task setRVersion(type: PrintExec, dependsOn: setupProjectProperties) {
commandLine project.ext.props.Rscript, 'getRVersion.R'
doLast {
project.ext.RVersion = standardOutput.toString()
}
}
task checkVersions(dependsOn: [setPythonVersion, setRVersion, setJavaVersion]) << {
println 'R Version: ' + project.ext.RVersion
println 'Python Version: ' + project.ext.PythonVersion
println 'Java Version: ' + project.ext.JavaVersion
}
task copyRpkg (type: Copy) {
from('PiMP') {
into 'PiMP'
}
from('PiMPDB') {
into 'PiMPDB'
}
into 'build'
}
task createPiMP(type: Exec, dependsOn: [copyRpkg, setupProjectProperties]) {
workingDir 'build'
commandLine project.ext.props.R, 'CMD', 'build', 'PiMP'
}
task createPiMPDB(type: Exec, dependsOn: [copyRpkg, setupProjectProperties]) {
workingDir 'build'
commandLine project.ext.props.R, 'CMD', 'build', 'PiMPDB'
}
*/
task createVirtualEnvironment(type: PrintExec) {
onlyIf {
! file('venv').exists()
}
commandLine 'python', 'virtualenv/virtualenv.py', '--python=python2.7', 'venv'
}
task installPiMPRequirements(type: Exec, dependsOn: createVirtualEnvironment) {
commandLine 'venv/bin/pip', 'install', '-r', 'django_projects/requirements.txt'
}
task installFrankRequirements(type: Exec, dependsOn: createVirtualEnvironment) {
commandLine 'venv/bin/pip', 'install', '-r', 'django_projects/requirements_frank.txt'
}
task installPiMPPythonDependencies(dependsOn: [installPiMPRequirements, installFrankRequirements])
task installPiMPRDependencies(type: Exec, dependsOn: setupProjectProperties) {
commandLine project.ext.props.PIMP_RSCRIPT_PATH, 'setupR.R', '--args', '--bootstrap-packrat'
}
task updatePiMPR(type: Exec, dependsOn: setupProjectProperties) {
commandLine project.ext.props.PIMP_RSCRIPT_PATH, 'update_pimp.R'
}
task installPiMPDependencies(dependsOn: [installPiMPPythonDependencies, installPiMPRDependencies])
task synchroniseDatabase(type: Exec, dependsOn: [installPiMPPythonDependencies, setupProjectProperties]) {
//println project.ext.props.PATH
environment 'PATH', project.ext.props['PATH']
commandLine 'venv/bin/honcho', '-e', 'django_projects/pimp/.env', 'run', 'venv/bin/python2.7', 'django_projects/pimp/manage.py', 'migrate'
}
task makeMigrateDatabase(type: Exec) {
environment 'PATH', project.ext.props['PATH']
commandLine 'venv/bin/honcho', '-e', 'django_projects/pimp/.env', 'run', 'venv/bin/python2.7', 'django_projects/pimp/manage.py', 'makemigrations'
}
/*
task populatePiMP (type: Exec, dependsOn: [installPiMPPythonDependencies, setupProjectProperties, synchroniseDatabase]) {
environment 'PATH', project.ext.props['PATH']
commandLine 'venv/bin/honcho', '-e', 'django_projects/pimp/.env', 'run', 'venv/bin/python2.7', 'django_projects/pimp/manage.py', 'populate_parameters'
}
*/
task createSuperUser(dependsOn: [installPiMPPythonDependencies, setupProjectProperties, synchroniseDatabase]) << {
def command = ['venv/bin/honcho', '-e', 'django_projects/pimp/.env', 'run', 'venv/bin/python2.7', '-u', 'django_projects/pimp/setupInitialUser.py']
def proc = new ProcessBuilder(command)
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectInput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
proc.waitFor()
}
task setupPiMP(dependsOn: [synchroniseDatabase, createSuperUser])
task installPiMP(dependsOn: [installPiMPDependencies, setupPiMP])
task runPiMP(type: Exec) {
environment 'PATH', project.ext.props['PATH']
workingDir 'django_projects/pimp'
commandLine '../../venv/bin/honcho', 'start'
}