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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
#!/usr/bin/env python
import subprocess
import optparse
import sys
from path import path
fromscratch = False
#download source tarball (live555-latest.tar.gz) from http://www.live555.com/liveMedia/public into $srcdir
LIVE555 = ['wget http://www.live555.com/liveMedia/public/live555-latest.tar.gz']
#download source tarball (ftp://xmlsoft.org/libxml2/libxml2-sources-2.7.1.tar.gz) from ftp://xmlsoft.org/libxml2 into $srcdir
LIBXML2 = ['wget ftp://xmlsoft.org/libxml2/libxml2-sources-2.7.1.tar.gz']
#download source tarball gettext-0.17.tar.gz into $srcdir
GETTEXT = ['wget ftp://ftp.gnu.org/gnu/gettext/gettext-0.17.tar.gz']
#download ffmpeg (svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg)
FFMPEG = ['svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg', 'cp -r $srcdir/ffmpeg .']
#Create a function, that takes a list parameter
#Function uses default keyword parameter of cmds
def runCommands(cmds):
#Iterates over list, running statements for each item in the list
count=0
for cmd in cmds:
count += 1
print "Running Command %s, %s" % (count, cmd)
subprocess.call(cmd, shell=True)
#If ROOTDIR does not exist, downloads ambulant, extracts to ROOTDIR
def fetchAmbulant():
if ROOTDIR.exists():
fromscratch = False
return
else:
fromscratch = True
#download ambulant 2 and extract to ROOTDIR
wgetcmd = 'wget --directory-prefix ' + ROOTDIR + ' http://downloads.sourceforge.net/ambulant/ambulant-2.0.1-src.tgz'
print 'wget', wgetcmd
subprocess.call(wgetcmd, shell=True)
print 'tar', tarcmd
tarcmd = 'tar -xf ambulant-2.0.1-src.tgz'
subprocess.call(tarcmd, shell=True, cwd=ROOTDIR)
def fetchTPP():
print 'fromscratch', fromscratch, options.fetch
if fromscratch or "expat" in options.fetch:
wgetcmd = 'wget http://downloads.sourceforge.net/expat/expat-2.0.1.tar.gz'
print 'expat wget', wgetcmd
subprocess.call(wgetcmd, shell=True, cwd=ROOTDIR)
tarcmd = 'tar -xf ' + ROOTDIR + '/expat-2.0.1.tar.gz'
print 'expat tarcmd', tarcmd
subprocess.call(tarcmd, shell=True, cwd=TPPDIR)
if fromscratch or "ffmpeg" in options.fetch:
svncmd = 'svn checkout -r "{2008-06-15}" svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg'
print 'ffmpeg', svncmd
subprocess.call(svncmd, shell=True, cwd=TPPDIR)
if fromscratch or "libsdl" in options.fetch:
wgetcmd = 'wget http://www.libsdl.org/release/SDL-1.2.13.tar.gz'
print 'libsdl', wgetcmd
subprocess.call(wgetcmd, shell=True, cwd=ROOTDIR)
tarcmd = 'tar -xf ' + ROOTDIR + '/SDL-1.2.13.tar.gz'
print 'libsdl', tarcmd
subprocess.call(tarcmd, shell=True, cwd=TPPDIR)
if fromscratch or "live555" in options.fetch:
wgetcmd = 'wget http://www.live555.com/liveMedia/public/live555-latest.tar.gz'
print 'live555', wgetcmd
subprocess.call(wgetcmd, shell=True, cwd=ROOTDIR)
tarcmd = 'tar -xf ' + ROOTDIR + '/live555-latest.tar.gz'
print 'live555', tarcmd
subprocess.call(tarcmd, shell=True, cwd=TPPDIR)
if fromscratch or "libxml2" in options.fetch:
wgetcmd = 'wget ftp://xmlsoft.org/libxml2/libxml2-2.7.3.tar.gz'
print 'libxml2', wgetcmd
subprocess.call(wgetcmd, shell=True, cwd=ROOTDIR)
tarcmd = 'tar -xf ' + ROOTDIR + '/libxml2-2.7.3.tar.gz'
print 'libxml2', tarcmd
subprocess.call(tarcmd, shell=True, cwd=TPPDIR)
def buildTPP():
if fromscratch or "expat" in options.build:
configcmd = './configure --prefix=' + TPPDIR + '/expat-unix'
cwdpath = TPPDIR + '/expat-2.0.1'
subprocess.call(configcmd, shell=True, cwd=cwdpath)
subprocess.call('make', shell = True, cwd=cwdpath)
subprocess.call('make install', shell=True, cwd=cwdpath)
if fromscratch or "ffmpeg" in options.build:
configcmd = './configure --enable-gpl'
cwdpath = TPPDIR + '/ffmpeg'
subprocess.call(configcmd, shell=True, cwd=cwdpath)
subprocess.call('make', shell = True, cwd=cwdpath)
if fromscratch or "libsdl" in options.build:
print 'build libsdl'
configcmd = './configure'
cwdpath = TPPDIR + '/SDL-1.2.13'
subprocess.call(configcmd, shell=True, cwd=cwdpath)
subprocess.call('make', shell = True, cwd=cwdpath)
subprocess.call('make install', shell=True, cwd=cwdpath)
if fromscratch or "live555" in options.build:
print 'build live555'
configcmd = './genMakefiles linux'
cwdpath = TPPDIR + '/live'
subprocess.call(configcmd, shell=True, cwd=cwdpath)
subprocess.call('make', shell = True, cwd=cwdpath)
if fromscratch or "libxml2" in options.build:
print 'build libxml2'
configcmd = './configure'
cwdpath = TPPDIR + '/libxml2-2.7.3'
subprocess.call(configcmd, shell=True, cwd=cwdpath)
subprocess.call('make', shell = True, cwd=cwdpath)
subprocess.call('make install', shell=True, cwd=cwdpath)
def buildAmbulant():
if not test == 'yes':
#configcmd = './configure --with-live --with-python --with-ffmpeg'
configcmd = './configure --with-ffmpeg --with-live -with-python'
cwdpath = ROOTDIR + '/ambulant-2.0.1'
retcode = subprocess.call(configcmd, shell=True, cwd=cwdpath)
if retcode > 0:
print 'ambulant configure failed'
return
logfile = open('make.log', 'w')
retcode = subprocess.call('make', shell = True, cwd=cwdpath, stdout=logfile, stderr = subprocess.STDOUT)
logfile.close()
if retcode > 0:
print 'ambulant make failed'
return
logfile = open('install.log', 'w')
retcode = subprocess.call('make install', shell=True, cwd=cwdpath, stdout=logfile, stderr=subprocess.STDOUT)
logfile.close()
if retcode > 0:
print 'ambulant install failed'
return
#builds ambulant
def main():
temp = 'ROOTDIR= ' + str(ROOTDIR) + ' ' + str(ROOTDIR.exists()) + '\n'
print temp
print 'fetch= ' + fetch + '\n'
print 'build= ' + build + '\n'
#fetch ambulant if ROOTDIR does not exist
fetchAmbulant()
#download latest version of selected packages
fetchTPP()
#build selected packages
buildTPP()
#build ambulant
buildAmbulant()
print 'done'
#This idiom means the below code only runs when executed from command line
if __name__ == '__main__':
sys.stdout = open("ambulant.log", "w")
parser = optparse.OptionParser("usage: %ambulant [options] ")
#option --prefix = path to ambulant folder; if ambulant folder does not exist, fetch ambulant and all third-party packages
#option --fetch=[expat, ffmpeg, ...] list of packages to download
#option --build=[expat, ffmpeg, ...] list of packages to build
parser.add_option("-p", "--prefix", dest="prefix",
default="/home/tony/Documents/testambulant", type="string",
help="path to ambulant2 folder")
parser.add_option("-f", "--fetch", dest="fetch",
default="[]", type="string",
help="list of packages to be downloaded, e.g. [expat, ffmpeg]")
parser.add_option("-b", "--build", dest="build", default="[]",
type="string", help="list of packages to be built, e.g. [expat, ffmpeg")
parser.add_option("-t", "--test", dest="test", default="no", type="string", help="--test to log commands but not execute")
(options, args) = parser.parse_args()
prefix = options.prefix
fetch = options.fetch
build = options.build
test = options.test
print 'options prefix', prefix
print 'options fetch', fetch
print 'options build', build
print 'options test', test
if len(prefix) > 0:
ROOTDIR = path(prefix)
else:
ROOTDIR = path('/home/tony/Documents/testambulant')
print 'ROOTDIR', ROOTDIR
TPPDIR= path(ROOTDIR / 'ambulant-2.0.1' / 'third_party_packages')
print 'ROOTDIR', ROOTDIR
print 'TPPDIR', TPPDIR
main()
sys.exit()
|