Merge pull request #82 from ceph/wip-rm-blkin
[autobuild-ceph.git] / get-libcephfs-java-jar.py
1
2 import logging
3 import urllib2
4 import urlparse
5 import os
6 import sys
7 from subprocess import Popen
8 from subprocess import PIPE
9 import glob
10
11
12 logging.basicConfig()
13 log = logging.getLogger(__name__)
14 #log = logging.getLogger()
15 log.setLevel(logging.INFO)
16
17 def get_ceph_binary_url(package=None,
18                         branch=None, tag=None, sha1=None, dist=None,
19                         flavor=None, format=None, arch=None):
20     BASE = 'http://gitbuilder.ceph.com/{package}-{format}-{dist}-{arch}-{flavor}/'.format(
21         package=package,
22         flavor=flavor,
23         arch=arch,
24         format=format,
25         dist=dist
26         )
27
28     log.info('BASE: %s' % (BASE))
29     if sha1 is not None:
30         assert branch is None, "cannot set both sha1 and branch"
31         assert tag is None, "cannot set both sha1 and tag"
32     else:
33         # gitbuilder uses remote-style ref names for branches, mangled to
34         # have underscores instead of slashes; e.g. origin_master
35         if tag is not None:
36             ref = tag
37             assert branch is None, "cannot set both branch and tag"
38         else:
39             if branch is None:
40                 branch = 'master'
41             ref = branch
42
43         sha1_url = urlparse.urljoin(BASE, 'ref/{ref}/sha1'.format(ref=ref))
44         log.info('sha1_url: %s' % (sha1_url))
45         log.info('Translating ref to sha1 using url %s', sha1_url)
46         sha1_fp = urllib2.urlopen(sha1_url)
47         sha1 = sha1_fp.read().rstrip('\n')
48         sha1_fp.close()
49
50     log.debug('Using %s %s sha1 %s', package, format, sha1)
51     bindir_url = urlparse.urljoin(BASE, 'sha1/{sha1}/'.format(sha1=sha1))
52     log.info('sha1: %s bindir_url: %s' % (sha1, bindir_url))
53     return (sha1, bindir_url)
54
55 def main():
56     package='ceph'
57     format='tarball'
58     dist='precise'
59     arch='x86_64'
60     flavor='basic'
61     branch='master'
62
63     sha1,bindir_url = get_ceph_binary_url(package, branch,None,None,dist,flavor,format,arch)
64     log.info('sha1: %s bindir_url: %s' % (sha1, bindir_url))
65
66     p1 = Popen(args=[
67             'install', '-d', '-m0755', '--', '/tmp/hadooptest/binary'],
68             stdout=PIPE)
69     p2 = Popen( args=[
70             'uname', '-m',], stdin=p1.stdout, stdout=PIPE)
71     p3 = Popen( args=[
72             'sed', '-e', 's/^/ceph./; s/$/.tgz/',], stdin=p2.stdout, stdout=PIPE)
73     p4 = Popen( args=[
74             'wget',
75             '-nv',
76             '-O-',
77             '--base={url}'.format(url=bindir_url),
78             # need to use --input-file to make wget respect --base
79             '--input-file=-',], stdin=p3.stdout, stdout=PIPE)
80     p5 = Popen( args=[
81             'tar', '-xzf', '-', '-C', '/tmp/hadooptest/binary',],
82             stdin=p4.stdout,stdout=PIPE)
83     p5.wait()
84
85     log.info('copying libcephfs*.so to lib/')
86
87     p1 = Popen(args=[
88             'install', '-d', '-m0755', '--', 'lib'],
89             stdout=PIPE)
90
91     soFiles = glob.glob('/tmp/hadooptest/binary/usr/local/lib/libcephfs*.so')
92     for libFile in soFiles:
93         #log.info('soFile: %s' % libFile)
94         p1 = Popen(args=[
95             'cp', libFile, 'lib/'])
96         p1.wait()
97
98     log.info('copying jars to lib/')
99
100     jarFiles = glob.glob('/tmp/hadooptest/binary/usr/local/share/java/*.jar')
101     for jarFile in jarFiles:
102         #log.info('soFile: %s' % libFile)
103         p1 = Popen(args=[
104             'cp', jarFile, 'lib/'])
105         p1.wait()
106
107 if __name__ == "__main__":
108     main()
109