/
build_server_package.py
111 lines (93 loc) · 3.96 KB
/
build_server_package.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from __future__ import with_statement
import os
#########################################
# Downloads a Virgo server and the OpenWorm
# bundles and creates a zip file that contains
# a configured Virgo server
# by: Stephen Larson (stephen@openworm.org)
#
# To use:
# * Make sure Maven (http://maven.apache.org) is installed
# * Make sure Fabric is installed:
# http://docs.fabfile.org/en/1.5/installation.html
# * Set JAVA_HOME and MAVEN_HOME directories below:
os.environ['JAVA_HOME'] = '/usr'
os.environ['MAVEN_HOME'] = '/usr'
#######################################
import urllib
import tempfile, shutil, zipfile, re, sys
from fabric.api import *
import os.path as op
#check to make sure Maven is pointed to appropriately
try:
with open(op.join(os.environ['MAVEN_HOME'], 'bin/mvn')) as f: pass
except IOError as e:
sys.exit("Can't find mvn under " + os.environ['MAVEN_HOME'] + "-- is MAVEN_HOME set appropriately?")
virgo_version = "3.6.0.RELEASE"
urls = ["http://www.eclipse.org/downloads/download.php?file=/virgo/release/VP/%s/virgo-tomcat-server-%s.zip&r=1"%(virgo_version, virgo_version)]
openwormpackages = ['org.openworm.simulationengine.core',
'org.openworm.simulationengine.samplesolver',
'org.openworm.simulationengine.samplesimulator',
'org.openworm.simulationengine.samplesimulation',
'org.openworm.simulationengine.model.sph',
'org.openworm.simulationengine.solver.sph',
'org.openworm.simulationengine.simulator.sph',
'org.openworm.simulationengine.simulation',
'org.openworm.simulationengine.frontend',
'org.openworm.simulationengine']
for p in openwormpackages:
urls = urls + ['https://github.com/openworm/' + p + '/archive/master.zip']
print urls
tempdir = tempfile.mkdtemp()
#download and unpack all packages into a temp directory
for u in urls:
print "Downloading: %s and unzipping into %s..."%(u,tempdir)
(zFile, x) = urllib.urlretrieve(u)
vz = zipfile.ZipFile(zFile)
vz.extractall(tempdir)
os.remove(zFile)
#make an openworm directory and move the contents of virgo into it
#so the final package has a nice name
with lcd(tempdir):
print local('mkdir -p package/openworm', capture=True)
print local("mv virgo-tomcat-server-%s/* package/openworm/"%(virgo_version), capture=True)
#set server home in temp directory
server_home = op.join(tempdir, 'package/openworm')
os.environ['SERVER_HOME'] = server_home
#use Maven to build all the OpenWorm code bundles
#and place the contents in the Virgo installation
for p in openwormpackages:
with lcd(tempdir):
print local('mv %s-master %s'%(p, p), capture=True)
dirp = op.join(tempdir, p)
print '**************************'
print 'BUILDING ' + dirp
print '**************************'
with lcd(dirp):
with settings(hide('everything'), warn_only=True):
print local('$MAVEN_HOME/bin/mvn install', capture=True)
print local('cp target/classes/lib/* $SERVER_HOME/repository/usr/', capture=True)
print local('cp target/* $SERVER_HOME/repository/usr/', capture=True)
#put the .plan file in the pickup folder
with lcd(op.join(tempdir, 'org.openworm.simulationengine')):
print local('cp owsefull.plan $SERVER_HOME/pickup/', capture=True)
#fix the properties file
f = open(op.join(server_home, 'repository/ext/org.eclipse.virgo.web.properties'), 'r+')
text = f.read()
text = re.sub('strict', 'defaulted', text)
f.seek(0)
f.write(text)
f.truncate()
f.close()
#set permissions on the bin directory
#these do carry over into the archive
with lcd(server_home):
print local('chmod -R +x ./bin', capture=True)
#zip up the contents of the virgo directory for distribution
archive_name = os.path.expanduser(os.path.join('~', 'openworm-snapshot'))
root_dir = os.path.expanduser(os.path.join(tempdir, 'package'))
snapshot = shutil.make_archive(archive_name, 'zip', root_dir)
#delete the temp directory
########################print 'Deleting temp directory'
########################shutil.rmtree(tempdir)
print 'Your snapshot is ready: ' + snapshot