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
|
#!/usr/bin/python
# fedpkg-pull-build-chain:
# Build binary RPMS for the named source RPMs from the latest upstream code. Fedora CVS tree
# is checked out into the current directory. Build logs go in _build. You must specify
# a destination path for RPMS with --resultdir.
#
# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
# Copyright (C) 2010 Red Hat, Inc.
# Written by Colin Walters <walters@verbum.org>
import getopt
import os
import sys
import subprocess
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], '', ['release', 'arch'])
except getopt.GetoptError, e:
print "Usage: fedpkg-pull-build-chain --release=F-12 --resultdir=/path/to/repo rpm1 rpm2 ..."
sys.exit(1)
release = None
resultdir = None
architectures = []
for o, a in opts:
if o in ('--release', ):
release = a
elif o in ('--arch', ):
architectures.append(a)
elif o in ('--resultdir', ):
resultdir = a
if release is None:
print "Must specify --release"
sys.exit(1)
if resultdir is None:
print "Must specify --resultdir=/path/to/repository"
sys.exit(1)
if len(architectures) == 0:
architectures.append(subprocess.check_call(['uname', '-m'], stdout=subprocess.PIPE).communicate()[0])
failed = []
for arg in args:
if not os.path.isdir(arg):
print "Checking out %r from fedora-cvs" % (arg, )
subprocess.check_call(['fedora-cvs', arg], stdout=sys.stdout, stderr=sys.stderr)
release_dir = os.path.join(arg, release)
for filename in os.listdir(release_dir):
fpath = os.path.join(release_dir, filename)
if filename.endswith('.src.rpm'):
print "Deleting old srpm: " + fpath
os.unlink(fpath)
print "Running fedpkg-make-pull"
try:
subprocess.check_call(['fedpkg-make-pull'], stdout=sys.stdout, stderr=sys.stderr)
except subprocess.CalledProcessError, e:
print "Failed: " + unicode(e)
failed.append(arg)
continue
srpm = None
for filename in os.listdir(release_dir):
fpath = os.path.join(release_dir, filename)
if filename.endswith('.src.rpm'):
srpm = fpath
if srpm is None:
print "No SRPM, assuming no changes upstream"
continue
mock_resultdir = os.path.join('_build', arg)
try:
os.mkdir(mock_resultdir)
except OSError, e:
# assume EEXIST, and clean out old results
for filename in os.listdir(mock_resultdir):
os.unlink(os.path.join(mock_resultdir, filename))
for architecture in architectures:
# FIXME do this better
mockrelease = 'fedora-' + release[2:].lower() + '-' + architecture
try:
subprocess.check_call(['mock', '-r', mockrelease, '--resultdir=' + mock_resultdir, 'rebuild', srpm], stdout=sys.stdout, stderr=sys.stderr)
except subprocess.CalledProcessError, e:
print "Failed: " + unicode(e)
failed.append(arg)
continue
for filename in os.listdir(mock_resultdir):
if not filename.endswith('.rpm'):
continue
os.link(os.path.join(resultdir, filename), os.path.join(mock_resultdir, filename))
if len(failed) > 0:
sys.exit(1)
else:
sys.exit(0)
if __name__ == '__main__':
main()
|