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
|
from __future__ import with_statement
from shutil import copyfileobj
from os.path import join, abspath
from os import listdir, getcwd, walk
from subprocess import Popen
from base.base import log
from base.module import Module
from base.util import pwd, copy, symlink, move
from base.exceptions import ExecutionException
from base.vars import FEDORA_DIR
from modules.package import Package
class Build(Module):
def __init__(self, name=None, target_dir=None):
log.debug('name is %s' % name)
self.name = name
self.pkg = Package(name)
self.target_dir = target_dir
def setup_source(self, target_dir=None):
if not target_dir:
if self.target_dir:
target_dir = self.target_dir
else:
raise ExecutionException(None, 'no Target Dir specified')
log.debug('target dir is %s' % target_dir)
with pwd(self.pkg.code_dir):
symlink(self.name + '.spec',
join(self.target_dir, 'SPECS', self.name + '.spec'))
sball = self.pkg.pkg_cfg['sourceball']
symlink(sball, join(self.target_dir, 'SOURCES', sball))
patches = [f for f in listdir(getcwd()) if f.endswith('.patch')]
for p in patches:
symlink(patch, join(self.target_dir, 'SOURCES', p))
def build_quick_rpm(self, target_dir=None):
self.rpmbuild('-ba', target_dir)
def build_source_rpm(self, target_dir=None):
self.rpmbuild('-bs', target_dir)
def rpmbuild(self, param, target_dir=None):
if not target_dir:
if self.target_dir:
target_dir = self.target_dir
else:
raise ExecutionException(None, 'no Target Dir specified')
with pwd(self.pkg.code_dir):
rpm_out = file('rpmbuild.log', 'w')
with pwd(join(target_dir, 'SPECS')):
p = Popen(['rpmbuild', param, self.name + '.spec'],
stdout=rpm_out, stderr=rpm_out)
log.info('quick compiling %s... please wait' % self.name)
p.wait()
rpm_out.close()
def fetch_rpms(self, target_dir=None):
if not target_dir:
if self.target_dir:
target_dir = self.target_dir
else:
raise ExecutionException(None, 'no Target Dir specified')
with pwd(target_dir):
for path, dirs, files in walk('.'):
for f in files:
if f.endswith('.rpm'):
move(join(path, f), join(FEDORA_DIR, f))
def fetch_build(self, target_dir=None):
if not target_dir:
if self.target_dir:
target_dir = self.target_dir
else:
raise ExecutionException(None, 'no Target Dir specified')
with pwd(target_dir):
source = self.pkg.pkg_cfg['source']
move(join('BUILD', source), join(self.pkg.code_dir, 'results'))
def close(self):
self.pkg.close()
|