Skip to content
Newer
Older
100755 96 lines (76 sloc) 2.56 KB
1f80d31 add python build script hard coded for memcached. should provide basi…
Christian Carey authored
1 #!/usr/bin/env python
2 import os, sys, tarfile, shutil
3 import subprocess as proc
4 import warnings
5
6 warnings.filterwarnings('ignore','.*apt API not stable yet.*')
7
8 import apt
9
e9e53ba refactor directory create
Christian Carey authored
10 def create_dir(name):
11 if not os.path.exists(name):
12 os.mkdir(name)
13
1f80d31 add python build script hard coded for memcached. should provide basi…
Christian Carey authored
14 def dependenciesMet(packages):
15 met = True
16 cache = apt.Cache()
17 for package in packages:
18 pkg = cache[package]
19 if not pkg.isInstalled:
20 print("%s package is not installed." % package)
21 met = False
22 return met
32310df convert build script to configured build
Christian Carey authored
23
24 def copy_built_files(files, build_dir):
0865fd5 correct issue with the copy built files list check.
Christian Carey authored
25 if type(files) is list:
48a42d7 correct issue with build file copy when only one file exists
Christian Carey authored
26 for f in files:
27 shutil.copy('tmp/%s/%s' % (build_dir, f), 'build/bin')
28 else:
29 shutil.copy('tmp/%s/%s' % (build_dir, files), 'build/bin')
32310df convert build script to configured build
Christian Carey authored
30
31 def usage():
32 print("Usage: %s component_name" % sys.argv[0])
1f80d31 add python build script hard coded for memcached. should provide basi…
Christian Carey authored
33
32310df convert build script to configured build
Christian Carey authored
34 def get_config(component):
35 config_file = open("%s-conf" % component)
36 config = { }
37 for setting in config_file:
38 if len(setting.split('=')) > 1:
39 if (len(setting.split(' '))) > 1:
40 config[setting.split('=')[0]] = setting.rstrip('\n').split('=')[1].split(' ')
41 else:
42 config[setting.split('=')[0]] = setting.rstrip('\n').split('=')[1]
43 return config
44
1f80d31 add python build script hard coded for memcached. should provide basi…
Christian Carey authored
45 def main():
32310df convert build script to configured build
Christian Carey authored
46 if len(sys.argv) != 2:
47 usage()
48 sys.exit(1)
49 component = sys.argv[1]
50
51 print("building %s" % component)
52
53 config = get_config(component)
54
e9e53ba refactor directory create
Christian Carey authored
55 create_dir('tmp')
56 create_dir('build')
57 create_dir('build/bin')
58
1f80d31 add python build script hard coded for memcached. should provide basi…
Christian Carey authored
59 os.chdir('tmp')
60
61 print("checking build depedencies...")
32310df convert build script to configured build
Christian Carey authored
62 if not dependenciesMet(config['BUILDDEP']):
63 print("install dependencies using the following command and try again")
64 print("sudo apt-get install %s" % " ".join(config['BUILDDEP']))
1f80d31 add python build script hard coded for memcached. should provide basi…
Christian Carey authored
65 sys.exit(1)
66
67 print("downloading source...")
68 try:
32310df convert build script to configured build
Christian Carey authored
69 proc.check_call(['wget','-c', '%s/%s' % (config['SOURCEPATH'], config['SOURCETARFILE'])])
1f80d31 add python build script hard coded for memcached. should provide basi…
Christian Carey authored
70 except proc.CalledProcessError:
71 sys.exit(1)
72
73 print("extracting tar ball...")
32310df convert build script to configured build
Christian Carey authored
74 memcached = tarfile.open(name=config['SOURCETARFILE'], mode='r:gz')
1f80d31 add python build script hard coded for memcached. should provide basi…
Christian Carey authored
75 memcached.extractall()
76
77 print("configuring...")
32310df convert build script to configured build
Christian Carey authored
78 os.chdir(config['BUILDDIR'])
1f80d31 add python build script hard coded for memcached. should provide basi…
Christian Carey authored
79 try:
80 proc.check_call(['./configure'])
81 except proc.CalledProcessError:
82 sys.exit(1)
83
84 print("building...")
85 try:
86 proc.check_call(['make'])
87 except proc.CalledProcessError:
88 sys.exit(1)
89
90 print("copying built files...")
91 os.chdir('../..')
32310df convert build script to configured build
Christian Carey authored
92 copy_built_files(config['INSTALLFILES'], config['BUILDDIR'])
1f80d31 add python build script hard coded for memcached. should provide basi…
Christian Carey authored
93
94 if __name__ == "__main__":
95 main()
Something went wrong with that request. Please try again.