~dktrkranz/debomatic/debomatic

« back to all changes in this revision

Viewing changes to Debomatic/build.py

  • Committer: Luca Falavigna
  • Date: 2007-11-29 21:01:35 UTC
  • mfrom: (1.1.87 debomatic.dev)
  • Revision ID: dktrkranz@ubuntu.com-20071129210135-y77d6rp21ir6gfkb
Stable release: 0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Deb-o-Matic
 
2
#
 
3
# Copyright (C) 2007 Luca Falavigna
 
4
#
 
5
# Author: Luca Falavigna <dktrkranz@ubuntu.com>
 
6
#
 
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
 
10
#
 
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.
 
15
#
 
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.
 
19
 
 
20
import os
 
21
import sys
 
22
import threading
 
23
from re import findall
 
24
from sha import new
 
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
 
30
 
 
31
def build_package(directory, configfile, distdir, package, distopts):
 
32
    if not locks.buildlock_acquire():
 
33
        packages.del_package(package)
 
34
        sys.exit(-1)
 
35
    dscfile = None
 
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]:
 
39
            if not dscfile:
 
40
                dscfile = findall('(.*\.dsc$)', pkgfile)
 
41
    try:
 
42
        packageversion = findall('.*/(.*).dsc$', dscfile[0])[0]
 
43
    except:
 
44
        packageversion = None
 
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):
 
54
            os.remove(pkgfile)
 
55
    locks.buildlock_release()
 
56
 
 
57
def check_package(directory, distribution, changes):
 
58
    try:
 
59
        packagename = findall('(.*_.*)_source.changes', changes)[0]
 
60
    except:
 
61
        print 'Bad .changes file'
 
62
        return
 
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'
 
66
    changesfile = None
 
67
    for filename in os.listdir(resultdir):
 
68
        result = findall('.*.changes', filename)
 
69
        if len(result):
 
70
            changesfile = os.path.join(resultdir, result[0])
 
71
            break
 
72
    if changesfile:
 
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))
 
77
 
 
78
def build_process():
 
79
    directory = globals.Options.get('default', 'packagedir')
 
80
    configdir = globals.Options.get('default', 'configdir')
 
81
    package = packages.select_package(directory)
 
82
    if package:
 
83
        distopts = parser.parse_distribution_options(directory, configdir, package)
 
84
        try:
 
85
            fd = os.open(os.path.join(directory, package), os.O_RDONLY)
 
86
        except:
 
87
            print 'Unable to open %s' % os.path.join(directory, package)
 
88
            packages.del_package(package)
 
89
            sys.exit(-1)
 
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))
 
93
        os.close(fd)
 
94
        distdir = os.path.join(directory, distopts['distribution'])
 
95
        if pbuilder.setup_pbuilder(distdir, configdir, distopts):
 
96
            packages.del_package(package)
 
97
            sys.exit(-1)
 
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)
 
101