3
# Copyright (C) 2007 Luca Falavigna
5
# Author: Luca Falavigna <dktrkranz@ubuntu.com>
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; only version 2 of the License
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
23
from re import findall
25
from Debomatic import globals
26
from Debomatic import locks
27
from Debomatic import packages
28
from Debomatic import parser
29
from Debomatic import pbuilder
31
def build_package(directory, configfile, distdir, package, distopts):
32
if not locks.buildlock_acquire():
33
packages.del_package(package)
36
if not os.path.exists(os.path.join(distdir, 'result')):
37
os.mkdir(os.path.join(distdir, 'result'))
38
for pkgfile in globals.packagequeue[package]:
40
dscfile = findall('(.*\.dsc$)', pkgfile)
42
packageversion = findall('.*/(.*).dsc$', dscfile[0])[0]
45
if not os.path.exists(os.path.join(distdir, 'result', packageversion)):
46
os.mkdir(os.path.join(distdir, 'result', packageversion))
47
os.system('pbuilder build --basetgz %(directory)s/%(distribution)s \
48
--distribution %(distribution)s --override-config --pkgname-logfile --configfile %(cfg)s \
49
--buildplace %(directory)s/build --buildresult %(directory)s/result/%(package)s \
50
--aptcache %(directory)s/aptcache %(dsc)s' % { 'directory': distdir, 'package': packageversion, \
51
'cfg': configfile, 'distribution': distopts['distribution'], 'dsc': dscfile[0]})
52
for pkgfile in globals.packagequeue[package]:
53
if os.path.exists(pkgfile):
55
locks.buildlock_release()
57
def check_package(directory, distribution, changes):
59
packagename = findall('(.*_.*)_source.changes', changes)[0]
61
print 'Bad .changes file'
63
resultdir = os.path.join(directory, distribution, 'result', packagename)
64
lintian = os.path.join(resultdir, packagename) + '.lintian'
65
linda = os.path.join(resultdir, packagename) + '.linda'
67
for filename in os.listdir(resultdir):
68
result = findall('.*.changes', filename)
70
changesfile = os.path.join(resultdir, result[0])
73
if globals.Options.getint('default', 'lintian'):
74
os.system('lintian --allow-root -i -I %s > %s' % (changesfile, lintian))
75
if globals.Options.getint('default', 'linda'):
76
os.system('linda -q -i %s > %s' % (changesfile, linda))
79
directory = globals.Options.get('default', 'packagedir')
80
configdir = globals.Options.get('default', 'configdir')
81
package = packages.select_package(directory)
83
distopts = parser.parse_distribution_options(directory, configdir, package)
85
fd = os.open(os.path.join(directory, package), os.O_RDONLY)
87
print 'Unable to open %s' % os.path.join(directory, package)
88
packages.del_package(package)
90
for entry in findall('\s\w{32}\s\d+\s\S+\s\S+\s(.*)', os.read(fd, os.fstat(fd).st_size)):
91
globals.packagequeue[package].append(os.path.join(directory, entry))
92
globals.packagequeue[package].append(os.path.join(directory, package))
94
distdir = os.path.join(directory, distopts['distribution'])
95
if pbuilder.setup_pbuilder(distdir, configdir, distopts):
96
packages.del_package(package)
98
build_package(directory, os.path.join(configdir, distopts['distribution']), distdir, package, distopts)
99
check_package(directory, distopts['distribution'], package)
100
packages.del_package(package)